Skip to content

Commit

Permalink
Merge branch 'depfu/update/npm/prettier-2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Mar 29, 2020
2 parents c1d52fd + c757951 commit 071c835
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 98 deletions.
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
language: node_js
node_js:
- '8'
- '10'
- 'node'
script: 'npm run ci'
- 8
- 10
- 12
- node

matrix:
include:
- name: Lint
node_js: 12
script: npm run lint

script: npm run test:ci
after_success: '<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js'
2 changes: 1 addition & 1 deletion integration-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
rootDir: require('path').resolve(__dirname, '..'),
testEnvironment: 'node',
testMatch: ['<rootDir>/integration-test/tmp/httpception.jest*.js']
testMatch: ['<rootDir>/integration-test/tmp/httpception.jest*.js'],
};
76 changes: 39 additions & 37 deletions integration-test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const expect = require('unexpected').clone();
const pathModule = require('path');
const childProcess = require('child_process');

describe('in afterEach mode', function() {
describe('in afterEach mode', function () {
const fs = expect.promise.promisifyAll(require('fs'));
const tmpDir = pathModule.resolve(__dirname, 'tmp');

Expand Down Expand Up @@ -30,7 +30,7 @@ describe('in afterEach mode', function() {
}

const code = subject.toString().replace(/^[^{]+\{|\}\s*$/g, '');
expect.subjectOutput = function(output) {
expect.subjectOutput = function (output) {
output.code(code, 'javascript');
};
const tmpFileName = pathModule.resolve(
Expand Down Expand Up @@ -63,20 +63,22 @@ describe('in afterEach mode', function() {
return fs
.writeFileAsync(tmpFileName, preamble + code, 'utf-8')
.then(() =>
expect.promise.fromNode(cb =>
expect.promise.fromNode((cb) =>
childProcess.exec(testCommand, cb.bind(null, null))
)
)
.then(output => expect.shift({ stdout: output[1], stderr: output[2] }))
.then((output) =>
expect.shift({ stdout: output[1], stderr: output[2] })
)
.finally(() => fs.unlinkAsync(tmpFileName));
}
);

it('should succeed when the correct HTTP request is made', function() {
it('should succeed when the correct HTTP request is made', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception({ request: 'GET /', response: 200 });
return expect('GET /', 'to yield response', 200);
});
Expand All @@ -86,42 +88,42 @@ describe('in afterEach mode', function() {
{
stdout: expect
.it('to contain', '✓ should foo')
.and('to contain', '1 passing')
.and('to contain', '1 passing'),
}
).and('when run through jest to satisfy', {
stderr: expect
.it('to contain', '✓ should foo')
.and('to contain', '1 passed, 1 total')
.and('to contain', '1 passed, 1 total'),
});
});

it('should fail with a diff when too few requests are made', function() {
it('should fail with a diff when too few requests are made', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception({ request: 'GET /', response: 200 });
});
/* eslint-enable */
},
'when run through mocha to satisfy',
{
stdout: /"after each" hook for "should foo"[\s\S]*\/\/ missing:\n\/\/ GET \/\n/,
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
.it('to contain', '✕ should foo')
.and('to contain', '1 failed, 1 total')
.and('not to contain', 'UnhandledPromiseRejection')
.and('not to contain', 'UnhandledPromiseRejection'),
});
});

it('should fail with a diff when a request does not match the mocked out traffic', function() {
it('should fail with a diff when a request does not match the mocked out traffic', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception({ request: 'GET /foo', response: 200 });
return expect('/bar', 'to yield response', 200);
});
Expand All @@ -139,7 +141,7 @@ describe('in afterEach mode', function() {
'\n' +
'HTTP/1.1 200 OK\n'
),
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
Expand All @@ -154,20 +156,20 @@ describe('in afterEach mode', function() {
'\n' +
' HTTP/1.1 200 OK\n'
)
.and('to contain', '1 failed, 1 total')
.and('to contain', '1 failed, 1 total'),
});
});

it('should fail with a diff the first test out of two fails', function() {
it('should fail with a diff the first test out of two fails', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception({ request: 'GET /foo', response: 200 });
return expect('/bar', 'to yield response', 200);
});

it('should bar', function() {
it('should bar', function () {
httpception({ request: 'GET /foo', response: 200 });
return expect('GET /bar', 'to yield response', 200);
});
Expand All @@ -185,7 +187,7 @@ describe('in afterEach mode', function() {
'\n' +
'HTTP/1.1 200 OK\n'
),
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
Expand All @@ -200,20 +202,20 @@ describe('in afterEach mode', function() {
'\n' +
' HTTP/1.1 200 OK\n'
)
.and('to contain', '1 failed, 1 total')
.and('to contain', '1 failed, 1 total'),
});
});

it('should fail with a diff the second test out of two fails', function() {
it('should fail with a diff the second test out of two fails', function () {
return expect(
() => {
/* eslint-disable */
it('should bar', function() {
it('should bar', function () {
httpception({ request: 'GET /foo', response: 200 });
return expect('GET /bar', 'to yield response', 200);
});

it('should foo', function() {
it('should foo', function () {
httpception({ request: 'GET /foo', response: 200 });
return expect('/bar', 'to yield response', 200);
});
Expand All @@ -231,7 +233,7 @@ describe('in afterEach mode', function() {
'\n' +
'HTTP/1.1 200 OK\n'
),
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
Expand All @@ -246,19 +248,19 @@ describe('in afterEach mode', function() {
'\n' +
' HTTP/1.1 200 OK\n'
)
.and('to contain', '1 failed, 1 total')
.and('to contain', '1 failed, 1 total'),
});
});

it('should error with more than one req', function() {
it('should error with more than one req', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception([
{ request: 'GET /foo', response: 200 },
{ request: 'GET /bar', response: 200 },
{ request: 'GET /baz', response: 200 }
{ request: 'GET /baz', response: 200 },
]);

return expect('/foo', 'to yield response', 200).then(() =>
Expand All @@ -276,7 +278,7 @@ describe('in afterEach mode', function() {
' // -GET /foo HTTP/1.1\n' +
' // +GET /bar HTTP/1.1'
),
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
Expand All @@ -288,25 +290,25 @@ describe('in afterEach mode', function() {
' // -GET /foo HTTP/1.1\n' +
' // +GET /bar HTTP/1.1'
)
.and('to contain', '1 failed, 1 total')
.and('to contain', '1 failed, 1 total'),
});
});

it('should error from both afterEach and the it block', function() {
it('should error from both afterEach and the it block', function () {
return expect(
() => {
/* eslint-disable */
it('should foo', function() {
it('should foo', function () {
httpception([
{ request: 'GET /foo', response: 200 },
{ request: 'GET /bar', response: 200 },
{ request: 'GET /baz', response: 200 }
{ request: 'GET /baz', response: 200 },
]);

return expect('/foo', 'to yield response', 200)
.then(() => expect('/foo', 'to yield response', 200))
.catch(
err =>
(err) =>
new Promise((resolve, reject) => {
const actualError = new Error('Actual Error');
setTimeout(() => reject(actualError), 500);
Expand All @@ -320,7 +322,7 @@ describe('in afterEach mode', function() {
stdout: expect
.it('to contain', '1) should foo')
.and('to contain', '2) "after each" hook for "should foo"'),
stderr: expect.it('not to contain', 'UnhandledPromiseRejection')
stderr: expect.it('not to contain', 'UnhandledPromiseRejection'),
}
).and('when run through jest to satisfy', {
stderr: expect
Expand All @@ -337,7 +339,7 @@ describe('in afterEach mode', function() {
' // -GET /foo HTTP/1.1\n' +
' // +GET /bar HTTP/1.1'
)
.and('to contain', '1 failed, 1 total')
.and('to contain', '1 failed, 1 total'),
});
});
});
28 changes: 14 additions & 14 deletions lib/httpception.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var afterEachRegistered = false;
function ensureAfterEachIsRegistered() {
if (typeof afterEach === 'function' && !afterEachRegistered) {
afterEachRegistered = true;
afterEach(function() {
afterEach(function () {
mockDefinitionForTheCurrentTest = undefined;
var promiseForThisTest = promise;
promise = undefined;
Expand All @@ -28,16 +28,16 @@ var expect = require('unexpected').clone();
expect.use(require('unexpected-mitm/lib/mockerAssertions'));

var originalChildMethod = expect.child;
expect.child = function() {
expect.child = function () {
// ...
var child = originalChildMethod.apply(expect, arguments);
child.notifyPendingPromise = function() {};
child.notifyPendingPromise = function () {};
return child;
};

expect.addAssertion(
'<function> to perform HTTP traffic <array|object>',
function(expect, promiseFactory, mockDefinition) {
function (expect, promiseFactory, mockDefinition) {
expect.errorMode = 'default';
return expect(mocker, 'to be complete');
}
Expand Down Expand Up @@ -69,7 +69,7 @@ module.exports = function httpception(mockDefinition, promiseFactory) {
mocker =
mocker ||
new UnexpectedMitmMocker({
requestDescriptions: mockDefinitionForTheCurrentTest
requestDescriptions: mockDefinitionForTheCurrentTest,
});

if (promiseFactory) {
Expand All @@ -89,33 +89,33 @@ module.exports = function httpception(mockDefinition, promiseFactory) {

return mocker
.mock(promiseFactory)
.then(function() {
.then(function () {
return expect(
promiseFactory,
'to perform HTTP traffic',
mocker.requestDescriptions
);
})
.then(function() {
.then(function () {
mocker = undefined;
})
.catch(function(e) {
.catch(function (e) {
mocker = undefined;
throw e;
});
} else if (!promise) {
var resolvePromise = expect.promise(function(resolve, reject) {
var resolvePromise = expect.promise(function (resolve, reject) {
resolveFromAfterEach = resolve;
});

var mockerPromise = expect.promise(function() {
return mocker.mock(function() {
var mockerPromise = expect.promise(function () {
return mocker.mock(function () {
return resolvePromise;
});
});

promise = Promise.all([resolvePromise, mockerPromise])
.then(result => {
.then((result) => {
const functionToInspect =
promiseFactoryForCurrentTest || function afterEach() {};

Expand All @@ -127,10 +127,10 @@ module.exports = function httpception(mockDefinition, promiseFactory) {
mocker.requestDescriptions
);
})
.then(function() {
.then(function () {
mocker = undefined;
})
.catch(function(e) {
.catch(function (e) {
mocker = undefined;
throw e;
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test-integration": "mocha integration-test/test.js --timeout 30000",
"test-mocha": "mocha --opts test/mocha/mocha.opts",
"test-jest": "if ( node-version-gte-6 ); then jest --config test/jest/jest.config.js; fi",
"ci": "npm test && npm run lint && npm run coverage",
"test:ci": "npm run coverage",
"coverage": "NODE_ENV=development nyc --reporter=lcov --reporter=text --all -- npm run coverage-test && echo google-chrome coverage/lcov-report/index.html",
"coverage-test": "npm run test-mocha && JEST=false npm run test-integration"
},
Expand Down Expand Up @@ -37,7 +37,7 @@
"mocha": "^7.0.0",
"node-version-check": "^2.2.0",
"nyc": "^15.0.0",
"prettier": "~1.19.1",
"prettier": "~2.0.2",
"unexpected-http": "^7.0.0"
},
"nyc": {
Expand Down
Loading

0 comments on commit 071c835

Please sign in to comment.