-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add failureDetails property to circus test results
#9496
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
Merged
SimenB
merged 6 commits into
jestjs:master
from
G-Rath:include-matcher-results-in-circus
Aug 1, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5aa0c7a
Add `failureDetails` property to circus test results
G-Rath 1ebbed2
fix(jest-circus): format `errorsDetailed` for test results
G-Rath 53f97bc
reuse errors instead of recreating
SimenB 4d691a9
chore: populate failureDetails parray
G-Rath d34fe6c
Add test for `failureDetails` property
G-Rath eea5f42
docs: update `CHANGELOG.md`
G-Rath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,217 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
|
|
||
| import {isJestCircusRun} from '@jest/test-utils'; | ||
| import runJest from '../runJest'; | ||
|
|
||
| const removeStackTraces = (stdout: string) => | ||
| stdout.replace( | ||
| /at (new Promise \(<anonymous>\)|.+:\d+:\d+\)?)/g, | ||
| 'at <stacktrace>', | ||
| ); | ||
|
|
||
| test('that the failureDetails property is set', () => { | ||
| const {stdout, stderr} = runJest('failureDetails-property', [ | ||
| 'tests.test.js', | ||
| ]); | ||
|
|
||
| // safety check: if the reporter errors it'll show up here | ||
| expect(stderr).toStrictEqual(''); | ||
|
|
||
| const output = JSON.parse(removeStackTraces(stdout)); | ||
|
|
||
| if (isJestCircusRun()) { | ||
| expect(output).toMatchInlineSnapshot(` | ||
| Array [ | ||
| Array [ | ||
| Object { | ||
| "matcherResult": Object { | ||
| "actual": true, | ||
| "expected": false, | ||
| "name": "toBe", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "matcherResult": Object { | ||
| "actual": true, | ||
| "expected": false, | ||
| "name": "toBe", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "matcherResult": Object { | ||
| "actual": "Object { | ||
| \\"p1\\": \\"hello\\", | ||
| \\"p2\\": \\"world\\", | ||
| }", | ||
| "expected": "Object { | ||
| \\"p1\\": \\"hello\\", | ||
| \\"p2\\": \\"sunshine\\", | ||
| }", | ||
| "name": "toMatchInlineSnapshot", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object {}, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "message": "expect(received).rejects.toThrowError() | ||
|
|
||
| Received promise resolved instead of rejected | ||
| Resolved to value: 1", | ||
| }, | ||
| ], | ||
| ] | ||
| `); | ||
| } else { | ||
| expect(output).toMatchInlineSnapshot(` | ||
| Array [ | ||
| Array [ | ||
| Object { | ||
| "actual": "", | ||
| "error": Object { | ||
| "matcherResult": Object { | ||
| "actual": true, | ||
| "expected": false, | ||
| "name": "toBe", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| "expected": "", | ||
| "matcherName": "", | ||
| "message": "Error: expect(received).toBe(expected) // Object.is equality | ||
|
|
||
| Expected: false | ||
| Received: true", | ||
| "passed": false, | ||
| "stack": "Error: expect(received).toBe(expected) // Object.is equality | ||
|
|
||
| Expected: false | ||
| Received: true | ||
| at <stacktrace>", | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "actual": "", | ||
| "error": Object { | ||
| "matcherResult": Object { | ||
| "actual": true, | ||
| "expected": false, | ||
| "name": "toBe", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| "expected": "", | ||
| "matcherName": "", | ||
| "message": "Error: expect(received).toBe(expected) // Object.is equality | ||
|
|
||
| Expected: false | ||
| Received: true", | ||
| "passed": false, | ||
| "stack": "Error: expect(received).toBe(expected) // Object.is equality | ||
|
|
||
| Expected: false | ||
| Received: true | ||
| at <stacktrace>", | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "actual": "", | ||
| "error": Object { | ||
| "matcherResult": Object { | ||
| "actual": "Object { | ||
| \\"p1\\": \\"hello\\", | ||
| \\"p2\\": \\"world\\", | ||
| }", | ||
| "expected": "Object { | ||
| \\"p1\\": \\"hello\\", | ||
| \\"p2\\": \\"sunshine\\", | ||
| }", | ||
| "name": "toMatchInlineSnapshot", | ||
| "pass": false, | ||
| }, | ||
| }, | ||
| "expected": "", | ||
| "matcherName": "", | ||
| "message": "expect(received).toMatchInlineSnapshot(snapshot) | ||
|
|
||
| Snapshot name: \`my test a snapshot failure 1\` | ||
|
|
||
| - Snapshot - 1 | ||
| + Received + 1 | ||
|
|
||
| Object { | ||
| \\"p1\\": \\"hello\\", | ||
| - \\"p2\\": \\"sunshine\\", | ||
| + \\"p2\\": \\"world\\", | ||
| }", | ||
| "passed": false, | ||
| "stack": "Error: expect(received).toMatchInlineSnapshot(snapshot) | ||
|
|
||
| Snapshot name: \`my test a snapshot failure 1\` | ||
|
|
||
| - Snapshot - 1 | ||
| + Received + 1 | ||
|
|
||
| Object { | ||
| \\"p1\\": \\"hello\\", | ||
| - \\"p2\\": \\"sunshine\\", | ||
| + \\"p2\\": \\"world\\", | ||
| } | ||
| at <stacktrace>", | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "actual": "", | ||
| "error": Object {}, | ||
| "expected": "", | ||
| "matcherName": "", | ||
| "message": "Error", | ||
| "passed": false, | ||
| "stack": "Error: | ||
| at <stacktrace>", | ||
| }, | ||
| ], | ||
| Array [ | ||
| Object { | ||
| "actual": "", | ||
| "error": Object { | ||
| "message": "expect(received).rejects.toThrowError() | ||
|
|
||
| Received promise resolved instead of rejected | ||
| Resolved to value: 1", | ||
| }, | ||
| "expected": "", | ||
| "matcherName": "", | ||
| "message": "Error: expect(received).rejects.toThrowError() | ||
|
|
||
| Received promise resolved instead of rejected | ||
| Resolved to value: 1", | ||
| "passed": false, | ||
| "stack": "Error: expect(received).rejects.toThrowError() | ||
|
|
||
| Received promise resolved instead of rejected | ||
| Resolved to value: 1 | ||
| at <stacktrace>", | ||
| }, | ||
| ], | ||
| ] | ||
| `); | ||
| } | ||
| }); |
This file contains hidden or 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,37 @@ | ||
| /** | ||
| * 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'; | ||
|
|
||
| describe('my test', () => { | ||
| test('it passes', () => { | ||
| expect(true).toBe(false); | ||
| }); | ||
|
|
||
| it('fails :(', () => { | ||
| expect(true).toBe(false); | ||
| }); | ||
|
|
||
| test('a snapshot failure', () => { | ||
| expect({ | ||
| p1: 'hello', | ||
| p2: 'world', | ||
| }).toMatchInlineSnapshot(` | ||
| Object { | ||
| "p1": "hello", | ||
| "p2": "sunshine", | ||
| } | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| it('throws!', () => { | ||
| throw new Error(); | ||
| }); | ||
|
|
||
| test('promise rejection', async () => { | ||
| await expect(Promise.resolve(1)).rejects.toThrowError(); | ||
| }); |
This file contains hidden or 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'; | ||
|
|
||
| class MyCustomReporter { | ||
| onRunComplete(contexts, results) { | ||
| console.log( | ||
| JSON.stringify( | ||
| results.testResults[0].testResults.map(f => f.failureDetails), | ||
| null, | ||
| 2, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| module.exports = MyCustomReporter; | ||
This file contains hidden or 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,8 @@ | ||
| { | ||
| "jest": { | ||
| "testEnvironment": "node", | ||
| "reporters": [ | ||
| "<rootDir>/myreporter.js" | ||
| ] | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.