Skip to content

Commit

Permalink
Bump all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
exogen committed Apr 12, 2021
1 parent 46d28ce commit 866a230
Show file tree
Hide file tree
Showing 17 changed files with 4,075 additions and 3,819 deletions.
7 changes: 3 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"presets": [
[
"env",
"@babel/preset-env",
{
"targets": {
"node": "8.10"
"node": "12.20.0"
}
}
]
],
"plugins": ["syntax-object-rest-spread"]
]
}
15 changes: 8 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module.exports = {
extends: ['standard', 'prettier', 'prettier/standard'],
extends: ['standard', 'prettier'],
parser: '@babel/eslint-parser',
env: {
es6: true,
node: true
node: true,
},
parserOptions: {
ecmaVersion: 6
ecmaVersion: 6,
},
plugins: ['prettier'],
plugins: ['@babel', 'prettier'],
rules: {
'prettier/prettier': 'warn'
}
}
'prettier/prettier': 'warn',
},
};
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ requests. This function will add `beforeEach`, `afterEach`, and
`afterEach.always` hooks that manage Nock fixtures for you.

```js
import test from 'ava'
import fetch from 'isomorphic-fetch'
import { setupTests } from 'ava-nock'
import test from 'ava';
import fetch from 'isomorphic-fetch';
import { setupTests } from 'ava-nock';

setupTests()
setupTests();

test('using fetch to get JSON', t => {
test('using fetch to get JSON', (t) => {
return fetch(
'https://musicbrainz.org/ws/2/artist/c8da2e40-bd28-4d4e-813a-bd2f51958ba8?fmt=json'
)
.then(response => response.json())
.then(data => {
t.is(data.name, 'Lures')
})
})
.then((response) => response.json())
.then((data) => {
t.is(data.name, 'Lures');
});
});
```

Fixtures behave similarly to AVA snapshots: they are stored in a `.nock` file
Expand Down Expand Up @@ -128,6 +128,6 @@ keep them out of source control.

```js
{
pathFilter: ['([?&]secretKey=)([^&]*)', '$1*']
pathFilter: ['([?&]secretKey=)([^&]*)', '$1*'];
}
```
64 changes: 32 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "Brian Beck <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=8.10"
"node": ">=12.20.0"
},
"main": "lib/index.js",
"files": [
Expand Down Expand Up @@ -45,11 +45,11 @@
},
"ava": {
"require": [
"babel-register"
"@babel/register"
],
"files": [
"src/**/*.test.js",
"test"
"test/**/*.test.js"
]
},
"ava-nock": {
Expand All @@ -59,7 +59,6 @@
]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"lint-staged": {
Expand All @@ -73,39 +72,40 @@
]
},
"peerDependencies": {
"ava": ">=0.23.0 <1"
"ava": "^1.0.0 || ^2.0.0 || ^3.0.0"
},
"dependencies": {
"debug": "^3.1.0",
"fs-extra": "^7.0.0",
"debug": "^4.3.1",
"fs-extra": "^9.1.0",
"json-parse-better-errors": "^1.0.2",
"json-stable-stringify": "^1.0.1",
"nock": "^9.4.4",
"object-hash": "^1.3.0",
"temp-write": "^3.4.0"
"nock": "^13.0.11",
"object-hash": "^2.1.1",
"temp-write": "^4.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"axios": "^0.18.0",
"babel-cli": "^6.26.0",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"eslint": "^5.3.0",
"eslint-config-prettier": "^2.9.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"husky": "^0.14.3",
"isomorphic-fetch": "^2.2.1",
"lint-staged": "^7.2.0",
"nyc": "^12.0.2",
"prettier": "^1.14.0",
"request": "^2.87.0",
"rimraf": "^2.6.2",
"uuid": "^3.3.2"
"@babel/cli": "^7.13.14",
"@babel/core": "^7.13.14",
"@babel/eslint-parser": "^7.13.14",
"@babel/eslint-plugin": "^7.13.15",
"@babel/preset-env": "^7.13.14",
"@babel/register": "^7.13.14",
"ava": "^4.0.0-alpha.2",
"axios": "^0.21.1",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^5.1.0",
"husky": "^6.0.0",
"isomorphic-fetch": "^3.0.0",
"lint-staged": "^10.5.4",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"request": "^2.88.2",
"rimraf": "^3.0.2",
"uuid": "^8.3.2"
}
}
51 changes: 27 additions & 24 deletions src/encoding.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import zlib from 'zlib'
import createLogger from 'debug'
import zlib from 'zlib';
import createLogger from 'debug';

const debug = createLogger('ava-nock:encoding')
const decoders = new Map([['gzip', zlib.gunzip], ['deflate', zlib.inflate]])
const debug = createLogger('ava-nock:encoding');
const decoders = new Map([
['gzip', zlib.gunzip],
['deflate', zlib.inflate],
]);

function findLastEncoding(headers) {
const reversedHeaders = headers.slice().reverse()
const reversedHeaders = headers.slice().reverse();
const index = reversedHeaders.findIndex(
(header, index) => header.toLowerCase() === 'content-encoding' && index % 2
)
return index === -1 ? -1 : headers.length - index - 1
);
return index === -1 ? -1 : headers.length - index - 1;
}

export function decodeResponse(call) {
if (Array.isArray(call.response)) {
// Reverse the headers array, because Content-Encoding can appear multiple
// times and we need to decode the response in the opposite order that it
// was encoded.
const encodingIndex = findLastEncoding(call.rawHeaders)
const encodingIndex = findLastEncoding(call.rawHeaders);
if (encodingIndex !== -1) {
const encodingValue = call.rawHeaders[encodingIndex + 1]
const encodingValue = call.rawHeaders[encodingIndex + 1];
if (decoders.has(encodingValue)) {
debug(`Found encoding: ${encodingValue}, attempting to decode.`)
const decode = decoders.get(encodingValue)
debug(`Found encoding: ${encodingValue}, attempting to decode.`);
const decode = decoders.get(encodingValue);
const buffer = Buffer.concat(
call.response.map(hexString => Buffer.from(hexString, 'hex'))
)
call.response.map((hexString) => Buffer.from(hexString, 'hex'))
);
return new Promise((resolve, reject) => {
decode(buffer, (err, outputBuffer) => {
if (err) {
reject(err)
reject(err);
} else {
// Remove the Content-Encoding that was processed.
const headers = call.rawHeaders.slice()
headers.splice(encodingIndex, 2)
const hasEncoding = findLastEncoding(headers) !== -1
const headers = call.rawHeaders.slice();
headers.splice(encodingIndex, 2);
const hasEncoding = findLastEncoding(headers) !== -1;
// If there's another Content-Encoding, leave the response as an
// array of hex-encoded buffers and call this function again.
// Otherwise, convert it to a string.
Expand All @@ -43,18 +46,18 @@ export function decodeResponse(call) {
rawHeaders: headers,
response: hasEncoding
? [outputBuffer.toString('hex')]
: outputBuffer.toString()
}
: outputBuffer.toString(),
};
if (hasEncoding) {
decodeResponse(outputCall).then(resolve, reject)
decodeResponse(outputCall).then(resolve, reject);
} else {
resolve(outputCall)
resolve(outputCall);
}
}
})
})
});
});
}
}
}
return Promise.resolve(call)
return Promise.resolve(call);
}
50 changes: 25 additions & 25 deletions src/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import fs from 'fs'
import path from 'path'
import parseJSON from 'json-parse-better-errors'
import stringifyJSON from 'json-stable-stringify'
import { ensureDir, move } from 'fs-extra'
import tempWrite from 'temp-write'
import createLogger from 'debug'
import fs from 'fs';
import path from 'path';
import parseJSON from 'json-parse-better-errors';
import stringifyJSON from 'json-stable-stringify';
import { ensureDir, move } from 'fs-extra';
import tempWrite from 'temp-write';
import createLogger from 'debug';

const debug = createLogger('ava-nock:fixtures')
const debug = createLogger('ava-nock:fixtures');

export function readFixture(filename) {
filename = path.relative(process.cwd(), filename)
filename = path.relative(process.cwd(), filename);
return new Promise((resolve, reject) => {
debug(`Reading fixture: ${filename}`)
debug(`Reading fixture: ${filename}`);
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
reject(err)
reject(err);
} else {
resolve(parseJSON(data))
resolve(parseJSON(data));
}
})
})
});
});
}

export function writeFixture(filename, data, options) {
filename = path.relative(process.cwd(), filename)
const output = stringifyJSON(data, { space: 2 }) + '\n'
debug(`Writing fixture to temporary file.`)
filename = path.relative(process.cwd(), filename);
const output = stringifyJSON(data, { space: 2 }) + '\n';
debug(`Writing fixture to temporary file.`);
return tempWrite(output)
.then(tempFile => {
const dirname = path.dirname(filename)
debug(`Ensuring fixture directory exists: ${dirname}`)
return ensureDir(dirname).then(() => tempFile)
})
.then(tempFile => {
debug(`Moving fixture into place: ${filename}`)
return move(tempFile, filename, options)
.then((tempFile) => {
const dirname = path.dirname(filename);
debug(`Ensuring fixture directory exists: ${dirname}`);
return ensureDir(dirname).then(() => tempFile);
})
.then((tempFile) => {
debug(`Moving fixture into place: ${filename}`);
return move(tempFile, filename, options);
});
}
Loading

0 comments on commit 866a230

Please sign in to comment.