Skip to content

Commit

Permalink
Update docs + tests to use globalConfig.testPathPatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 committed Sep 22, 2023
1 parent 518c357 commit e347e72
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 24 deletions.
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#--testpathpatternregex)
- [`updateSnapshot`](cli#--updatesnapshot)
- [`verbose`](configuration#verbose-boolean)

Expand Down
12 changes: 4 additions & 8 deletions e2e/__tests__/globalSetup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ test('jest throws an error when globalSetup does not export a function', () => {
test('globalSetup function gets global config object and project config as parameters', () => {
const setupPath = path.resolve(e2eDir, 'setupWithConfig.js');

const testPathPattern = 'pass';

const result = runJest(e2eDir, [
`--globalSetup=${setupPath}`,
`--testPathPattern=${testPathPattern}`,
'--testPathPattern=pass',
'--cache=true',
]);

expect(result.stdout).toBe(`${testPathPattern}\ntrue`);
expect(result.stdout).toBe("[ 'pass' ]\ntrue");
});

test('should call globalSetup function of multiple projects', () => {
Expand Down Expand Up @@ -140,15 +138,13 @@ test('should not call any globalSetup if there are no tests to run', () => {
test('globalSetup works with default export', () => {
const setupPath = path.resolve(e2eDir, 'setupWithDefaultExport.js');

const testPathPattern = 'pass';

const result = runJest(e2eDir, [
`--globalSetup=${setupPath}`,
`--testPathPattern=${testPathPattern}`,
'--testPathPattern=pass',
'--cache=true',
]);

expect(result.stdout).toBe(`${testPathPattern}\ntrue`);
expect(result.stdout).toBe("[ 'pass' ]\ntrue");
});

test('globalSetup throws with named export', () => {
Expand Down
10 changes: 4 additions & 6 deletions e2e/__tests__/globalTeardown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ test('jest throws an error when globalTeardown does not export a function', () =
test('globalSetup function gets global config object and project config as parameters', () => {
const teardownPath = path.resolve(e2eDir, 'teardownWithConfig.js');

const testPathPattern = 'pass';

const result = runJest(e2eDir, [
`--globalTeardown=${teardownPath}`,
`--testPathPattern=${testPathPattern}`,
'--testPathPattern=pass',
'--cache=true',
]);

expect(result.stdout).toBe(`${testPathPattern}\ntrue`);
expect(result.stdout).toBe("[ 'pass' ]\ntrue");
});

test('should call globalTeardown function of multiple projects', () => {
Expand Down Expand Up @@ -112,11 +110,11 @@ test('globalTeardown works with default export', () => {

const result = runJest(e2eDir, [
`--globalTeardown=${teardownPath}`,
`--testPathPattern=${testPathPattern}`,
'--testPathPattern=pass',
'--cache=true',
]);

expect(result.stdout).toBe(`${testPathPattern}\ntrue`);
expect(result.stdout).toBe("[ 'pass' ]\ntrue");
});

test('globalTeardown throws with named export', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/global-setup/invalidSetupWithNamedExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

function invalidSetupWithNamedExport(jestConfig): void {
console.log(jestConfig.testPathPattern);
console.log(jestConfig.testPathPatterns);
}

export {invalidSetupWithNamedExport};
2 changes: 1 addition & 1 deletion e2e/global-setup/setupWithConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

module.exports = function (globalConfig, projectConfig) {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);
};
2 changes: 1 addition & 1 deletion e2e/global-setup/setupWithDefaultExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

export default function (globalConfig, projectConfig): void {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);
}
2 changes: 1 addition & 1 deletion e2e/global-teardown/invalidTeardownWithNamedExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

function invalidTeardownWithNamedExport(jestConfig): void {
console.log(jestConfig.testPathPattern);
console.log(jestConfig.testPathPatterns);
}

export {invalidTeardownWithNamedExport};
2 changes: 1 addition & 1 deletion e2e/global-teardown/teardownWithConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

module.exports = function (globalConfig, projectConfig) {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);
};
2 changes: 1 addition & 1 deletion e2e/global-teardown/teardownWithDefaultExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

export default function (globalConfig, projectConfig): void {
console.log(globalConfig.testPathPattern);
console.log(globalConfig.testPathPatterns);
console.log(projectConfig.cache);
}
2 changes: 1 addition & 1 deletion packages/jest-core/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('Watch mode flows', () => {
});

it('Correctly passing test path pattern', async () => {
globalConfig.testPathPattern = 'test-*';
globalConfig.testPathPatterns = ['test-*'];

await watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

Expand Down

0 comments on commit e347e72

Please sign in to comment.