-
-
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 --ignoreProjects
CLI argument to ignore test suites by project name
#12620
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
287aad4
Add `--ignoreProjects` CLI argument to ignore test suites by project …
F3n67u 9d2e091
add test
F3n67u 7f9090f
args check
F3n67u 6f7f542
fix type
F3n67u 185b732
add more test
F3n67u 6942a8e
adjust warning
F3n67u a38ddd4
Update docs/CLI.md
F3n67u bc92ed9
refactor notIgnore
F3n67u 29abd26
Merge branch 'ignoreProjects' of github.com:F3n67u/jest into ignorePr…
F3n67u 4871daa
unnamed project
F3n67u 43e0fa8
optimize message
F3n67u 01315cb
add changelog
F3n67u f71c418
type sort-keys
F3n67u 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,131 @@ describe('Given a config with two named projects, first-project and second-proje | |
); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--ignoreProjects first-project', () => { | ||
let result: RunJestJsonResult; | ||
beforeAll(() => { | ||
result = runWithJson('select-projects', [ | ||
'--ignoreProjects', | ||
'first-project', | ||
]); | ||
}); | ||
it('runs the tests in the second project only', () => { | ||
expect(result.json).toHaveProperty('success', true); | ||
expect(result.json).toHaveProperty('numTotalTests', 1); | ||
expect(result.json.testResults.map(({name}) => name)).toEqual([ | ||
resolve(dir, '__tests__/second-project.test.js'), | ||
]); | ||
}); | ||
it('prints that only second-project will run', () => { | ||
expect(result.stderr).toMatch(/^Running one project: second-project/); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--ignoreProjects second-project', () => { | ||
let result: RunJestJsonResult; | ||
beforeAll(() => { | ||
result = runWithJson('select-projects', [ | ||
'--ignoreProjects', | ||
'second-project', | ||
]); | ||
}); | ||
it('runs the tests in the first project only', () => { | ||
expect(result.json).toHaveProperty('success', true); | ||
expect(result.json).toHaveProperty('numTotalTests', 1); | ||
expect(result.json.testResults.map(({name}) => name)).toEqual([ | ||
resolve(dir, '__tests__/first-project.test.js'), | ||
]); | ||
}); | ||
it('prints that only first-project will run', () => { | ||
expect(result.stderr).toMatch(/^Running one project: first-project/); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--ignoreProjects third-project`', () => { | ||
let result: RunJestJsonResult; | ||
beforeAll(() => { | ||
result = runWithJson('select-projects', [ | ||
'--ignoreProjects', | ||
'third-project', | ||
]); | ||
}); | ||
it('runs the tests in the first and second projects', () => { | ||
expect(result.json).toHaveProperty('success', true); | ||
expect(result.json).toHaveProperty('numTotalTests', 2); | ||
expect(result.json.testResults.map(({name}) => name).sort()).toEqual([ | ||
resolve(dir, '__tests__/first-project.test.js'), | ||
resolve(dir, '__tests__/second-project.test.js'), | ||
]); | ||
}); | ||
it('prints that both first-project and second-project will run', () => { | ||
expect(result.stderr).toMatch( | ||
/^Running 2 projects:\n- first-project\n- second-project/, | ||
); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--ignoreProjects first-project second-project`', () => { | ||
let result: RunJestResult; | ||
beforeAll(() => { | ||
result = run('select-projects', [ | ||
'--ignoreProjects', | ||
'first-project', | ||
'second-project', | ||
]); | ||
}); | ||
it('fails', () => { | ||
expect(result).toHaveProperty('failed', true); | ||
}); | ||
it.skip('prints that no project was found', () => { | ||
expect(result.stdout).toMatch( | ||
/^You provided values for --ignoreProjects, but no projects were found matching the selection/, | ||
); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--selectProjects first-project second-project --ignoreProjects first-project` ', () => { | ||
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. @SimenB here is the test for using |
||
let result: RunJestJsonResult; | ||
beforeAll(() => { | ||
result = runWithJson('select-projects', [ | ||
'--selectProjects', | ||
'first-project', | ||
'second-project', | ||
'--ignoreProjects', | ||
'first-project', | ||
]); | ||
}); | ||
it('runs the tests in the second project only', () => { | ||
expect(result.json).toHaveProperty('success', true); | ||
expect(result.json).toHaveProperty('numTotalTests', 1); | ||
expect(result.json.testResults.map(({name}) => name)).toEqual([ | ||
resolve(dir, '__tests__/second-project.test.js'), | ||
]); | ||
}); | ||
it('prints that only second-project will run', () => { | ||
expect(result.stderr).toMatch(/^Running one project: second-project/); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--selectProjects first-project --ignoreProjects first-project` ', () => { | ||
let result: RunJestResult; | ||
beforeAll(() => { | ||
result = run('select-projects', [ | ||
'--selectProjects', | ||
'first-project', | ||
'--ignoreProjects', | ||
'first-project', | ||
]); | ||
}); | ||
it('fails', () => { | ||
expect(result).toHaveProperty('failed', true); | ||
}); | ||
it.skip('prints that no project was found', () => { | ||
expect(result.stdout).toMatch( | ||
/^You provided values for --selectProjects and --ignoreProjects, but no projects were found matching the selection./, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Given a config with two projects, first-project and an unnamed project', () => { | ||
|
@@ -185,4 +310,32 @@ describe('Given a config with two projects, first-project and an unnamed project | |
); | ||
}); | ||
}); | ||
|
||
describe('when Jest is started with `--ignoreProjects first-project`', () => { | ||
let result: RunJestJsonResult; | ||
beforeAll(() => { | ||
result = runWithJson('select-projects-missing-name', [ | ||
'--ignoreProjects', | ||
'first-project', | ||
]); | ||
}); | ||
it('runs the tests in the second project only', () => { | ||
expect(result.json.success).toBe(true); | ||
expect(result.json.numTotalTests).toBe(1); | ||
expect(result.json.testResults.map(({name}) => name)).toEqual([ | ||
resolve(dir, '__tests__/second-project.test.js'), | ||
]); | ||
}); | ||
it('prints that a project does not have a name', () => { | ||
expect(result.stderr).toMatch( | ||
/^You provided values for --ignoreProjects but a project does not have a name/, | ||
); | ||
}); | ||
it('prints that only second-project will run', () => { | ||
const stderrThirdLine = result.stderr.split('\n')[2]; | ||
expect(stderrThirdLine).toMatch( | ||
/^Running one project: <unnamed project>/, | ||
); | ||
}); | ||
}); | ||
}); |
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
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.
what happens if both this and
selectProjects
is used? Ideally it should be a configuration error. (and be mentioned in the docs)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.
selectProjects
andignoreProjects
could be used together. now it seems no need to do it because we don't support glob pattern, but I think to allow them to be used together will be better (not include a breaking change) because we maybe support glob in bothselectProjects
andignoreProjects
. just as Typescript allows you to useinclude
andexclude
together.and I don't think there is any reason to restrict our user to use them together, If they like to, we will allow them to use.
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.
see how our user's opinion here: #12618 (comment)
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.
@F3n67u Glob support for both would be awesome as well, especially if you're using https://github.com/jest-community/jest-runner-eslint so you could do ignore *-test when running tests and ignore *-lint when running lint.
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.
Mind opening up a separate feature request?
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.
Sure!