Skip to content

Commit

Permalink
Merge pull request #1373 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed May 10, 2022
2 parents 9558b9d + ac9b37b commit 55a0860
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 225 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Expand Up @@ -9,15 +9,15 @@ workflows:
- test-node-v14:
requires:
- gally-create-pr
- test-node-v17:
- test-node-v18:
requires:
- gally-create-pr
- gally-auto-approve:
requires:
- gally-create-pr
- test-node-v16
- test-node-v14
- test-node-v17
- test-node-v18
filters:
branches:
only: /dependabot\/.*/
Expand All @@ -26,7 +26,7 @@ workflows:
- gally-create-pr
- test-node-v16
- test-node-v14
- test-node-v17
- test-node-v18
filters:
branches:
only: master
Expand Down Expand Up @@ -157,9 +157,9 @@ jobs:
- run: >-
(git add . && git diff-index --quiet HEAD --) || (git status && exit
1);
test-node-v17:
test-node-v18:
docker:
- image: circleci/node:17
- image: cimg/node:18.0
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion .gally.json
Expand Up @@ -25,7 +25,7 @@
"ci/circleci: gally-create-pr",
"ci/circleci: test-node-v16",
"ci/circleci: test-node-v14",
"ci/circleci: test-node-v17"
"ci/circleci: test-node-v18"
]
},
"enforce_admins": true,
Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,16 @@ describe('Testing some stuff', /* { ...options }, */ () => {

Please see tests for further usage examples.

### Custom Cassette Logic

### delayConnection

Delay the connection by a certain number of ms.

### delayBody

Delay the response body by a certain number of ms.

### Function Kwargs

#### dir
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -42,18 +42,18 @@
},
"homepage": "https://github.com/blackflux/node-tdd#readme",
"devDependencies": {
"@babel/core": "7.17.9",
"@babel/core": "7.17.10",
"@babel/eslint-parser": "7.17.0",
"@babel/register": "7.17.7",
"@blackflux/eslint-plugin-rules": "2.1.0",
"@blackflux/robo-config-plugin": "7.7.6",
"aws-sdk": "2.1112.0",
"aws-sdk-wrap": "12.0.4",
"axios": "0.26.1",
"c8": "7.11.0",
"@blackflux/robo-config-plugin": "7.7.12",
"aws-sdk": "2.1131.0",
"aws-sdk-wrap": "12.1.3",
"axios": "0.27.2",
"c8": "7.11.2",
"chai": "4.3.6",
"coveralls": "3.1.1",
"eslint": "8.13.0",
"eslint": "8.15.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-json": "3.1.0",
Expand Down
8 changes: 8 additions & 0 deletions src/modules/request-recorder.js
Expand Up @@ -183,6 +183,14 @@ export default (opts) => {
scope.on('request', (req, interceptor, requestBodyString) => {
const idx = pendingMocks.findIndex((e) => e.idx === scopeIdx);

// https://github.com/nock/nock/blob/79ee0429050af929c525ae21a326d22796344bfc/lib/interceptor.js#L616
if (Number.isInteger(pendingMocks[idx]?.record?.delayConnection)) {
interceptor.delayConnection(pendingMocks[idx].record.delayConnection);
}
if (Number.isInteger(pendingMocks[idx]?.record?.delayBody)) {
interceptor.delayBody(pendingMocks[idx].record.delayBody);
}

if (anyFlagPresent(['magic', 'headers'])) {
// add new headers
const reqheaders = {
Expand Down
2 changes: 1 addition & 1 deletion test/hot.js
Expand Up @@ -6,7 +6,7 @@ import { URL } from 'url';
const lookup = {};

export const resolve = async (specifier, context, defaultResolve) => {
const result = defaultResolve(specifier, context, defaultResolve);
const result = await defaultResolve(specifier, context, defaultResolve);
const child = new URL(result.url);

if (
Expand Down
35 changes: 26 additions & 9 deletions test/modules/request-recorder.spec.js
Expand Up @@ -253,7 +253,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
reqheaders: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
'user-agent': 'axios/0.26.1',
'user-agent': 'axios/0.27.2',
'content-length': 59
},
response: { data: `${id}` },
Expand Down Expand Up @@ -305,9 +305,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
expect(get(content, [0, 'body', 'payload'], null)).to.equal(null);
}
};
mkRequest = async () => {
await axios(server.uri);
};
mkRequest = async () => axios(server.uri);
});

it('Testing without healing', async () => {
Expand Down Expand Up @@ -417,7 +415,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
'content-type': 'application/json',
host: server.host,
'content-length': 59,
'user-agent': 'axios/0.26.1'
'user-agent': 'axios/0.27.2'
}
}),
makeCassetteEntry(3)
Expand Down Expand Up @@ -446,7 +444,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
'content-type': 'application/json',
host: server.host,
'content-length': 59,
'user-agent': 'axios/0.26.1'
'user-agent': 'axios/0.27.2'
}
}),
makeCassetteEntry(3)
Expand All @@ -467,7 +465,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
reqheaders: {
accept: 'application/json, text/plain, */*',
host: server.host,
'user-agent': 'axios/0.26.1'
'user-agent': 'axios/0.27.2'
},
response: {},
responseIsBinary: false,
Expand Down Expand Up @@ -503,7 +501,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
path: '/?q=1',
reqheaders: {
accept: 'application/json, text/plain, */*',
host: `${server2.host} @ axios/0.26.1`,
host: `${server2.host} @ axios/0.27.2`,
'user-agent': '^axios/.*$'
},
response: {
Expand Down Expand Up @@ -535,6 +533,25 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
]);
});

it('Testing delay', async () => {
const cassettePath = path.join(tmpDir, cassetteFile);
fs.smartWrite(cassettePath, [
makeCassetteEntry(1),
Object.assign(makeCassetteEntry(2), {
delayBody: 500,
delayConnection: 500
})
]);
const startTime = process.hrtime();
await runTest({
heal: false,
qs: [1, 2]
});
const elapsed = process.hrtime(startTime);
const elapsedSeconds = elapsed[0] + (elapsed[1] / 1e9);
expect(elapsedSeconds).to.be.greaterThan(1);
});

it('Testing stub (empty cassette)', async ({ capture }) => {
const cassettePath = path.join(tmpDir, cassetteFile);
fs.smartWrite(cassettePath, []);
Expand All @@ -547,7 +564,7 @@ describe('Testing RequestRecorder', { useTmpDir: true, timestamp: 0 }, () => {
path: '/',
reqheaders: {
accept: 'application/json, text/plain, */*',
'user-agent': 'axios/0.26.1'
'user-agent': 'axios/0.27.2'
},
response: {},
responseIsBinary: false,
Expand Down

0 comments on commit 55a0860

Please sign in to comment.