Skip to content
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

Only match relative paths when specifying paths #12519

Merged
merged 23 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
344bc43
Factor out toString() call
brandonchinn178 Apr 26, 2023
317d079
Remove redundant 'globalConfig.testPathPattern == null' check
brandonchinn178 Apr 26, 2023
86993d4
Consolidate testPathPatterns logic
brandonchinn178 Apr 26, 2023
ecd979f
Return TestPathPatterns in normalize helper
brandonchinn178 Apr 26, 2023
4caaa45
Store parsed patterns in global config
brandonchinn178 Apr 26, 2023
225b6fe
Change normalize tests to test testPathPatterns
brandonchinn178 Apr 26, 2023
993fc50
Replace testPathPatternToRegExp with TestPathPatterns
brandonchinn178 Apr 26, 2023
518c357
Update testPathPatterns in updateGlobalConfig
brandonchinn178 Apr 26, 2023
e347e72
Update docs + tests to use globalConfig.testPathPatterns
brandonchinn178 Apr 26, 2023
6713c2c
Replace remaining usages of globalConfig.testPathPattern
brandonchinn178 Sep 21, 2023
a4efd87
Remove testPathPattern from GlobalConfig
brandonchinn178 Apr 26, 2023
ae8ee58
Add failing tests for matching outside relative path
brandonchinn178 Apr 26, 2023
1911750
Only match within relative path
brandonchinn178 Apr 26, 2023
5fd3eda
Fix tests using partial GlobalConfigs
brandonchinn178 Apr 26, 2023
0225d22
Update CHANGELOG
brandonchinn178 Apr 26, 2023
e228478
Fix --testPathPattern => --testPathPatterns
brandonchinn178 Apr 26, 2023
de9edca
Don't overload TestPathPatterns constructor
brandonchinn178 Sep 25, 2023
042fddd
Update docs
brandonchinn178 Sep 25, 2023
a52fc2f
Add deprecation error for --testPathPattern
brandonchinn178 Sep 25, 2023
70a3999
Convert isValid() to validate()
brandonchinn178 Sep 25, 2023
3c22ef3
Make toPretty() render prettier output
brandonchinn178 Sep 30, 2023
0b22568
Merge branch 'main' into chinn/relative-paths
SimenB Oct 2, 2023
09aed7d
oops
SimenB Oct 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
- `[pretty-format]` [**BREAKING**] Print `ArrayBuffer` and `DataView` correctly ([#14290](https://github.com/facebook/jest/pull/14290))
- `[jest-cli]` When specifying paths on the command line, only match against the relative paths of the test files ([#12519](https://github.com/facebook/jest/pull/12519))
- [**BREAKING**] Changes `testPathPattern` configuration option to `testPathPatterns`, which now takes a list of patterns instead of the regex.
- [**BREAKING**] `--testPathPattern` is now `--testPathPatterns`
SimenB marked this conversation as resolved.
Show resolved Hide resolved

### Performance

Expand Down
4 changes: 2 additions & 2 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,11 @@ The regex is matched against the full name, which is a combination of the test n

### `--testPathIgnorePatterns=<regex>|[array]`

A single or array of regexp pattern strings that are tested against all tests paths before executing the test. Contrary to `--testPathPattern`, it will only run those tests with a path that does not match with the provided regexp expressions.
A single or array of regexp pattern strings that are tested against all tests paths before executing the test. Contrary to `--testPathPatterns`, it will only run those tests with a path that does not match with the provided regexp expressions.

To pass as an array use escaped parentheses and space delimited regexps such as `\(/node_modules/ /tests/e2e/\)`. Alternatively, you can omit parentheses by combining regexps into a single regexp like `/node_modules/|/tests/e2e/`. These two examples are equivalent.

### `--testPathPattern=<regex>`
### `--testPathPatterns=<regex>`

A regexp pattern string that is matched against all tests paths before executing the test. On Windows, you will need to use `/` as a path separator or escape `\` as `\\`.

Expand Down
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ While code transformation is applied to the linked setup-file, Jest will **not**

```js title="setup.js"
module.exports = async function (globalConfig, projectConfig) {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);

// Set reference to mongod in order to close the server during teardown.
Expand All @@ -797,7 +797,7 @@ module.exports = async function (globalConfig, projectConfig) {

```js title="teardown.js"
module.exports = async function (globalConfig, projectConfig) {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);

await globalThis.__MONGOD__.stop();
Expand Down
2 changes: 1 addition & 1 deletion docs/WatchPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ For stability and safety reasons, only part of the global configuration keys can
- [`onlyFailures`](configuration#onlyfailures-boolean)
- [`reporters`](configuration#reporters-arraymodulename--modulename-options)
- [`testNamePattern`](cli#--testnamepatternregex)
- [`testPathPattern`](cli#--testpathpatternregex)
- [`testPathPatterns`](cli#--testpathpatternsregex)
- [`updateSnapshot`](cli#--updatesnapshot)
- [`verbose`](configuration#verbose-boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ exports[`CLI accepts exact file names if matchers matched 2`] = `
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /.\\/foo\\/bar.spec.js/i."
Ran all test suites matching ./foo/bar.spec.js."
`;
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/customReporters.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ exports[`Custom Reporters Integration default reporters enabled 2`] = `
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /add.test.js/i."
Ran all test suites matching add.test.js."
`;

exports[`Custom Reporters Integration default reporters enabled 3`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
Tests: 1 skipped, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /hookInDescribeWithSkippedTest.test.js/i.",
Ran all test suites matching hookInDescribeWithSkippedTest.test.js.",
}
`;

Expand All @@ -34,7 +34,7 @@ Object {
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /hookInEmptyDescribe.test.js/i.",
Ran all test suites matching hookInEmptyDescribe.test.js.",
}
`;

Expand All @@ -61,7 +61,7 @@ Object {
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /hookInEmptyNestedDescribe.test.js/i.",
Ran all test suites matching hookInEmptyNestedDescribe.test.js.",
}
`;

Expand Down Expand Up @@ -133,6 +133,6 @@ Object {
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /multipleHooksInEmptyDescribe.test.js/i.",
Ran all test suites matching multipleHooksInEmptyDescribe.test.js.",
}
`;
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/findRelatedFiles.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`--findRelatedTests flag coverage configuration is applied correctly 1`]
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites related to files matching /a.js|b.js/i."
Ran all test suites related to files matching a.js|b.js."
`;

exports[`--findRelatedTests flag coverage configuration is applied correctly 2`] = `
Expand Down Expand Up @@ -50,7 +50,7 @@ exports[`--findRelatedTests flag generates coverage report for filename 4`] = `
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites related to files matching /a.js/i."
Ran all test suites related to files matching a.js."
`;

exports[`--findRelatedTests flag generates coverage report for filename 5`] = `
Expand Down
16 changes: 8 additions & 8 deletions e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,61 @@ exports[`does not enforce import assertions 1`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-missing-import-assertions.test.js/i."
Ran all test suites matching native-esm-missing-import-assertions.test.js."
`;

exports[`on node >=16.11.0 support re-exports from CJS of dual packages 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-deep-cjs-reexport.test.js/i."
Ran all test suites matching native-esm-deep-cjs-reexport.test.js."
`;

exports[`on node >=16.12.0 supports import assertions 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-import-assertions.test.js/i."
Ran all test suites matching native-esm-import-assertions.test.js."
`;

exports[`properly handle re-exported native modules in ESM via CJS 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-native-module.test.js/i."
Ran all test suites matching native-esm-native-module.test.js."
`;

exports[`runs WebAssembly (Wasm) test with native ESM 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 6 passed, 6 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-wasm.test.js/i."
Ran all test suites matching native-esm-wasm.test.js."
`;

exports[`runs test with native ESM 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 33 passed, 33 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm.test.js/i."
Ran all test suites matching native-esm.test.js."
`;

exports[`support re-exports from CJS of core module 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-core-cjs-reexport.test.js/i."
Ran all test suites matching native-esm-core-cjs-reexport.test.js."
`;

exports[`supports top-level await 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm.tla.test.js/i."
Ran all test suites matching native-esm.tla.test.js."
`;
12 changes: 6 additions & 6 deletions e2e/__tests__/__snapshots__/promiseAsyncHandling.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Object {
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /unhandledRejectionAfterAll.test.js/i.",
Ran all test suites matching unhandledRejectionAfterAll.test.js.",
}
`;

Expand Down Expand Up @@ -63,7 +63,7 @@ Object {
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /unhandledRejectionAfterEach.test.js/i.",
Ran all test suites matching unhandledRejectionAfterEach.test.js.",
}
`;

Expand All @@ -89,7 +89,7 @@ Object {
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /unhandledRejectionBeforeAll.test.js/i.",
Ran all test suites matching unhandledRejectionBeforeAll.test.js.",
}
`;

Expand Down Expand Up @@ -130,7 +130,7 @@ Object {
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /unhandledRejectionBeforeEach.test.js/i.",
Ran all test suites matching unhandledRejectionBeforeEach.test.js.",
}
`;

Expand Down Expand Up @@ -217,7 +217,7 @@ Object {
Tests: 4 failed, 4 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /unhandledRejectionTest.test.js/i.",
Ran all test suites matching unhandledRejectionTest.test.js.",
}
`;

Expand All @@ -231,6 +231,6 @@ Object {
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /rejectionHandled.test.js/i.",
Ran all test suites matching rejectionHandled.test.js.",
}
`;
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"printBasicPrototype": false
},
"testFailureExitCode": 1,
"testPathPattern": "",
"testPathPatterns": [],
"testSequencer": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-test-sequencer/build/index.js",
"updateSnapshot": "none",
"useStderr": false,
Expand Down
14 changes: 7 additions & 7 deletions e2e/__tests__/__snapshots__/snapshot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -85,53 +85,53 @@ exports[`Snapshot works with escaped characters 1`] = `
Tests: 1 passed, 1 total
Snapshots: 1 written, 1 total
Time: <<REPLACED>>
Ran all test suites matching /snapshot.test.js/i."
Ran all test suites matching snapshot.test.js."
`;

exports[`Snapshot works with escaped characters 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 1 written, 1 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching /snapshot.test.js/i."
Ran all test suites matching snapshot.test.js."
`;

exports[`Snapshot works with escaped characters 3`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 2 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching /snapshot.test.js/i."
Ran all test suites matching snapshot.test.js."
`;

exports[`Snapshot works with escaped regex 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 2 written, 2 total
Time: <<REPLACED>>
Ran all test suites matching /snapshotEscapeRegex.js/i."
Ran all test suites matching snapshotEscapeRegex.js."
`;

exports[`Snapshot works with escaped regex 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 2 passed, 2 total
Time: <<REPLACED>>
Ran all test suites matching /snapshotEscapeRegex.js/i."
Ran all test suites matching snapshotEscapeRegex.js."
`;

exports[`Snapshot works with template literal substitutions 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 1 written, 1 total
Time: <<REPLACED>>
Ran all test suites matching /snapshotEscapeSubstitution.test.js/i."
Ran all test suites matching snapshotEscapeSubstitution.test.js."
`;

exports[`Snapshot works with template literal substitutions 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 1 passed, 1 total
Time: <<REPLACED>>
Ran all test suites matching /snapshotEscapeSubstitution.test.js/i."
Ran all test suites matching snapshotEscapeSubstitution.test.js."
`;
14 changes: 7 additions & 7 deletions e2e/__tests__/__snapshots__/stackTrace.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,53 @@ exports[`Stack Trace does not print a stack trace for errors when --noStackTrace
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /testError.test.js/i."
Ran all test suites matching testError.test.js."
`;

exports[`Stack Trace does not print a stack trace for matching errors when --noStackTrace is given 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /stackTrace.test.js/i."
Ran all test suites matching stackTrace.test.js."
`;

exports[`Stack Trace does not print a stack trace for runtime errors when --noStackTrace is given 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /runtimeError.test.js/i."
Ran all test suites matching runtimeError.test.js."
`;

exports[`Stack Trace prints a stack trace for errors 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /testError.test.js/i."
Ran all test suites matching testError.test.js."
`;

exports[`Stack Trace prints a stack trace for errors without message in stack trace 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /stackTraceWithoutMessage.test.js/i."
Ran all test suites matching stackTraceWithoutMessage.test.js."
`;

exports[`Stack Trace prints a stack trace for matching errors 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /stackTrace.test.js/i."
Ran all test suites matching stackTrace.test.js."
`;

exports[`Stack Trace prints a stack trace for runtime errors 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /runtimeError.test.js/i."
Ran all test suites matching runtimeError.test.js."
`;
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/testTodo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Test Suites: 1 passed, 1 total
Tests: 2 todo, 1 passed, 3 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /only-todo.test.js/i."
Ran all test suites matching only-todo.test.js."
`;

exports[`shows error messages when called with invalid argument 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/watchModePatterns.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exports[`can press "p" to filter by file name: test summary 2`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /bar/i."
Ran all test suites matching bar."
`;

exports[`can press "t" to filter by test name 1`] = `
Expand Down
Loading