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

fix: rename config option name to id #11981

Merged
merged 10 commits into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -94,6 +94,7 @@
- `[expect]` [**BREAKING**] Snapshot matcher types are moved to `@jest/expect` ([#12404](https://github.com/facebook/jest/pull/12404))
- `[jest-cli]` Update `yargs` to v17 ([#12357](https://github.com/facebook/jest/pull/12357))
- `[jest-config]` [**BREAKING**] Remove `getTestEnvironment` export ([#12353](https://github.com/facebook/jest/pull/12353))
- `[jest-config]` [**BREAKING**] Rename config option `name` to `id` ([#11981](https://github.com/facebook/jest/pull/11981))
- `[jest-create-cache-key-function]` Added README.md file with basic usage instructions ([#12492](https://github.com/facebook/jest/pull/12492))
- `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
- `[jest-environment-jsdom]` [**BREAKING**] Migrate to ESM ([#12340](https://github.com/facebook/jest/pull/12340))
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -27,6 +27,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"forceNodeFilesystemAPI": true,
"throwOnModuleCollision": false
},
"id": "[md5 hash]",
"injectGlobals": true,
"moduleDirectories": [
"node_modules"
Expand All @@ -43,7 +44,6 @@ exports[`--showConfig outputs config info and exits 1`] = `
],
"moduleNameMapper": [],
"modulePathIgnorePatterns": [],
"name": "[md5 hash]",
"prettierPath": "prettier",
"resetMocks": false,
"resetModules": false,
Expand Down
28 changes: 14 additions & 14 deletions e2e/__tests__/multiProjectRunner.test.ts
Expand Up @@ -346,7 +346,7 @@ test('resolves projects and their <rootDir> properly', () => {
},
}),
'project1.conf.json': JSON.stringify({
name: 'project1',
id: 'project1',
rootDir: './project1',
// root dir should be this project's directory
setupFiles: ['<rootDir>/project1_setup.js'],
Expand All @@ -358,7 +358,7 @@ test('resolves projects and their <rootDir> properly', () => {
'project2/__tests__/test.test.js':
"test('project2', () => expect(globalThis.project2).toBe(true))",
'project2/project2.conf.json': JSON.stringify({
name: 'project2',
id: 'project2',
rootDir: '../', // root dir is set to the top level
setupFiles: ['<rootDir>/project2/project2_setup.js'], // rootDir shold be of the
testEnvironment: 'node',
Expand Down Expand Up @@ -514,13 +514,13 @@ describe("doesn't bleed module file extensions resolution with multiple workers"

expect(configs).toHaveLength(2);

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

expect(name1).toEqual(expect.any(String));
expect(name2).toEqual(expect.any(String));
expect(name1).toHaveLength(32);
expect(name2).toHaveLength(32);
expect(name1).not.toEqual(name2);
expect(id1).toEqual(expect.any(String));
expect(id2).toEqual(expect.any(String));
expect(id1).toHaveLength(32);
expect(id2).toHaveLength(32);
expect(id1).not.toEqual(id2);

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

expect(configs).toHaveLength(2);

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

expect(name1).toEqual(expect.any(String));
expect(name2).toEqual(expect.any(String));
expect(name1).toHaveLength(32);
expect(name2).toHaveLength(32);
expect(name1).not.toEqual(name2);
expect(id1).toEqual(expect.any(String));
expect(id2).toEqual(expect.any(String));
expect(id1).toHaveLength(32);
expect(id2).toHaveLength(32);
expect(id1).not.toEqual(id2);

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

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/showConfig.test.ts
Expand Up @@ -33,7 +33,7 @@ test('--showConfig outputs config info and exits', () => {
.replace(/\\\\\.pnp\\\\\.\[\^[/\\]+\]\+\$/g, '<<REPLACED_PNP_PATH>>')
.replace(/\\\\(?:([^.]+?)|$)/g, '/$1')
.replace(/"cacheDirectory": "(.+)"/g, '"cacheDirectory": "/tmp/jest"')
.replace(/"name": "(.+)"/g, '"name": "[md5 hash]"')
.replace(/"id": "(.+)"/g, '"id": "[md5 hash]"')
.replace(/"version": "(.+)"/g, '"version": "[version]"')
.replace(/"maxWorkers": (\d+)/g, '"maxWorkers": "[maxWorkers]"')
.replace(/"\S*show-config-test/gm, '"<<REPLACED_ROOT_DIR>>')
Expand Down
6 changes: 3 additions & 3 deletions e2e/custom-haste-map/hasteMap.js
Expand Up @@ -109,7 +109,7 @@ class HasteMap {
constructor(options) {
this._cachePath = HasteMap.getCacheFilePath(
options.cacheDirectory,
options.name,
options.id,
);
}

Expand All @@ -120,8 +120,8 @@ class HasteMap {
};
}

static getCacheFilePath(tmpdir, name) {
return path.join(tmpdir, name);
static getCacheFilePath(tmpdir, id) {
return path.join(tmpdir, id);
}

getCacheFilePath() {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -90,6 +90,7 @@ const initialOptions: Config.InitialOptions = {
retainAllFiles: false,
throwOnModuleCollision: false,
},
id: 'string',
injectGlobals: true,
json: false,
lastCommit: false,
Expand All @@ -113,7 +114,6 @@ const initialOptions: Config.InitialOptions = {
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
name: 'string',
noStackTrace: false,
notify: false,
notifyMode: 'failure-change',
Expand Down
18 changes: 9 additions & 9 deletions packages/jest-config/src/__tests__/normalize.test.ts
Expand Up @@ -66,7 +66,7 @@ afterEach(() => {
(console.warn as unknown as jest.SpyInstance).mockRestore();
});

it('picks a name based on the rootDir', async () => {
it('picks an id based on the rootDir', async () => {
const rootDir = '/root/path/foo';
const expected = createHash('md5')
.update('/root/path/foo')
Expand All @@ -78,32 +78,32 @@ it('picks a name based on the rootDir', async () => {
},
{} as Config.Argv,
);
expect(options.name).toBe(expected);
expect(options.id).toBe(expected);
});

it('keeps custom project name based on the projects rootDir', async () => {
const name = 'test';
it('keeps custom project id based on the projects rootDir', async () => {
const id = 'test';
const {options} = await normalize(
{
projects: [{name, rootDir: '/path/to/foo'}],
projects: [{id, rootDir: '/path/to/foo'}],
rootDir: '/root/path/baz',
},
{} as Config.Argv,
);

expect(options.projects[0].name).toBe(name);
expect(options.projects[0].id).toBe(id);
});

it('keeps custom names based on the rootDir', async () => {
it('keeps custom ids based on the rootDir', async () => {
const {options} = await normalize(
{
name: 'custom-name',
id: 'custom-id',
rootDir: '/root/path/foo',
},
{} as Config.Argv,
);

expect(options.name).toBe('custom-name');
expect(options.id).toBe('custom-id');
});

it('minimal config is stable across runs', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -192,13 +192,13 @@ const groupOptions = (
globalTeardown: options.globalTeardown,
globals: options.globals,
haste: options.haste,
id: options.id,
injectGlobals: options.injectGlobals,
moduleDirectories: options.moduleDirectories,
moduleFileExtensions: options.moduleFileExtensions,
moduleNameMapper: options.moduleNameMapper,
modulePathIgnorePatterns: options.modulePathIgnorePatterns,
modulePaths: options.modulePaths,
name: options.name,
prettierPath: options.prettierPath,
resetMocks: options.resetMocks,
resetModules: options.resetModules,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -370,8 +370,8 @@ const normalizeMissingOptions = (
configPath: string | null | undefined,
projectIndex: number,
): Config.InitialOptionsWithRootDir => {
if (!options.name) {
options.name = createHash('md5')
if (!options.id) {
options.id = createHash('md5')
.update(options.rootDir)
// In case we load config from some path that has the same root dir
.update(configPath || '')
Expand Down Expand Up @@ -989,7 +989,7 @@ export default async function normalize(
case 'listTests':
case 'logHeapUsage':
case 'maxConcurrency':
case 'name':
case 'id':
case 'noStackTrace':
case 'notify':
case 'notifyMode':
Expand Down