forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a bug causing custom async matcher stack traces to be lost. The issue was caused by the JestAssertionError being created after the promise for the async matcher resolved - by which point the stack containing the correct stack trace (pointing to the line where matcher was called) has been discarded. The issue was fixed by passing the error that is created before the promise resolves.
- Loading branch information
Don Schrimsher
committed
Jan 15, 2019
1 parent
805ec3c
commit 7640a08
Showing
7 changed files
with
350 additions
and
237 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
e2e/__tests__/__snapshots__/customAsyncMatcherStackTrace.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`showing the line number and code fence for custom async matchers 1`] = ` | ||
Object { | ||
"rest": "FAIL __tests__/test.js | ||
✕ showing the line number and code fence for custom async matchers | ||
● showing the line number and code fence for custom async matchers | ||
The line number and code fence for this error should be shown properly | ||
11 | | ||
12 | test('showing the line number and code fence for custom async matchers', async () => { | ||
> 13 | await expect(true).failingAsyncMatcher(); | ||
| ^ | ||
14 | }); | ||
15 | | ||
16 | async function failingAsyncMatcher() { | ||
at Object.failingAsyncMatcher (__tests__/test.js:13:22) | ||
", | ||
"summary": "Test Suites: 1 failed, 1 total | ||
Tests: 1 failed, 1 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites matching /test.js/i. | ||
", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import path from 'path'; | ||
import runJest from '../runJest'; | ||
import {extractSummary} from '../Utils'; | ||
const dir = path.resolve(__dirname, '../custom-async-matcher-stack-trace'); | ||
|
||
test('showing the line number and code fence for custom async matchers', () => { | ||
const testOutput = runJest(dir, ['test.js']); | ||
const result = extractSummary(testOutput.stderr); | ||
|
||
expect(result).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
expect.extend({failingAsyncMatcher}); | ||
|
||
test('showing the line number and code fence for custom async matchers', async () => { | ||
await expect(true).failingAsyncMatcher(); | ||
}); | ||
|
||
async function failingAsyncMatcher() { | ||
const message = () => | ||
'The line number and code fence for this error should be shown properly'; | ||
const pass = false; | ||
|
||
return {message, pass}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
class JestAssertionError extends Error { | ||
matcherResult: any; | ||
} | ||
|
||
export default JestAssertionError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.