Skip to content

Commit 051af02

Browse files
authored
fix: rename config option name to id (#11981)
1 parent a5f1ef4 commit 051af02

File tree

25 files changed

+93
-95
lines changed

25 files changed

+93
-95
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
- `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404))
9595
- `[jest-cli]` Update `yargs` to v17 ([#12357](https://github.com/facebook/jest/pull/12357))
9696
- `[jest-config]` [**BREAKING**] Remove `getTestEnvironment` export ([#12353](https://github.com/facebook/jest/pull/12353))
97+
- `[jest-config]` [**BREAKING**] Rename config option `name` to `id` ([#11981](https://github.com/facebook/jest/pull/11981))
9798
- `[jest-create-cache-key-function]` Added README.md file with basic usage instructions ([#12492](https://github.com/facebook/jest/pull/12492))
9899
- `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
99100
- `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))

e2e/__tests__/__snapshots__/showConfig.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
2727
"forceNodeFilesystemAPI": true,
2828
"throwOnModuleCollision": false
2929
},
30+
"id": "[md5 hash]",
3031
"injectGlobals": true,
3132
"moduleDirectories": [
3233
"node_modules"
@@ -43,7 +44,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
4344
],
4445
"moduleNameMapper": [],
4546
"modulePathIgnorePatterns": [],
46-
"name": "[md5 hash]",
4747
"prettierPath": "prettier",
4848
"resetMocks": false,
4949
"resetModules": false,

e2e/__tests__/multiProjectRunner.test.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ test('resolves projects and their <rootDir> properly', () => {
346346
},
347347
}),
348348
'project1.conf.json': JSON.stringify({
349-
name: 'project1',
349+
id: 'project1',
350350
rootDir: './project1',
351351
// root dir should be this project's directory
352352
setupFiles: ['<rootDir>/project1_setup.js'],
@@ -358,7 +358,7 @@ test('resolves projects and their <rootDir> properly', () => {
358358
'project2/__tests__/test.test.js':
359359
"test('project2', () => expect(globalThis.project2).toBe(true))",
360360
'project2/project2.conf.json': JSON.stringify({
361-
name: 'project2',
361+
id: 'project2',
362362
rootDir: '../', // root dir is set to the top level
363363
setupFiles: ['<rootDir>/project2/project2_setup.js'], // rootDir shold be of the
364364
testEnvironment: 'node',
@@ -514,13 +514,13 @@ describe("doesn't bleed module file extensions resolution with multiple workers"
514514

515515
expect(configs).toHaveLength(2);
516516

517-
const [{name: name1}, {name: name2}] = configs;
517+
const [{id: id1}, {id: id2}] = configs;
518518

519-
expect(name1).toEqual(expect.any(String));
520-
expect(name2).toEqual(expect.any(String));
521-
expect(name1).toHaveLength(32);
522-
expect(name2).toHaveLength(32);
523-
expect(name1).not.toEqual(name2);
519+
expect(id1).toEqual(expect.any(String));
520+
expect(id2).toEqual(expect.any(String));
521+
expect(id1).toHaveLength(32);
522+
expect(id2).toHaveLength(32);
523+
expect(id1).not.toEqual(id2);
524524

525525
const {stderr} = runJest(DIR, [
526526
'--no-watchman',
@@ -557,13 +557,13 @@ describe("doesn't bleed module file extensions resolution with multiple workers"
557557

558558
expect(configs).toHaveLength(2);
559559

560-
const [{name: name1}, {name: name2}] = configs;
560+
const [{id: id1}, {id: id2}] = configs;
561561

562-
expect(name1).toEqual(expect.any(String));
563-
expect(name2).toEqual(expect.any(String));
564-
expect(name1).toHaveLength(32);
565-
expect(name2).toHaveLength(32);
566-
expect(name1).not.toEqual(name2);
562+
expect(id1).toEqual(expect.any(String));
563+
expect(id2).toEqual(expect.any(String));
564+
expect(id1).toHaveLength(32);
565+
expect(id2).toHaveLength(32);
566+
expect(id1).not.toEqual(id2);
567567

568568
const {stderr} = runJest(DIR, ['--no-watchman', '-w=2']);
569569

e2e/__tests__/showConfig.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('--showConfig outputs config info and exits', () => {
3333
.replace(/\\\\\.pnp\\\\\.\[\^[/\\]+\]\+\$/g, '<<REPLACED_PNP_PATH>>')
3434
.replace(/\\\\(?:([^.]+?)|$)/g, '/$1')
3535
.replace(/"cacheDirectory": "(.+)"/g, '"cacheDirectory": "/tmp/jest"')
36-
.replace(/"name": "(.+)"/g, '"name": "[md5 hash]"')
36+
.replace(/"id": "(.+)"/g, '"id": "[md5 hash]"')
3737
.replace(/"version": "(.+)"/g, '"version": "[version]"')
3838
.replace(/"maxWorkers": (\d+)/g, '"maxWorkers": "[maxWorkers]"')
3939
.replace(/"\S*show-config-test/gm, '"<<REPLACED_ROOT_DIR>>')

e2e/custom-haste-map/hasteMap.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class HasteMap {
109109
constructor(options) {
110110
this._cachePath = HasteMap.getCacheFilePath(
111111
options.cacheDirectory,
112-
options.name,
112+
options.id,
113113
);
114114
}
115115

@@ -120,8 +120,8 @@ class HasteMap {
120120
};
121121
}
122122

123-
static getCacheFilePath(tmpdir, name) {
124-
return path.join(tmpdir, name);
123+
static getCacheFilePath(tmpdir, id) {
124+
return path.join(tmpdir, id);
125125
}
126126

127127
getCacheFilePath() {

packages/jest-config/src/ValidConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const initialOptions: Config.InitialOptions = {
9090
retainAllFiles: false,
9191
throwOnModuleCollision: false,
9292
},
93+
id: 'string',
9394
injectGlobals: true,
9495
json: false,
9596
lastCommit: false,
@@ -113,7 +114,6 @@ const initialOptions: Config.InitialOptions = {
113114
},
114115
modulePathIgnorePatterns: ['<rootDir>/build/'],
115116
modulePaths: ['/shared/vendor/modules'],
116-
name: 'string',
117117
noStackTrace: false,
118118
notify: false,
119119
notifyMode: 'failure-change',

packages/jest-config/src/__tests__/normalize.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ afterEach(() => {
6666
(console.warn as unknown as jest.SpyInstance).mockRestore();
6767
});
6868

69-
it('picks a name based on the rootDir', async () => {
69+
it('picks an id based on the rootDir', async () => {
7070
const rootDir = '/root/path/foo';
7171
const expected = createHash('md5')
7272
.update('/root/path/foo')
@@ -78,32 +78,32 @@ it('picks a name based on the rootDir', async () => {
7878
},
7979
{} as Config.Argv,
8080
);
81-
expect(options.name).toBe(expected);
81+
expect(options.id).toBe(expected);
8282
});
8383

84-
it('keeps custom project name based on the projects rootDir', async () => {
85-
const name = 'test';
84+
it('keeps custom project id based on the projects rootDir', async () => {
85+
const id = 'test';
8686
const {options} = await normalize(
8787
{
88-
projects: [{name, rootDir: '/path/to/foo'}],
88+
projects: [{id, rootDir: '/path/to/foo'}],
8989
rootDir: '/root/path/baz',
9090
},
9191
{} as Config.Argv,
9292
);
9393

94-
expect(options.projects[0].name).toBe(name);
94+
expect(options.projects[0].id).toBe(id);
9595
});
9696

97-
it('keeps custom names based on the rootDir', async () => {
97+
it('keeps custom ids based on the rootDir', async () => {
9898
const {options} = await normalize(
9999
{
100-
name: 'custom-name',
100+
id: 'custom-id',
101101
rootDir: '/root/path/foo',
102102
},
103103
{} as Config.Argv,
104104
);
105105

106-
expect(options.name).toBe('custom-name');
106+
expect(options.id).toBe('custom-id');
107107
});
108108

109109
it('minimal config is stable across runs', async () => {

packages/jest-config/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ const groupOptions = (
192192
globalTeardown: options.globalTeardown,
193193
globals: options.globals,
194194
haste: options.haste,
195+
id: options.id,
195196
injectGlobals: options.injectGlobals,
196197
moduleDirectories: options.moduleDirectories,
197198
moduleFileExtensions: options.moduleFileExtensions,
198199
moduleNameMapper: options.moduleNameMapper,
199200
modulePathIgnorePatterns: options.modulePathIgnorePatterns,
200201
modulePaths: options.modulePaths,
201-
name: options.name,
202202
prettierPath: options.prettierPath,
203203
resetMocks: options.resetMocks,
204204
resetModules: options.resetModules,

packages/jest-config/src/normalize.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ const normalizeMissingOptions = (
370370
configPath: string | null | undefined,
371371
projectIndex: number,
372372
): Config.InitialOptionsWithRootDir => {
373-
if (!options.name) {
374-
options.name = createHash('md5')
373+
if (!options.id) {
374+
options.id = createHash('md5')
375375
.update(options.rootDir)
376376
// In case we load config from some path that has the same root dir
377377
.update(configPath || '')
@@ -989,7 +989,7 @@ export default async function normalize(
989989
case 'listTests':
990990
case 'logHeapUsage':
991991
case 'maxConcurrency':
992-
case 'name':
992+
case 'id':
993993
case 'noStackTrace':
994994
case 'notify':
995995
case 'notifyMode':

0 commit comments

Comments
 (0)