Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest-circus] fix stack frame for test timeout #6303

Merged
merged 3 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -124,11 +124,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.`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more timeouts please!


// 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