-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
[Discussion] Expect only overrides error stack for built-in matchers #5162
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
cpojer
merged 23 commits into
jestjs:master
from
bvaughn:override-error-stack-only-for-internal-matchers
Jan 5, 2018
Merged
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f39d750
Expect only overrides error stack for built-in matchers
bvaughn e7d9bbd
Fixed naggy lint issue
bvaughn 9c10921
Replaced for...of with Object.keys().forEach()
bvaughn eb5d29c
Merged master
bvaughn ea088cf
Removed JestAssertionError export (as it is no longer needed)
bvaughn f2e7335
Added custom matcher test
bvaughn 3e00753
Adjusted custom_matcher test to use prettified, non-absolute stack
bvaughn 9e0cfae
test: refactor integration test
SimenB 31f8e58
update with correct snapshot
SimenB c388a49
test: skip on windows
SimenB 0c5c78c
Clarified comment
bvaughn 5843ab5
Further clarified comment
bvaughn f902b4b
test: fix test for node 6
SimenB bd21922
test: move custom matcher stack to separate file to be able to skip i…
SimenB 3ef09ea
Revert "test: fix test for node 6"
SimenB f88bf07
test: really fix node 6
SimenB ff50df6
Merge branch 'master' into override-error-stack-only-for-internal-mat…
SimenB 2da0eee
docs: add package prefix to changelog
SimenB 6f6dd91
Merge branch 'master' into override-error-stack-only-for-internal-mat…
bvaughn e8ab539
Reverted unrelated Markdown changes that had made their way into the …
bvaughn 7dad466
Replaced '__jestInternal' string attribute with a Symbol
bvaughn 179093c
Merge branch 'master' into override-error-stack-only-for-internal-mat…
bvaughn b8c6bfe
Updated snapshot
bvaughn 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
15 changes: 15 additions & 0 deletions
15
integration_tests/__tests__/__snapshots__/custom_matcher.test.js.snap
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,15 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Custom matcher preserves error stack 1`] = ` | ||
| "Error: qux | ||
| at baz (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:49:13) | ||
| at bar (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:47:23) | ||
| at foo (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:46:23) | ||
| at expect (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:54:9) | ||
| at Object.toCustomMatch (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:12:18) | ||
| at Object.throwingMatcher [as toCustomMatch] (/Users/bvaughn/Documents/git/jest/packages/expect/build/index.js:214:24) | ||
| at Object.it (/Users/bvaughn/Documents/git/jest/integration_tests/__tests__/custom_matcher.test.js:55:10) | ||
| at Object.asyncFn (/Users/bvaughn/Documents/git/jest/packages/jest-jasmine2/build/jasmine_async.js:129:432) | ||
| at resolve (/Users/bvaughn/Documents/git/jest/packages/jest-jasmine2/build/queue_runner.js:51:12) | ||
| at Promise (<anonymous>)" | ||
| `; | ||
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,60 @@ | ||
| /** | ||
| * 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'; | ||
|
|
||
| function toCustomMatch(callback, expectation) { | ||
| const actual = callback(); | ||
|
|
||
| if (actual !== expectation) { | ||
| return { | ||
| message: () => `Expected "${expectation}" but got "${actual}"`, | ||
| pass: false, | ||
| }; | ||
| } else { | ||
| return {pass: true}; | ||
| } | ||
| } | ||
|
|
||
| expect.extend({ | ||
| toCustomMatch, | ||
| }); | ||
|
|
||
| declare var expect: (func: Function) => any; | ||
|
|
||
| describe('Custom matcher', () => { | ||
| // This test is expected to pass | ||
| it('passes', () => { | ||
| expect(() => 'foo').toCustomMatch('foo'); | ||
| }); | ||
|
|
||
| // This test is expected to fail | ||
| it('fails', () => { | ||
| expect(() => { | ||
| expect(() => 'foo').toCustomMatch('bar'); | ||
| }).toThrow(); | ||
| }); | ||
|
|
||
| // This test fails due to an unrelated/unexpected error | ||
| // It will show a helpful stack trace though | ||
| it('preserves error stack', () => { | ||
| const foo = () => bar(); | ||
| const bar = () => baz(); | ||
| const baz = () => { | ||
| throw Error('qux'); | ||
| }; | ||
|
|
||
| try { | ||
| expect(() => { | ||
| foo(); | ||
| }).toCustomMatch('test'); | ||
| } catch (error) { | ||
| expect(error.stack).toMatchSnapshot(); | ||
| } | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,13 @@ export const setState = (state: Object) => { | |
|
|
||
| export const getMatchers = () => global[JEST_MATCHERS_OBJECT].matchers; | ||
|
|
||
| export const setMatchers = (matchers: MatchersObject) => { | ||
| export const setMatchers = (matchers: MatchersObject, isInternal: boolean) => { | ||
| Object.keys(matchers).forEach(key => { | ||
| const matcher = matchers[key]; | ||
| Object.defineProperty(matcher, '__jestInternal', { | ||
|
||
| value: isInternal, | ||
| }); | ||
| }); | ||
|
|
||
| Object.assign(global[JEST_MATCHERS_OBJECT].matchers, matchers); | ||
| }; | ||
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
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.
this shouldn't happen, right? we should still clean it up to be relative paths (especially for this integration test, but in general as well)
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.
Or do we really not want prettified stack trace at all?
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.
😆 Sorry. This was super silly of me. I'm embarrassed. I noticed that CI failed but hadn't had a chance yet to circle back and see why.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not sure if I fixed this in the best way 😄 but it now tests the prettified, relative stack.