@nerdwallet/jest-nock-fixtures
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,5 @@ | ||
## 2.1.0 (2022-12-08) | ||
- Move many logs behind a `JEST_NOCK_FIXTURES_VERBOSE` environment variable flag | ||
## 2.0.0 (2021-03-31) benjroy | ||
@@ -2,0 +6,0 @@ |
{ | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"name": "@nerdwallet/jest-nock-fixtures", | ||
@@ -9,9 +9,8 @@ "description": "jest-nock-fixtures", | ||
"jest": "jest --config=jest.config.js --coverage", | ||
"build": "true", | ||
"fix-lint": "npm run lint -- --fix", | ||
"format": "yarn lint --fix", | ||
"lint": "eslint src --ext .js", | ||
"test": "npm run jest --", | ||
"test:wild": "JEST_NOCK_FIXTURES_MODE=wild npm run test --", | ||
"test:record": "JEST_NOCK_FIXTURES_MODE=record npm run test --", | ||
"test:lockdown": "JEST_NOCK_FIXTURES_MODE=lockdown npm run test --" | ||
"test": "yarn jest --", | ||
"test:wild": "JEST_NOCK_FIXTURES_MODE=wild yarn test", | ||
"test:record": "JEST_NOCK_FIXTURES_MODE=record yarn test", | ||
"test:lockdown": "JEST_NOCK_FIXTURES_MODE=lockdown yarn test" | ||
}, | ||
@@ -18,0 +17,0 @@ "repository": { |
@@ -10,3 +10,3 @@ # jest-nock-fixtures | ||
## Setup | ||
## Setup and usage | ||
@@ -62,3 +62,3 @@ Configure `jest` to setup this wrapper before the tests in each test file are executed. In `jest@24`, this can be achieved by configuring `setupFilesAfterEnv` (https://jestjs.io/docs/en/configuration#setupfilesafterenv-array) | ||
#### Modes | ||
### Modes | ||
@@ -100,2 +100,10 @@ Available modes: | ||
### Log levels | ||
By default, minimal logs will be printed. To increase the verbosity of the logs, set `JEST_NOCK_FIXTURES_VERBOSE` when running tests. For example: | ||
```sh | ||
JEST_NOCK_FIXTURES_VERBOSE=1 npm run test | ||
``` | ||
## Developing | ||
@@ -105,6 +113,15 @@ | ||
- `npm run test`: Run unit tests and generate coverage reports | ||
- `yarn install`: Install all dependencies | ||
- `yarn test`: Run unit tests and generate coverage reports | ||
Other commands you might care about: | ||
- `npm run lint`: Run lint | ||
- `yarn lint`: Run lint | ||
- `yarn format`: Automatically fix code issues | ||
### Releasing a new version | ||
1. Update the version in `package.json`. Take care to follow semantic versioning. | ||
2. Update `CHANGELOG.md` to reflect the changes in the new version. | ||
3. Push both of the above changes to the `master` branch. | ||
4. Create a new release in the GitHub CI. GitHub Actions will automatically publish the new version to npm. |
@@ -90,5 +90,10 @@ const { dirname, basename, join } = require('path'); | ||
].join(' '); | ||
// utility for logging user messages | ||
// eslint-disable-next-line no-console | ||
const print = str => console.log(message(str)); | ||
const log = str => console.log(message(str)); | ||
const logVerbose = str => { | ||
if (!process.env.JEST_NOCK_FIXTURES_VERBOSE) return; | ||
log(str); | ||
}; | ||
@@ -110,3 +115,3 @@ // ensure a valid mode is being used | ||
if (mode === MODES.WILD) { | ||
print("Not intercepting any requests in 'wild' mode"); | ||
log("Not intercepting any requests in 'wild' mode"); | ||
return; | ||
@@ -135,7 +140,7 @@ } | ||
fixture = JSON.parse(readFileSync(fixtureFilepath())); | ||
print(yellow(`loaded nock fixture file: ${fixtureFilepath()}`)); | ||
logVerbose(yellow(`loaded nock fixture file: ${fixtureFilepath()}`)); | ||
} catch (err) { | ||
fixture = {}; | ||
if (err.code !== 'ENOENT') { | ||
print( | ||
log( | ||
red( | ||
@@ -194,3 +199,3 @@ `Error parsing fixture file:\nFile:\n\t${fixtureFilepath()}\nError message:\n\t${ | ||
nock.define(recordings); | ||
print( | ||
logVerbose( | ||
yellow( | ||
@@ -206,3 +211,3 @@ `Defined (${ | ||
if (unmatched.length) { | ||
print(yellow(`${unmatched.length} unmatched requests`)); | ||
log(yellow(`${unmatched.length} unmatched requests`)); | ||
} | ||
@@ -220,3 +225,3 @@ }, | ||
nock.define(recordings); | ||
print( | ||
logVerbose( | ||
yellow( | ||
@@ -257,3 +262,3 @@ `Defined (${ | ||
// message what happened | ||
print(yellow(`Recorded ${recordings.length} request(s)`)); | ||
logVerbose(yellow(`Recorded ${recordings.length} request(s)`)); | ||
} else if (has(fixture, uniqueTestName())) { | ||
@@ -270,3 +275,3 @@ delete fixture[uniqueTestName()]; | ||
delete fixture[name]; | ||
print(yellow(`Removed obsolete fixture entry for ${name}`)); | ||
logVerbose(yellow(`Removed obsolete fixture entry for ${name}`)); | ||
}); | ||
@@ -291,3 +296,3 @@ | ||
// message what happened | ||
print( | ||
logVerbose( | ||
yellow(`Wrote recordings to fixture file: ${fixtureFilepath()}`) | ||
@@ -302,3 +307,3 @@ ); | ||
// cleanup obsolete nock fixture file and dir if they exist | ||
print(yellow(`Nothing recorded, removing ${fixtureFilepath()}`)); | ||
logVerbose(yellow(`Nothing recorded, removing ${fixtureFilepath()}`)); | ||
// remove the fixture file | ||
@@ -310,3 +315,3 @@ unlinkSync(fixtureFilepath()); | ||
// message what happened | ||
print( | ||
logVerbose( | ||
yellow( | ||
@@ -313,0 +318,0 @@ `Removed ${fixtureDir()} directory because no fixtures were left.` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36654
17
505
124
3