-
-
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
Fix bug: MPR executes tests multiple times #5335
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions
8
integration-tests/__tests__/__snapshots__/execute-tests-once-in-mpr.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,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Tests are executed only once even in an MPR 1`] = ` | ||
"PASS foo/folder/my-test-bar.js | ||
✓ 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
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,65 @@ | ||
/** | ||
* Copyright (c) 2017-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 path = require('path'); | ||
const skipOnWindows = require('../../scripts/skip_on_windows'); | ||
const {extractSummary, cleanup, writeFiles} = require('../utils'); | ||
const runJest = require('../runJest'); | ||
|
||
const DIR = path.resolve(__dirname, '../execute-tests-once-in-mpr'); | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterAll(() => cleanup(DIR)); | ||
|
||
test('Tests are executed only once even in an MPR', () => { | ||
// Make a global config that ignores all sub-projects. | ||
const config = { | ||
jest: { | ||
projects: ['<rootDir>/foo/*/'], | ||
testPathIgnorePatterns: ['/foo/'], | ||
}, | ||
}; | ||
|
||
// Make a child config with a special regexp to ensure we execute the tests. | ||
const childConfig = { | ||
jest: { | ||
testRegex: /my-test-.*\.js/.source, | ||
}, | ||
}; | ||
|
||
/* eslint-disable sort-keys */ | ||
writeFiles(DIR, { | ||
'foo/folder/my-test-bar.js': `test('bar', () => console.log('Bar!'));`, | ||
'foo/folder/package.json': JSON.stringify(childConfig, null, 2), | ||
|
||
'foo/directory/my-test-baz.js': `test('baz', () => console.log('Baz!'));`, | ||
'foo/directory/package.json': JSON.stringify(childConfig, null, 2), | ||
|
||
'foo/whatever/my-test-qux.js': `test('qux', () => console.log('Qux!'));`, | ||
'foo/whatever/package.json': JSON.stringify(childConfig, null, 2), | ||
|
||
'package.json': JSON.stringify(config, null, 2), | ||
}); | ||
/* eslint-enable sort-keys */ | ||
|
||
const {stderr, status} = runJest(DIR, ['foo/folder/my-test-bar.js']); | ||
|
||
expect(status).toBe(0); | ||
|
||
const {rest, summary} = extractSummary(stderr); | ||
|
||
// We have only one test passed, so total should equal to one, despite we have | ||
// three projects. | ||
expect(rest).toMatchSnapshot(); | ||
expect(summary).toMatch(/1 total/); | ||
}); |
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
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.
can you remove the "return false" here? It's literally the next line.
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.
huh, I didn't spot that :D