Skip to content

Commit 9869d99

Browse files
committed
#8708 Add global setup/teardown per-worker configuration options (that do nothing at the moment)
1 parent 2c1249e commit 9869d99

File tree

13 files changed

+82
-0
lines changed

13 files changed

+82
-0
lines changed

packages/create-jest/src/__tests__/__snapshots__/init.test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,15 @@ const config: Config = {
190190
// A path to a module which exports an async function that is triggered once before all test suites
191191
// globalSetup: undefined,
192192
193+
// A path to a module which exports an async function that is triggered once before all test suites in a worker
194+
// globalSetupPerWorker: undefined,
195+
193196
// A path to a module which exports an async function that is triggered once after all test suites
194197
// globalTeardown: undefined,
195198
199+
// A path to a module which exports an async function that is triggered once after all test suites in a worker
200+
// globalTeardownPerWorker: undefined,
201+
196202
// A set of global variables that need to be available in all test environments
197203
// globals: {},
198204
@@ -394,9 +400,15 @@ const config = {
394400
// A path to a module which exports an async function that is triggered once before all test suites
395401
// globalSetup: undefined,
396402
403+
// A path to a module which exports an async function that is triggered once before all test suites in a worker
404+
// globalSetupPerWorker: undefined,
405+
397406
// A path to a module which exports an async function that is triggered once after all test suites
398407
// globalTeardown: undefined,
399408
409+
// A path to a module which exports an async function that is triggered once after all test suites in a worker
410+
// globalTeardownPerWorker: undefined,
411+
400412
// A set of global variables that need to be available in all test environments
401413
// globals: {},
402414
@@ -598,9 +610,15 @@ const config = {
598610
// A path to a module which exports an async function that is triggered once before all test suites
599611
// globalSetup: undefined,
600612
613+
// A path to a module which exports an async function that is triggered once before all test suites in a worker
614+
// globalSetupPerWorker: undefined,
615+
601616
// A path to a module which exports an async function that is triggered once after all test suites
602617
// globalTeardown: undefined,
603618
619+
// A path to a module which exports an async function that is triggered once after all test suites in a worker
620+
// globalTeardownPerWorker: undefined,
621+
604622
// A set of global variables that need to be available in all test environments
605623
// globals: {},
606624

packages/jest-cli/src/args.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,21 @@ export const options: {[key: string]: Options} = {
286286
requiresArg: true,
287287
type: 'string',
288288
},
289+
globalSetupPerWorker: {
290+
description: 'The path to a module that runs before All Tests in a worker',
291+
requiresArg: true,
292+
type: 'string',
293+
},
289294
globalTeardown: {
290295
description: 'The path to a module that runs after All Tests.',
291296
requiresArg: true,
292297
type: 'string',
293298
},
299+
globalTeardownPerWorker: {
300+
description: 'The path to a module that runs after All Tests in a worker',
301+
requiresArg: true,
302+
type: 'string',
303+
},
294304
globals: {
295305
description:
296306
'A JSON string with map of global variables that need ' +

packages/jest-config/src/Descriptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ const descriptions: {[key in keyof Config.InitialOptions]: string} = {
3636
'Force coverage collection from ignored files using an array of glob patterns',
3737
globalSetup:
3838
'A path to a module which exports an async function that is triggered once before all test suites',
39+
globalSetupPerWorker:
40+
'A path to a module which exports an async function that is triggered once before all test suites in a worker',
3941
globalTeardown:
4042
'A path to a module which exports an async function that is triggered once after all test suites',
43+
globalTeardownPerWorker:
44+
'A path to a module which exports an async function that is triggered once after all test suites in a worker',
4145
globals:
4246
'A set of global variables that need to be available in all test environments',
4347
maxWorkers:

packages/jest-config/src/ValidConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export const initialOptions: Config.InitialOptions = {
7474
forceCoverageMatch: ['**/*.t.js'],
7575
forceExit: false,
7676
globalSetup: 'setup.js',
77+
globalSetupPerWorker: 'setup-per-worker.js',
7778
globalTeardown: 'teardown.js',
79+
globalTeardownPerWorker: 'teardown-per-worker.js',
7880
globals: {__DEV__: true},
7981
haste: {
8082
computeSha1: true,
@@ -245,7 +247,9 @@ export const initialProjectOptions: Config.InitialProjectOptions = {
245247
filter: '<rootDir>/filter.js',
246248
forceCoverageMatch: ['**/*.t.js'],
247249
globalSetup: 'setup.js',
250+
globalSetupPerWorker: 'setup-per-worker.js',
248251
globalTeardown: 'teardown.js',
252+
globalTeardownPerWorker: 'teardown-per-worker.js',
249253
globals: {__DEV__: true},
250254
haste: {
251255
computeSha1: true,

packages/jest-config/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ const groupOptions = (
9999
findRelatedTests: options.findRelatedTests,
100100
forceExit: options.forceExit,
101101
globalSetup: options.globalSetup,
102+
globalSetupPerWorker: options.globalSetupPerWorker,
102103
globalTeardown: options.globalTeardown,
104+
globalTeardownPerWorker: options.globalTeardownPerWorker,
103105
json: options.json,
104106
lastCommit: options.lastCommit,
105107
listTests: options.listTests,
@@ -166,7 +168,9 @@ const groupOptions = (
166168
filter: options.filter,
167169
forceCoverageMatch: options.forceCoverageMatch,
168170
globalSetup: options.globalSetup,
171+
globalSetupPerWorker: options.globalSetupPerWorker,
169172
globalTeardown: options.globalTeardown,
173+
globalTeardownPerWorker: options.globalTeardownPerWorker,
170174
globals: options.globals,
171175
haste: options.haste,
172176
id: options.id,

packages/jest-config/src/normalize.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,9 @@ export default async function normalize(
637637
break;
638638
case 'dependencyExtractor':
639639
case 'globalSetup':
640+
case 'globalSetupPerWorker':
640641
case 'globalTeardown':
642+
case 'globalTeardownPerWorker':
641643
case 'runtime':
642644
case 'snapshotResolver':
643645
case 'testResultsProcessor':

packages/jest-core/src/__tests__/watch.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,9 @@ describe('Watch mode flows', () => {
651651
${'✔︎'} | ${'findRelatedTests'}
652652
${'✖︎'} | ${'forceExit'}
653653
${'✖︎'} | ${'globalSetup'}
654+
${'✖︎'} | ${'globalSetupPerWorker'}
654655
${'✖︎'} | ${'globalTeardown'}
656+
${'✖︎'} | ${'globalTeardownPerWorker'}
655657
${'✖︎'} | ${'json'}
656658
${'✖︎'} | ${'lastCommit'}
657659
${'✖︎'} | ${'listTests'}

packages/jest-schemas/src/raw-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ export const InitialOptions = Type.Partial(
256256
json: Type.Boolean(),
257257
globals: Type.Record(Type.String(), Type.Unknown()),
258258
globalSetup: Type.Union([Type.String(), Type.Null()]),
259+
globalSetupPerWorker: Type.Union([Type.String(), Type.Null()]),
259260
globalTeardown: Type.Union([Type.String(), Type.Null()]),
261+
globalTeardownPerWorker: Type.Union([Type.String(), Type.Null()]),
260262
haste: HasteConfig,
261263
id: Type.String(),
262264
injectGlobals: Type.Boolean(),

packages/jest-transform/src/__tests__/__snapshots__/ScriptTransformer.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ exports[`ScriptTransformer in async mode, passes expected transform options to g
4545
"filter": undefined,
4646
"forceCoverageMatch": Array [],
4747
"globalSetup": undefined,
48+
"globalSetupPerWorker": undefined,
4849
"globalTeardown": undefined,
50+
"globalTeardownPerWorker": undefined,
4951
"globals": Object {},
5052
"haste": Object {},
5153
"id": "test",
@@ -196,7 +198,9 @@ exports[`ScriptTransformer passes expected transform options to getCacheKey 1`]
196198
"filter": undefined,
197199
"forceCoverageMatch": Array [],
198200
"globalSetup": undefined,
201+
"globalSetupPerWorker": undefined,
199202
"globalTeardown": undefined,
203+
"globalTeardownPerWorker": undefined,
200204
"globals": Object {},
201205
"haste": Object {},
202206
"id": "test",
@@ -321,7 +325,9 @@ exports[`ScriptTransformer passes expected transform options to getCacheKeyAsync
321325
"filter": undefined,
322326
"forceCoverageMatch": Array [],
323327
"globalSetup": undefined,
328+
"globalSetupPerWorker": undefined,
324329
"globalTeardown": undefined,
330+
"globalTeardownPerWorker": undefined,
325331
"globals": Object {},
326332
"haste": Object {},
327333
"id": "test",

packages/jest-transform/src/__tests__/shouldInstrument.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,24 @@ describe('shouldInstrument', () => {
216216
});
217217
});
218218

219+
it('if file is a globalSetupPerWorker file', () => {
220+
testShouldInstrument('globalSetupPerWorker.js', defaultOptions, {
221+
globalSetupPerWorker: 'globalSetupPerWorker.js',
222+
});
223+
});
224+
219225
it('if file is globalTeardown file', () => {
220226
testShouldInstrument('globalTeardown.js', defaultOptions, {
221227
globalTeardown: 'globalTeardown.js',
222228
});
223229
});
224230

231+
it('if file is globalTeardownPerWorker file', () => {
232+
testShouldInstrument('globalTeardownPerWorker.js', defaultOptions, {
233+
globalTeardownPerWorker: 'globalTeardownPerWorker.js',
234+
});
235+
});
236+
225237
it('if file is in setupFiles', () => {
226238
testShouldInstrument('setupTest.js', defaultOptions, {
227239
setupFiles: ['setupTest.js'],

0 commit comments

Comments
 (0)