-
-
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 extra parameter: runTestsByPath. Fixes #4396 #4411
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import runJest from '../runJest'; | ||
import {cleanup, writeFiles} from '../utils'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
const skipOnWindows = require('../../scripts/skip_on_windows'); | ||
const DIR = path.resolve(os.tmpdir(), 'run_tests_by_path_test'); | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
test('runs tests by exact path', () => { | ||
writeFiles(DIR, { | ||
'.watchmanconfig': '', | ||
'__tests__/t1.test.js': 'it("foo", () => {})', | ||
'__tests__/t2.test.js': 'it("bar", () => {})', | ||
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}), | ||
}); | ||
|
||
// Passing an exact path executes only the given test. | ||
const run1 = runJest(DIR, ['--runTestsByPath', '__tests__/t1.test.js']); | ||
expect(run1.stderr).toMatch('PASS __tests__/t1.test.js'); | ||
expect(run1.stderr).not.toMatch('PASS __tests__/t2.test.js'); | ||
|
||
// When running with thte flag and a pattern, no test is found. | ||
const run2 = runJest(DIR, ['--runTestsByPath', '__tests__/t']); | ||
expect(run2.stdout).toMatch(/no tests found/i); | ||
|
||
// When ran without the flag and a pattern, both tests are found. | ||
const run3 = runJest(DIR, ['__tests__/t']); | ||
expect(run3.stderr).toMatch('PASS __tests__/t1.test.js'); | ||
expect(run3.stderr).toMatch('PASS __tests__/t2.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,17 @@ class SearchSource { | |
}; | ||
} | ||
|
||
findTestsByPaths(paths: Array<Path>): SearchResult { | ||
return { | ||
tests: toTests( | ||
this._context, | ||
paths | ||
.map(p => path.resolve(process.cwd(), p)) | ||
.filter(this.isTestFilePath.bind(this)), | ||
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. What happens if it can't find any tests, what does the message look like and does it make sense? |
||
), | ||
}; | ||
} | ||
|
||
findRelatedTestsFromPattern(paths: Array<Path>): SearchResult { | ||
if (Array.isArray(paths) && paths.length) { | ||
const resolvedPaths = paths.map(p => path.resolve(process.cwd(), p)); | ||
|
@@ -193,6 +204,8 @@ class SearchSource { | |
} | ||
|
||
return this.findTestRelatedToChangedFiles(changedFilesPromise); | ||
} else if (globalConfig.runTestsByPath && paths && paths.length) { | ||
return Promise.resolve(this.findTestsByPaths(paths)); | ||
} else if (globalConfig.findRelatedTests && paths && paths.length) { | ||
return Promise.resolve(this.findRelatedTestsFromPattern(paths)); | ||
} else if (globalConfig.testPathPattern != null) { | ||
|
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
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.
lol how did that happen
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.
probably me refactoring it last time and giving up on reading all if/else conditions :D
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.
That's because this
if
is useless.