-
-
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
Add a "errorOnDeprecated" mode that errors when calling deprecated APIs #6339
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
141f92b
Add a "errorOnDeprecated" mode that errors when accessing unsupported…
captbaritone b852e5d
Ignore error-on-deprecated in circus... for now
captbaritone e5c86c4
Trim stacktrace
captbaritone 4416b62
Fix typos
captbaritone e0483f2
Remove deprecation error for DEFAULT_TIMEOUT_INTERVAL
captbaritone 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
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
248 changes: 248 additions & 0 deletions
248
e2e/__tests__/__snapshots__/error-on-deprecated.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,248 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DEFAULT_TIMEOUT_INTERVAL.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/DEFAULT_TIMEOUT_INTERVAL.test.js | ||
✕ DEFAULT_TIMEOUT_INTERVAL | ||
|
||
● DEFAULT_TIMEOUT_INTERVAL | ||
|
||
Illegal usage of \`jasmine.DEFAULT_TIMEOUT_INTERVAL\`, prefer \`jest.setTimeout\`. | ||
|
||
8 | | ||
9 | test('DEFAULT_TIMEOUT_INTERVAL', () => { | ||
> 10 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
| ^ | ||
11 | expect(true).toBe(true); | ||
12 | }); | ||
13 | | ||
|
||
at packages/jest-jasmine2/build/error_on_private.js:69:11 | ||
at __tests__/DEFAULT_TIMEOUT_INTERVAL.test.js:10:3 | ||
|
||
" | ||
`; | ||
|
||
exports[`fail.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/fail.test.js | ||
✕ fail | ||
|
||
● fail | ||
|
||
Illegal usage of global \`fail\`, prefer throwing an error, or the \`done.fail\` callback. | ||
|
||
11 | test('fail', () => { | ||
12 | if (true) { | ||
> 13 | fail('The truth hurts!'); | ||
| ^ | ||
14 | } | ||
15 | }); | ||
16 | | ||
|
||
at __tests__/fail.test.js:13:5 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.addMatchers.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.addMatchers.test.js | ||
● Test suite failed to run | ||
|
||
Illegal usage of \`jasmine.addMatchers\`, prefer \`expect.extends\`. | ||
|
||
7 | 'use strict'; | ||
8 | | ||
> 9 | jasmine.addMatchers({ | ||
| ^ | ||
10 | theSpanishInquisition: () => ({ | ||
11 | compare: (actual, expected) => ({ | ||
12 | message: 'Nobdy expects the Spanish Inquisition!', | ||
|
||
at __tests__/jasmine.addMatchers.test.js:9:9 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.any.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.any.test.js | ||
✕ jasmine.any | ||
|
||
● jasmine.any | ||
|
||
Illegal usage of \`jasmine.any\`, prefer \`expect.any\`. | ||
|
||
8 | | ||
9 | test('jasmine.any', () => { | ||
> 10 | expect({name: 'Jessie'}).toEqual({name: jasmine.any(String)}); | ||
| ^ | ||
11 | }); | ||
12 | | ||
|
||
at __tests__/jasmine.any.test.js:10:51 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.anything.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.anything.test.js | ||
✕ jasmine.anything | ||
|
||
● jasmine.anything | ||
|
||
Illegal usage of \`jasmine.anything\`, prefer \`expect.anything\`. | ||
|
||
8 | | ||
9 | test('jasmine.anything', () => { | ||
> 10 | expect({input: ['some', 'stuff']}).toEqual({input: jasmine.anything()}); | ||
| ^ | ||
11 | }); | ||
12 | | ||
|
||
at __tests__/jasmine.anything.test.js:10:62 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.arrayContaining.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.arrayContaining.test.js | ||
✕ jasmine.arrayContaining | ||
|
||
● jasmine.arrayContaining | ||
|
||
Illegal usage of \`jasmine.arrayContaining\`, prefer \`expect.arrayContaining\`. | ||
|
||
8 | | ||
9 | test('jasmine.arrayContaining', () => { | ||
> 10 | expect(['some', 'stuff']).toEqual(jasmine.arrayContaining(['stuff'])); | ||
| ^ | ||
11 | }); | ||
12 | | ||
|
||
at __tests__/jasmine.arrayContaining.test.js:10:45 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.createSpy.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.createSpy.test.js | ||
✕ jasmine.createSpy | ||
|
||
● jasmine.createSpy | ||
|
||
Illegal usage of \`jasmine.createSpy\`, prefer \`jest.fn\`. | ||
|
||
8 | | ||
9 | test('jasmine.createSpy', () => { | ||
> 10 | const mySpy = jasmine.createSpy(); | ||
| ^ | ||
11 | mySpy('hello?'); | ||
12 | expect(mySpy).toHaveBeenCalledWith('hello?'); | ||
13 | }); | ||
|
||
at __tests__/jasmine.createSpy.test.js:10:25 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.objectContaining.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.objectContaining.test.js | ||
✕ jasmine.objectContaining | ||
|
||
● jasmine.objectContaining | ||
|
||
Illegal usage of \`jasmine.objectContaining\`, prefer \`expect.objectContaining\`. | ||
|
||
9 | test('jasmine.objectContaining', () => { | ||
10 | expect({input: 'trash', output: 'trash'}).toEqual( | ||
> 11 | jasmine.objectContaining({output: 'trash'}) | ||
| ^ | ||
12 | ); | ||
13 | }); | ||
14 | | ||
|
||
at __tests__/jasmine.objectContaining.test.js:11:13 | ||
|
||
" | ||
`; | ||
|
||
exports[`jasmine.stringMatching.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/jasmine.stringMatching.test.js | ||
✕ jasmine.stringMatching | ||
|
||
● jasmine.stringMatching | ||
|
||
Illegal usage of \`jasmine.stringMatching\`, prefer \`expect.stringMatching\`. | ||
|
||
8 | | ||
9 | test('jasmine.stringMatching', () => { | ||
> 10 | expect('Greetings Earthling!').toEqual(jasmine.stringMatching(/^Greetings/)); | ||
| ^ | ||
11 | }); | ||
12 | | ||
|
||
at __tests__/jasmine.stringMatching.test.js:10:50 | ||
|
||
" | ||
`; | ||
|
||
exports[`pending.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/pending.test.js | ||
✕ pending | ||
|
||
● pending | ||
|
||
Illegal usage of global \`pending\`, prefer explicitly skipping a test using \`test.skip\` | ||
|
||
9 | test('pending', () => { | ||
10 | if (true) { | ||
> 11 | pending('This test is pending.'); | ||
| ^ | ||
12 | } | ||
13 | expect(false).toBe(true); | ||
14 | }); | ||
|
||
at __tests__/pending.test.js:11:5 | ||
|
||
" | ||
`; | ||
|
||
exports[`spyOn.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/spyOn.test.js | ||
✕ spyOn | ||
|
||
● spyOn | ||
|
||
Illegal usage of global \`spyOn\`, prefer \`jest.spyOn\`. | ||
|
||
15 | | ||
16 | test('spyOn', () => { | ||
> 17 | spyOn(subject, 'func').and.returnValue('bar'); | ||
| ^ | ||
18 | expect(subject.func()).toBe('bar'); | ||
19 | }); | ||
20 | | ||
|
||
at __tests__/spyOn.test.js:17:3 | ||
|
||
" | ||
`; | ||
|
||
exports[`spyOnProperty.test.js errors in erroOnDeprecated mode 1`] = ` | ||
"FAIL __tests__/spyOnProperty.test.js | ||
✕ spyOnProperty | ||
|
||
● spyOnProperty | ||
|
||
Illegal usage of global \`spyOnProperty\`, prefer \`jest.spyOn\`. | ||
|
||
22 | }; | ||
23 | | ||
> 24 | const spy = spyOnProperty(obj, 'method', 'get'); | ||
| ^ | ||
25 | | ||
26 | obj.method(); | ||
27 | | ||
|
||
at __tests__/spyOnProperty.test.js:24:15 | ||
|
||
" | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* 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'; | ||
|
||
const runJest = require('../runJest'); | ||
const {extractSummary} = require('../Utils'); | ||
|
||
const testFiles = [ | ||
'fail.test.js', | ||
'jasmine.addMatchers.test.js', | ||
'jasmine.any.test.js', | ||
'jasmine.anything.test.js', | ||
'jasmine.arrayContaining.test.js', | ||
'jasmine.createSpy.test.js', | ||
'jasmine.objectContaining.test.js', | ||
'jasmine.stringMatching.test.js', | ||
'pending.test.js', | ||
'spyOn.test.js', | ||
'spyOnProperty.test.js', | ||
'DEFAULT_TIMEOUT_INTERVAL.test.js', | ||
]; | ||
|
||
const SHOULD_NOT_PASS_IN_JEST = new Set([ | ||
'fail.test.js', | ||
'spyOnProperty.test.js', | ||
]); | ||
|
||
testFiles.forEach(testFile => { | ||
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.
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. |
||
test(`${testFile} errors in erroOnDeprecated mode`, () => { | ||
const result = runJest('error-on-deprecated', [ | ||
testFile, | ||
'--errorOnDeprecated', | ||
]); | ||
expect(result.status).toBe(1); | ||
const {rest} = extractSummary(result.stderr); | ||
expect(rest).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
testFiles.forEach(testFile => { | ||
const shouldPass = SHOULD_NOT_PASS_IN_JEST.has(testFile); | ||
|
||
const expectation = `${testFile} ${shouldPass ? 'errors' : 'passes'}`; | ||
const testName = `${expectation} when not in erroOnDeprecated mode`; | ||
|
||
test(testName, () => { | ||
const result = runJest('error-on-deprecated', [testFile]); | ||
expect(result.status).toBe(shouldPass ? 1 : 0); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
e2e/error-on-deprecated/__tests__/DEFAULT_TIMEOUT_INTERVAL.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,12 @@ | ||
/** | ||
* 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. | ||
*/ | ||
'use strict'; | ||
|
||
test('DEFAULT_TIMEOUT_INTERVAL', () => { | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
expect(true).toBe(true); | ||
}); |
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. | ||
*/ | ||
'use strict'; | ||
|
||
/* globals fail */ | ||
|
||
test('fail', () => { | ||
if (true) { | ||
fail('The truth hurts!'); | ||
} | ||
}); |
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.
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 thought I had trimmed this. I'll see if it's possible.