Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
81bb4c0
Properly report Error cause from test/it
dubzzz Feb 19, 2023
e972e71
fix lint
dubzzz Feb 19, 2023
e2ffe8b
rework paths in tests
dubzzz Feb 19, 2023
3c1cceb
add support for old versions of node
dubzzz Feb 19, 2023
d7524b2
update snap
dubzzz Feb 19, 2023
e42a55e
Update packages/jest-message-util/src/index.ts
dubzzz Feb 19, 2023
56ebf8c
Update packages/jest-message-util/src/index.ts
dubzzz Feb 19, 2023
b0514ee
fix compilation
dubzzz Feb 19, 2023
156a1cf
extract error stack computation function
dubzzz Feb 20, 2023
8e763e7
rename option failureDetails
dubzzz Feb 20, 2023
046875a
update changelog
dubzzz Feb 20, 2023
f556c7a
add failures.test.ts
dubzzz Feb 20, 2023
39bf317
add error with cause support on node 14
dubzzz Feb 21, 2023
0e24922
update error with cause builder
dubzzz Feb 21, 2023
cf96b70
add missing failureDetails: []
dubzzz Feb 21, 2023
d4b5e47
fix new case for jasmine
dubzzz Feb 21, 2023
22df9f7
alter test to run well on jasmine too
dubzzz Feb 21, 2023
b0bd8a1
Revert "alter test to run well on jasmine too"
dubzzz Feb 21, 2023
238590e
Revert "fix new case for jasmine"
dubzzz Feb 21, 2023
808336b
only test for non-jasmine
dubzzz Feb 21, 2023
54df836
Merge remote-tracking branch 'origin/master' into rewrite-stack-extra…
dubzzz Feb 21, 2023
fdd56ca
merge
dubzzz Feb 21, 2023
5b3c4ad
Merge branch 'main' into rewrite-stack-extraction
SimenB Feb 22, 2023
56422b5
Merge remote-tracking branch 'origin/master' into rewrite-stack-extra…
dubzzz Feb 23, 2023
81295f7
simplify and extract nested if
dubzzz Feb 23, 2023
c6fa4a9
type error
dubzzz Feb 23, 2023
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
Prev Previous commit
Next Next commit
add failures.test.ts
  • Loading branch information
dubzzz committed Feb 20, 2023
commit f556c7a2f4a11345957bc39582788e6586f445b8
102 changes: 102 additions & 0 deletions e2e/__tests__/__snapshots__/failures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,108 @@ exports[`works with async failures 1`] = `
at Object.test (__tests__/asyncFailures.test.js:22:1)"
`;

exports[`works with error with cause 1`] = `
"FAIL __tests__/errorWithCause.test.js
✕ error with cause in test
describe block
✕ error with cause in describe/it

● error with cause in test

error during f

16 | g();
17 | } catch (err) {
> 18 | throw new Error('error during f', {cause: err});
| ^
19 | }
20 | }
21 |

at f (__tests__/errorWithCause.test.js:18:11)
at Object.f (__tests__/errorWithCause.test.js:23:3)

Cause:
error during g

10 |
11 | function g() {
> 12 | throw new Error('error during g');
| ^
13 | }
14 | function f() {
15 | try {

at g (__tests__/errorWithCause.test.js:12:9)
at g (__tests__/errorWithCause.test.js:16:5)
at Object.f (__tests__/errorWithCause.test.js:23:3)

● describe block › error with cause in describe/it

error during f

16 | g();
17 | } catch (err) {
> 18 | throw new Error('error during f', {cause: err});
| ^
19 | }
20 | }
21 |

at f (__tests__/errorWithCause.test.js:18:11)
at Object.f (__tests__/errorWithCause.test.js:28:5)

Cause:
error during g

10 |
11 | function g() {
> 12 | throw new Error('error during g');
| ^
13 | }
14 | function f() {
15 | try {

at g (__tests__/errorWithCause.test.js:12:9)
at g (__tests__/errorWithCause.test.js:16:5)
at Object.f (__tests__/errorWithCause.test.js:28:5)"
`;

exports[`works with error with cause thrown outside tests 1`] = `
"FAIL __tests__/errorWithCauseInDescribe.test.js
● Test suite failed to run

error during f

16 | g();
17 | } catch (err) {
> 18 | throw new Error('error during f', {cause: err});
| ^
19 | }
20 | }
21 |

at f (__tests__/errorWithCauseInDescribe.test.js:18:11)
at f (__tests__/errorWithCauseInDescribe.test.js:23:3)
at Object.describe (__tests__/errorWithCauseInDescribe.test.js:22:1)

Cause:
error during g

10 |
11 | function g() {
> 12 | throw new Error('error during g');
| ^
13 | }
14 | function f() {
15 | try {

at g (__tests__/errorWithCauseInDescribe.test.js:12:9)
at g (__tests__/errorWithCauseInDescribe.test.js:16:5)
at f (__tests__/errorWithCauseInDescribe.test.js:23:3)
at Object.describe (__tests__/errorWithCauseInDescribe.test.js:22:1)"
`;

exports[`works with node assert 1`] = `
"FAIL __tests__/assertionError.test.js
✕ assert
Expand Down
14 changes: 14 additions & 0 deletions e2e/__tests__/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ test('works with snapshot failures with hint', () => {
).toMatchSnapshot();
});

test('works with error with cause', () => {
const {stderr} = runJest(dir, ['errorWithCause.test.js']);
const summary = normalizeDots(cleanStderr(stderr));

expect(summary).toMatchSnapshot();
});

test('works with error with cause thrown outside tests', () => {
const {stderr} = runJest(dir, ['errorWithCauseInDescribe.test.js']);
const summary = normalizeDots(cleanStderr(stderr));

expect(summary).toMatchSnapshot();
});

test('errors after test has completed', () => {
const {stderr} = runJest(dir, ['errorAfterTestComplete.test.js']);

Expand Down
30 changes: 30 additions & 0 deletions e2e/failures/__tests__/errorWithCause.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

function g() {
throw new Error('error during g');
}
function f() {
try {
g();
} catch (err) {
throw new Error('error during f', {cause: err});
}
}

test('error with cause in test', () => {
f();
});

describe('describe block', () => {
it('error with cause in describe/it', () => {
f();
});
});
24 changes: 24 additions & 0 deletions e2e/failures/__tests__/errorWithCauseInDescribe.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

'use strict';

function g() {
throw new Error('error during g');
}
function f() {
try {
g();
} catch (err) {
throw new Error('error during f', {cause: err});
}
}

describe('error with cause in describe', () => {
f();
});