-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(expect, jest-snapshot, jest-circus, jest-types): Pass test.failin…
…g tests when containing failing snapshot matchers
- Loading branch information
1 parent
596422e
commit 90bb2e2
Showing
20 changed files
with
231 additions
and
5 deletions.
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
33 changes: 33 additions & 0 deletions
33
e2e/__tests__/__snapshots__/testFailingSnapshot.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,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test.failing doesnt update or remove snapshots 1`] = ` | ||
"// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
exports[\`snapshots not updated nor removed 1\`] = \`"1"\`; | ||
exports[\`snapshots not updated nor removed 2\`] = \`"1"\`; | ||
exports[\`snapshots not updated nor removed 3\`] = \`"1"\`; | ||
" | ||
`; | ||
|
||
exports[`test.failing doesnt update or remove snapshots 2`] = ` | ||
"/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
test.failing('inline snapshot not updated', () => { | ||
// eslint-disable-next-line quotes | ||
expect('0').toMatchInlineSnapshot(\`'1'\`); | ||
}); | ||
" | ||
`; | ||
exports[`test.failing should pass when at least one snapshot fails 1`] = `"1"`; | ||
exports[`test.failing should pass when at least one snapshot fails 2`] = `"1"`; | ||
exports[`test.failing should pass when snapshot matchers fails 1`] = `"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,61 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import * as fs from 'graceful-fs'; | ||
import runJest from '../runJest'; | ||
|
||
describe('test.failing', () => { | ||
describe('should pass when', () => { | ||
test.failing('snapshot matchers fails', () => { | ||
expect('0').toMatchSnapshot(); | ||
}); | ||
|
||
test.failing('snapshot doesnt exist', () => { | ||
expect('0').toMatchSnapshot(); | ||
}); | ||
|
||
test.failing('inline snapshot matchers fails', () => { | ||
expect('0').toMatchInlineSnapshot('0'); | ||
}); | ||
|
||
test.failing('at least one snapshot fails', () => { | ||
expect('1').toMatchSnapshot(); | ||
expect('0').toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('should fail when', () => { | ||
test.each([ | ||
['snapshot', 'snapshot'], | ||
['inline snapshot', 'inlineSnapshot'], | ||
])('%s matchers pass', (_, fileName) => { | ||
const dir = path.resolve(__dirname, '../test-failing-snapshot-all-pass'); | ||
const result = runJest(dir, [`./__tests__/${fileName}.test.js`]); | ||
expect(result.exitCode).toBe(1); | ||
}); | ||
}); | ||
|
||
it('doesnt update or remove snapshots', () => { | ||
const dir = path.resolve(__dirname, '../test-failing-snapshot'); | ||
const result = runJest(dir, ['-u']); | ||
expect(result.exitCode).toBe(0); | ||
expect(result.stdout).not.toMatch(/snapshots? (written|removed|obsolete)/); | ||
|
||
const snapshot = fs | ||
.readFileSync( | ||
path.resolve(dir, './__tests__/__snapshots__/snapshot.test.js.snap'), | ||
) | ||
.toString(); | ||
expect(snapshot).toMatchSnapshot(); | ||
|
||
const inlineSnapshot = fs | ||
.readFileSync(path.resolve(dir, './__tests__/inlineSnapshot.test.js')) | ||
.toString(); | ||
expect(inlineSnapshot).toMatchSnapshot(); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
e2e/test-failing-snapshot-all-pass/__tests__/__snapshots__/snapshot.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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`snapshots not updated 1`] = `"1"`; | ||
|
||
exports[`snapshots not updated 2`] = `"1"`; |
11 changes: 11 additions & 0 deletions
11
e2e/test-failing-snapshot-all-pass/__tests__/inlineSnapshot.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,11 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test.failing('inline snapshot not updated', () => { | ||
// eslint-disable-next-line quotes | ||
expect('1').toMatchInlineSnapshot(`"1"`); | ||
}); |
11 changes: 11 additions & 0 deletions
11
e2e/test-failing-snapshot-all-pass/__tests__/snapshot.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,11 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test.failing('snapshots not updated', () => { | ||
expect('1').toMatchSnapshot(); | ||
expect('1').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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
e2e/test-failing-snapshot/__tests__/__snapshots__/snapshot.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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`snapshots not updated nor removed 1`] = `"1"`; | ||
|
||
exports[`snapshots not updated nor removed 2`] = `"1"`; | ||
|
||
exports[`snapshots not updated nor removed 3`] = `"1"`; |
11 changes: 11 additions & 0 deletions
11
e2e/test-failing-snapshot/__tests__/inlineSnapshot.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,11 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test.failing('inline snapshot not updated', () => { | ||
// eslint-disable-next-line quotes | ||
expect('0').toMatchInlineSnapshot(`'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,12 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
test.failing('snapshots not updated nor removed', () => { | ||
expect('1').toMatchSnapshot(); | ||
expect('0').toMatchSnapshot(); | ||
expect('0').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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "node" | ||
} | ||
} |
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
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
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