Skip to content

Commit

Permalink
[jest-circus] fix stack frame for test timeout (#6303)
Browse files Browse the repository at this point in the history
* [jest-circus] fix stack frame for test timeout

* increase test timeout

* normalize jasmine and circus
  • Loading branch information
SimenB committed May 27, 2018
1 parent f976da6 commit f527647
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
13 changes: 6 additions & 7 deletions integration-tests/__tests__/__snapshots__/failures.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,22 @@ exports[`works with async failures 1`] = `
| ^
25 | });
26 |
27 | test('timeout', done => {
27 | test(
at __tests__/async_failures.test.js:24:10
timeout
Timeout - Async callback was not invoked within the 5ms timeout specified by jest.setTimeout.
<REPLACED>
25 | });
26 |
> 27 | test('timeout', done => {
> 27 | test(
| ^
28 | jest.setTimeout(5);
29 |
30 | setTimeout(done, 10);
28 | 'timeout',
29 | done => {
30 | setTimeout(done, 50);
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
at __tests__/async_failures.test.js:27:1
"
Expand Down
15 changes: 9 additions & 6 deletions integration-tests/__tests__/failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* @flow
*/

import skipOnJestCircus from '../../scripts/SkipOnJestCircus';
skipOnJestCircus.suite();

const path = require('path');
const SkipOnWindows = require('../../scripts/SkipOnWindows');
const {extractSummary} = require('../Utils');
Expand Down Expand Up @@ -156,12 +153,18 @@ test('works with assertions in separate files', () => {
test('works with async failures', () => {
const {stderr} = runJest(dir, ['async_failures.test.js']);

const rest = extractSummary(stderr)
.rest.split('\n')
const rest = cleanStderr(stderr)
.split('\n')
.filter(line => line.indexOf('packages/expect/build/index.js') === -1)
.join('\n');

expect(normalizeDots(rest)).toMatchSnapshot();
// Remove replacements when jasmine is gone
const result = normalizeDots(rest)
.replace(/.*thrown:.*\n/, '')
.replace(/.*Use jest\.setTimeout\(newTimeout\).*/, '<REPLACED>')
.replace(/.*Timeout - Async callback was not.*/, '<REPLACED>');

expect(result).toMatchSnapshot();
});

test('works with snapshot failures', () => {
Expand Down
12 changes: 7 additions & 5 deletions integration-tests/failures/__tests__/async_failures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ test('expect resolve', () => {
return expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'});
});

test('timeout', done => {
jest.setTimeout(5);

setTimeout(done, 10);
});
test(
'timeout',
done => {
setTimeout(done, 50);
},
5
);
8 changes: 3 additions & 5 deletions packages/jest-circus/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ export const getEachHooksForTest = (
};

const _makeTimeoutMessage = (timeout, isHook) =>
new Error(
`Exceeded timeout of ${timeout}ms for a ${
isHook ? 'hook' : 'test'
}.\nUse jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.`,
);
`Exceeded timeout of ${timeout}ms for a ${
isHook ? 'hook' : 'test'
}.\nUse jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.`;

// Global values can be overwritten by mocks or tests. We'll capture
// the original values in the variables before we require any files.
Expand Down

0 comments on commit f527647

Please sign in to comment.