Skip to content

Commit f527647

Browse files
authored
[jest-circus] fix stack frame for test timeout (#6303)
* [jest-circus] fix stack frame for test timeout * increase test timeout * normalize jasmine and circus
1 parent f976da6 commit f527647

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

integration-tests/__tests__/__snapshots__/failures.test.js.snap

+6-7
Original file line numberDiff line numberDiff line change
@@ -390,23 +390,22 @@ exports[`works with async failures 1`] = `
390390
| ^
391391
25 | });
392392
26 |
393-
27 | test('timeout', done => {
393+
27 | test(
394394
395395
at __tests__/async_failures.test.js:24:10
396396
397397
timeout
398398
399-
Timeout - Async callback was not invoked within the 5ms timeout specified by jest.setTimeout.
399+
<REPLACED>
400400
401401
25 | });
402402
26 |
403-
> 27 | test('timeout', done => {
403+
> 27 | test(
404404
| ^
405-
28 | jest.setTimeout(5);
406-
29 |
407-
30 | setTimeout(done, 10);
405+
28 | 'timeout',
406+
29 | done => {
407+
30 | setTimeout(done, 50);
408408
409-
at packages/jest-jasmine2/build/jasmine/Spec.js:85:20
410409
at __tests__/async_failures.test.js:27:1
411410
412411
"

integration-tests/__tests__/failures.test.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
* @flow
88
*/
99

10-
import skipOnJestCircus from '../../scripts/SkipOnJestCircus';
11-
skipOnJestCircus.suite();
12-
1310
const path = require('path');
1411
const SkipOnWindows = require('../../scripts/SkipOnWindows');
1512
const {extractSummary} = require('../Utils');
@@ -156,12 +153,18 @@ test('works with assertions in separate files', () => {
156153
test('works with async failures', () => {
157154
const {stderr} = runJest(dir, ['async_failures.test.js']);
158155

159-
const rest = extractSummary(stderr)
160-
.rest.split('\n')
156+
const rest = cleanStderr(stderr)
157+
.split('\n')
161158
.filter(line => line.indexOf('packages/expect/build/index.js') === -1)
162159
.join('\n');
163160

164-
expect(normalizeDots(rest)).toMatchSnapshot();
161+
// Remove replacements when jasmine is gone
162+
const result = normalizeDots(rest)
163+
.replace(/.*thrown:.*\n/, '')
164+
.replace(/.*Use jest\.setTimeout\(newTimeout\).*/, '<REPLACED>')
165+
.replace(/.*Timeout - Async callback was not.*/, '<REPLACED>');
166+
167+
expect(result).toMatchSnapshot();
165168
});
166169

167170
test('works with snapshot failures', () => {

integration-tests/failures/__tests__/async_failures.test.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ test('expect resolve', () => {
2424
return expect(Promise.reject({foo: 'bar'})).resolves.toEqual({foo: 'bar'});
2525
});
2626

27-
test('timeout', done => {
28-
jest.setTimeout(5);
29-
30-
setTimeout(done, 10);
31-
});
27+
test(
28+
'timeout',
29+
done => {
30+
setTimeout(done, 50);
31+
},
32+
5
33+
);

packages/jest-circus/src/utils.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ export const getEachHooksForTest = (
132132
};
133133

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

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

0 commit comments

Comments
 (0)