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

feat: Change project config from name to id #11089

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
- `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988))
- `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862))
- `[jest-validate]` [**BREAKING**] Remove `recursiveBlacklist ` option in favor of previously introduced `recursiveDenylist` ([#10650](https://github.com/facebook/jest/pull/10650))
- `[jest-config]` [**BREAKING**] Change project config from `name` to `id` ([#11089](https://github.com/facebook/jest/pull/11089))

### Performance

Expand Down
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 @@ -23,6 +23,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"computeSha1": false,
"throwOnModuleCollision": false
},
"id": "[md5 hash]",
"injectGlobals": true,
"moduleDirectories": [
"node_modules"
Expand All @@ -37,7 +38,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
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,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 @@ -357,7 +357,7 @@ test('resolves projects and their <rootDir> properly', () => {
'project1/project1_setup.js': 'global.project1 = true;',
'project2/__tests__/test.test.js': `test('project2', () => expect(global.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 @@ -513,13 +513,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 @@ -556,13 +556,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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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
1 change: 1 addition & 0 deletions packages/jest-config/src/Descriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type {Config} from '@jest/types';

// TODO should we had the description of id that was previously name
const descriptions: {[key in keyof Config.InitialOptions]: string} = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a description of what the id does? @SimenB
And should it be added in the docs? https://jestjs.io/docs/en/cli
If so what would be the correct description?

automock: 'All imported modules in your tests should be mocked automatically',
bail: 'Stop running tests after `n` failures',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const initialOptions: Config.InitialOptions = {
platforms: ['ios', 'android'],
throwOnModuleCollision: false,
},
id: 'string',
injectGlobals: true,
json: false,
lastCommit: false,
Expand All @@ -73,7 +74,6 @@ const initialOptions: Config.InitialOptions = {
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
name: 'string',
noStackTrace: false,
notify: false,
notifyMode: 'failure-change',
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ afterEach(() => {
console.warn.mockRestore();
});

it('picks a name based on the rootDir', () => {
it('picks an id based on the rootDir', () => {
const rootDir = '/root/path/foo';
const expected = crypto
.createHash('md5')
Expand All @@ -79,33 +79,33 @@ it('picks a name based on the rootDir', () => {
rootDir,
},
{},
).options.name,
).options.id,
).toBe(expected);
});

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

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

it('keeps custom names based on the rootDir', () => {
it('keeps custom ids based on the rootDir', () => {
expect(
normalize(
{
name: 'custom-name',
id: 'custom-id',
rootDir: '/root/path/foo',
},
{},
).options.name,
).toBe('custom-name');
).options.id,
).toBe('custom-id');
});

it('minimal config is stable across runs', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ const groupOptions = (
globalTeardown: options.globalTeardown,
globals: options.globals,
haste: options.haste,
id: options.id,
injectGlobals: options.injectGlobals,
moduleDirectories: options.moduleDirectories,
moduleFileExtensions: options.moduleFileExtensions,
moduleLoader: options.moduleLoader,
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
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ const normalizeMissingOptions = (
configPath: Config.Path | 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 @@ -953,12 +953,12 @@ export default function normalize(
case 'findRelatedTests':
case 'forceCoverageMatch':
case 'forceExit':
case 'id':
case 'injectGlobals':
case 'lastCommit':
case 'listTests':
case 'logHeapUsage':
case 'maxConcurrency':
case 'name':
case 'noStackTrace':
case 'notify':
case 'notifyMode':
Expand Down
40 changes: 20 additions & 20 deletions packages/jest-core/src/__tests__/SearchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const toPaths = (tests: Array<Test>) => tests.map(({path}) => path);
let findMatchingTests: (config: Config.ProjectConfig) => Promise<SearchResult>;

describe('SearchSource', () => {
const name = 'SearchSource';
const id = 'SearchSource';
let searchSource: SearchSource;

describe('isTestFilePath', () => {
Expand All @@ -49,7 +49,7 @@ describe('SearchSource', () => {
beforeEach(() => {
config = normalize(
{
name,
id,
rootDir: '.',
roots: [],
},
Expand All @@ -68,7 +68,7 @@ describe('SearchSource', () => {
if (process.platform !== 'win32') {
config = normalize(
{
name,
id,
rootDir: '.',
roots: [],
testMatch: undefined,
Expand Down Expand Up @@ -117,8 +117,8 @@ describe('SearchSource', () => {
it('finds tests matching a pattern via testRegex', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx', 'txt'],
name,
rootDir,
testMatch: undefined,
testRegex: 'not-really-a-test',
Expand All @@ -141,8 +141,8 @@ describe('SearchSource', () => {
it('finds tests matching a pattern via testMatch', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx', 'txt'],
name,
rootDir,
testMatch: ['**/not-really-a-test.txt', '!**/do-not-match-me.txt'],
testRegex: '',
Expand All @@ -165,8 +165,8 @@ describe('SearchSource', () => {
it('finds tests matching a JS regex pattern', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testMatch: undefined,
testRegex: 'test.jsx?',
Expand All @@ -187,8 +187,8 @@ describe('SearchSource', () => {
it('finds tests matching a JS glob pattern', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testMatch: ['**/test.js?(x)'],
testRegex: '',
Expand All @@ -209,8 +209,8 @@ describe('SearchSource', () => {
it('finds tests matching a JS with overriding glob patterns', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testMatch: [
'**/*.js?(x)',
Expand All @@ -237,7 +237,7 @@ describe('SearchSource', () => {
it('finds tests with default file extensions using testRegex', () => {
const {options: config} = normalize(
{
name,
id,
rootDir,
testMatch: undefined,
testRegex,
Expand All @@ -258,7 +258,7 @@ describe('SearchSource', () => {
it('finds tests with default file extensions using testMatch', () => {
const {options: config} = normalize(
{
name,
id,
rootDir,
testMatch,
testRegex: '',
Expand All @@ -279,7 +279,7 @@ describe('SearchSource', () => {
it('finds tests with parentheses in their rootDir when using testMatch', () => {
const {options: config} = normalize(
{
name,
id,
rootDir: path.resolve(__dirname, 'test_root_with_(parentheses)'),
testMatch: ['<rootDir>**/__testtests__/**/*'],
testRegex: undefined,
Expand All @@ -299,8 +299,8 @@ describe('SearchSource', () => {
it('finds tests with similar but custom file extensions', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testMatch,
},
Expand All @@ -320,8 +320,8 @@ describe('SearchSource', () => {
it('finds tests with totally custom foobar file extensions', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'foobar'],
name,
rootDir,
testMatch,
},
Expand All @@ -341,8 +341,8 @@ describe('SearchSource', () => {
it('finds tests with many kinds of file extensions', () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx'],
name,
rootDir,
testMatch,
},
Expand All @@ -362,7 +362,7 @@ describe('SearchSource', () => {
it('finds tests using a regex only', () => {
const {options: config} = normalize(
{
name,
id,
rootDir,
testMatch: undefined,
testRegex,
Expand All @@ -383,7 +383,7 @@ describe('SearchSource', () => {
it('finds tests using a glob only', () => {
const {options: config} = normalize(
{
name,
id,
rootDir,
testMatch,
testRegex: '',
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('SearchSource', () => {
'haste_impl.js',
),
},
name: 'SearchSource-findRelatedTests-tests',
id: 'SearchSource-findRelatedTests-tests',
rootDir,
},
{} as Config.Argv,
Expand Down Expand Up @@ -479,8 +479,8 @@ describe('SearchSource', () => {
beforeEach(async () => {
const {options: config} = normalize(
{
id,
moduleFileExtensions: ['js', 'jsx', 'foobar'],
name,
rootDir,
testMatch,
},
Expand Down Expand Up @@ -537,7 +537,7 @@ describe('SearchSource', () => {
if (process.platform !== 'win32') {
const config = normalize(
{
name,
id,
rootDir: '.',
roots: ['/foo/bar/prefix'],
},
Expand Down Expand Up @@ -570,7 +570,7 @@ describe('SearchSource', () => {
'../../../jest-haste-map/src/__tests__/haste_impl.js',
),
},
name: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests',
id: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests',
rootDir,
},
{} as Config.Argv,
Expand Down
Loading