-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Codeframe fixes #5094
Merged
Merged
Codeframe fixes #5094
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f6b9df
fix(jest-message-util): handle expectation being in another file from…
SimenB b89e000
fix(jest-message-util): exclude codeframes from node_modules
SimenB 26ff79c
style: flow fixes
SimenB 6861446
test: update snapshots
SimenB bd5a1f8
fix(jest-message-util): don't try to read relative paths
SimenB 9d52162
fix(jest-message-util): strip `next (native)` from stack
SimenB c66f3f7
fix(jest-message-util): don't try to read non-existent files
SimenB 620787c
fix(jest-message-util): make sure the frame chosen has a filename in it
SimenB 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 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 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 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
13 changes: 13 additions & 0 deletions
13
integration_tests/failures/__tests__/async_failures.test.js
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,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
'use strict'; | ||
|
||
test('something async', () => { | ||
return expect(Promise.resolve({foo: 'bar'})).resolves.toEqual({baz: 'bar'}); | ||
}); |
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,15 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
'use strict'; | ||
|
||
const shouldEqual = require('../macros'); | ||
|
||
test('use some imported macro to make assertion', () => { | ||
shouldEqual(1, 2); | ||
}); |
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,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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'; | ||
|
||
module.exports = (one: any, two: any) => { | ||
expect(one).toEqual(two); | ||
}; |
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 |
---|---|---|
|
@@ -18,6 +18,11 @@ import slash from 'slash'; | |
import {codeFrameColumns} from '@babel/code-frame'; | ||
import StackUtils from 'stack-utils'; | ||
|
||
// stack utils tries to create pretty stack by making paths relative. | ||
const stackUtils = new StackUtils({ | ||
cwd: 'something which does not exist', | ||
}); | ||
|
||
let nodeInternals = []; | ||
|
||
try { | ||
|
@@ -45,6 +50,7 @@ const JEST_INTERNALS_IGNORE = /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|pa | |
const ANONYMOUS_FN_IGNORE = /^\s+at <anonymous>.*$/; | ||
const ANONYMOUS_PROMISE_IGNORE = /^\s+at (new )?Promise \(<anonymous>\).*$/; | ||
const ANONYMOUS_GENERATOR_IGNORE = /^\s+at Generator.next \(<anonymous>\).*$/; | ||
const NATIVE_NEXT_IGNORE = /^\s+at next \(native\).*$/; | ||
const TITLE_INDENT = ' '; | ||
const MESSAGE_INDENT = ' '; | ||
const STACK_INDENT = ' '; | ||
|
@@ -136,6 +142,10 @@ const removeInternalStackEntries = (lines, options: StackTraceOptions) => { | |
return false; | ||
} | ||
|
||
if (NATIVE_NEXT_IGNORE.test(line)) { | ||
return false; | ||
} | ||
|
||
if (nodeInternals.some(internal => internal.test(line))) { | ||
return false; | ||
} | ||
|
@@ -202,19 +212,26 @@ export const formatStackTrace = ( | |
: null; | ||
lines = removeInternalStackEntries(lines, options); | ||
|
||
if (testPath) { | ||
const topFrame = lines | ||
.join('\n') | ||
.trim() | ||
.split('\n')[0]; | ||
|
||
const parsedFrame = StackUtils.parseLine(topFrame); | ||
|
||
if (parsedFrame) { | ||
const topFrame = lines | ||
.map(line => line.trim()) | ||
.filter(Boolean) | ||
.filter( | ||
line => | ||
!line.includes(`${path.sep}node_modules${path.sep}`) && | ||
!line.includes(`${path.sep}expect${path.sep}build${path.sep}`), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this second one is only needed in jest's own tests, as we resolve the symlink properly. In normal cases only |
||
) | ||
.map(line => stackUtils.parseLine(line)) | ||
.filter(Boolean) | ||
.filter(parsedFrame => parsedFrame.file)[0]; | ||
|
||
if (topFrame) { | ||
const filename = topFrame.file; | ||
|
||
if (path.isAbsolute(filename)) { | ||
renderedCallsite = codeFrameColumns( | ||
fs.readFileSync(testPath, 'utf8'), | ||
fs.readFileSync(filename, 'utf8'), | ||
{ | ||
start: {line: parsedFrame.line}, | ||
start: {line: topFrame.line}, | ||
}, | ||
{highlightCode: true}, | ||
); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially we can walk down the stack until we find the test file. But I think this makes more sense