diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index 932e7737d904..19ab5cb6c99a 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -66,6 +66,7 @@ const initialOptions: Config.InitialOptions = { platforms: ['ios', 'android'], throwOnModuleCollision: false, }, + id: 'string', injectGlobals: true, json: false, lastCommit: false, @@ -81,7 +82,6 @@ const initialOptions: Config.InitialOptions = { }, modulePathIgnorePatterns: ['/build/'], modulePaths: ['/shared/vendor/modules'], - name: 'string', noStackTrace: false, notify: false, notifyMode: 'failure-change', diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index b32f13298686..9706a3fd526e 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -84,28 +84,28 @@ it('picks a name based on the rootDir', async () => { }); it('keeps custom project name based on the projects rootDir', async () => { - const name = 'test'; + 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 () => { const {options} = await normalize( { - name: 'custom-name', + id: 'custom-name', rootDir: '/root/path/foo', }, {} as Config.Argv, ); - expect(options.name).toBe('custom-name'); + expect(options.id).toBe('custom-name'); }); it('minimal config is stable across runs', async () => { diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index e22cd5dfb754..c0942df9557b 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -193,6 +193,7 @@ const groupOptions = ( globalTeardown: options.globalTeardown, globals: options.globals, haste: options.haste, + id: options.id, injectGlobals: options.injectGlobals, moduleDirectories: options.moduleDirectories, moduleFileExtensions: options.moduleFileExtensions, @@ -200,7 +201,6 @@ const groupOptions = ( moduleNameMapper: options.moduleNameMapper, modulePathIgnorePatterns: options.modulePathIgnorePatterns, modulePaths: options.modulePaths, - name: options.name, prettierPath: options.prettierPath, resetMocks: options.resetMocks, resetModules: options.resetModules, diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index a50715620f29..ea4ab68a934d 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -369,8 +369,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 || '') @@ -928,7 +928,9 @@ export default async function normalize( typeof color !== 'string' ) { const errorMessage = - ` Option "${chalk.bold('displayName')}" must be of type:\n\n` + + ` Option "${chalk.bold( + 'displayNamename', + )}" must be of type:\n\n` + ' {\n' + ' name: string;\n' + ' color: string;\n' + @@ -978,7 +980,7 @@ export default async function normalize( case 'listTests': case 'logHeapUsage': case 'maxConcurrency': - case 'name': + case 'id': case 'noStackTrace': case 'notify': case 'notifyMode': diff --git a/packages/jest-core/src/__tests__/SearchSource.test.ts b/packages/jest-core/src/__tests__/SearchSource.test.ts index 76122f957363..0394a926230e 100644 --- a/packages/jest-core/src/__tests__/SearchSource.test.ts +++ b/packages/jest-core/src/__tests__/SearchSource.test.ts @@ -40,7 +40,7 @@ const toPaths = (tests: Array) => tests.map(({path}) => path); let findMatchingTests: (config: Config.ProjectConfig) => Promise; describe('SearchSource', () => { - const name = 'SearchSource'; + const id = 'SearchSource'; let searchSource: SearchSource; describe('isTestFilePath', () => { @@ -50,7 +50,7 @@ describe('SearchSource', () => { config = ( await normalize( { - name, + id, rootDir: '.', roots: [], }, @@ -71,7 +71,7 @@ describe('SearchSource', () => { config = ( await normalize( { - name, + id, rootDir: '.', roots: [], testMatch: undefined, @@ -121,8 +121,8 @@ describe('SearchSource', () => { it('finds tests matching a pattern via testRegex', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx', 'txt'], - name, rootDir, testMatch: undefined, testRegex: 'not-really-a-test', @@ -145,8 +145,8 @@ describe('SearchSource', () => { it('finds tests matching a pattern via testMatch', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx', 'txt'], - name, rootDir, testMatch: ['**/not-really-a-test.txt', '!**/do-not-match-me.txt'], testRegex: '', @@ -169,8 +169,8 @@ describe('SearchSource', () => { it('finds tests matching a JS regex pattern', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx'], - name, rootDir, testMatch: undefined, testRegex: 'test.jsx?', @@ -191,8 +191,8 @@ describe('SearchSource', () => { it('finds tests matching a JS glob pattern', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx'], - name, rootDir, testMatch: ['**/test.js?(x)'], testRegex: '', @@ -213,8 +213,8 @@ describe('SearchSource', () => { it('finds tests matching a JS with overriding glob patterns', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx'], - name, rootDir, testMatch: [ '**/*.js?(x)', @@ -241,7 +241,7 @@ describe('SearchSource', () => { it('finds tests with default file extensions using testRegex', async () => { const {options: config} = await normalize( { - name, + id, rootDir, testMatch: undefined, testRegex, @@ -262,7 +262,7 @@ describe('SearchSource', () => { it('finds tests with default file extensions using testMatch', async () => { const {options: config} = await normalize( { - name, + id, rootDir, testMatch, testRegex: '', @@ -283,7 +283,7 @@ describe('SearchSource', () => { it('finds tests with parentheses in their rootDir when using testMatch', async () => { const {options: config} = await normalize( { - name, + id, rootDir: path.resolve(__dirname, 'test_root_with_(parentheses)'), testMatch: ['**/__testtests__/**/*'], testRegex: undefined, @@ -303,8 +303,8 @@ describe('SearchSource', () => { it('finds tests with similar but custom file extensions', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx'], - name, rootDir, testMatch, }, @@ -324,8 +324,8 @@ describe('SearchSource', () => { it('finds tests with totally custom foobar file extensions', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'foobar'], - name, rootDir, testMatch, }, @@ -345,8 +345,8 @@ describe('SearchSource', () => { it('finds tests with many kinds of file extensions', async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx'], - name, rootDir, testMatch, }, @@ -366,7 +366,7 @@ describe('SearchSource', () => { it('finds tests using a regex only', async () => { const {options: config} = await normalize( { - name, + id, rootDir, testMatch: undefined, testRegex, @@ -387,7 +387,7 @@ describe('SearchSource', () => { it('finds tests using a glob only', async () => { const {options: config} = await normalize( { - name, + id, rootDir, testMatch, testRegex: '', @@ -411,7 +411,7 @@ describe('SearchSource', () => { const config = ( await normalize( { - name, + id, rootDir: '.', roots: [], }, @@ -509,7 +509,7 @@ describe('SearchSource', () => { 'haste_impl.js', ), }, - name: 'SearchSource-findRelatedTests-tests', + id: 'SearchSource-findRelatedTests-tests', rootDir, }, {} as Config.Argv, @@ -564,8 +564,8 @@ describe('SearchSource', () => { beforeEach(async () => { const {options: config} = await normalize( { + id, moduleFileExtensions: ['js', 'jsx', 'foobar'], - name, rootDir, testMatch, }, @@ -623,7 +623,7 @@ describe('SearchSource', () => { const config = ( await normalize( { - name, + id, rootDir: '.', roots: ['/foo/bar/prefix'], }, @@ -657,7 +657,7 @@ describe('SearchSource', () => { '../../../jest-haste-map/src/__tests__/haste_impl.js', ), }, - name: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests', + id: 'SearchSource-findRelatedSourcesFromTestsInChangedFiles-tests', rootDir, }, {} as Config.Argv, diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 5f6e17eeb615..dc52f82d9f50 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -160,8 +160,8 @@ export default class TestRunner { ) { const resolvers: Map = new Map(); for (const test of tests) { - if (!resolvers.has(test.context.config.name)) { - resolvers.set(test.context.config.name, { + if (!resolvers.has(test.context.config.id)) { + resolvers.set(test.context.config.id, { config: test.context.config, serializableModuleMap: test.context.moduleMap.toJSON(), }); diff --git a/packages/jest-runner/src/testWorker.ts b/packages/jest-runner/src/testWorker.ts index aca3f40c2680..988f1e210d4c 100644 --- a/packages/jest-runner/src/testWorker.ts +++ b/packages/jest-runner/src/testWorker.ts @@ -59,9 +59,9 @@ const formatError = (error: string | ErrorWithCode): SerializableError => { const resolvers = new Map(); const getResolver = (config: Config.ProjectConfig) => { - const resolver = resolvers.get(config.name); + const resolver = resolvers.get(config.id); if (!resolver) { - throw new Error('Cannot find resolver for: ' + config.name); + throw new Error('Cannot find resolver for: ' + config.id); } return resolver; }; @@ -77,7 +77,7 @@ export function setup(setupData: { const moduleMap = HasteMap.getStatic(config).getModuleMapFromJSON( serializableModuleMap, ); - resolvers.set(config.name, Runtime.createResolver(config, moduleMap)); + resolvers.set(config.id, Runtime.createResolver(config, moduleMap)); } } diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 69fd7a6c9db7..60c7fd8bccc5 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -380,7 +380,7 @@ export default class Runtime { ignorePattern, maxWorkers: options?.maxWorkers || 1, mocksPattern: escapePathForRegex(path.sep + '__mocks__' + path.sep), - name: config.name, + name: config.id, platforms: config.haste.platforms || ['ios', 'android'], resetCache: options?.resetCache, retainAllFiles: false, diff --git a/packages/jest-test-sequencer/src/index.ts b/packages/jest-test-sequencer/src/index.ts index 2637498f36d5..5e2a0b6f2dcb 100644 --- a/packages/jest-test-sequencer/src/index.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -38,7 +38,7 @@ export default class TestSequencer { const HasteMapClass = HasteMap.getStatic(config); return HasteMapClass.getCacheFilePath( config.cacheDirectory, - 'perf-cache-' + config.name, + 'perf-cache-' + config.id, ); } diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 7e17f65822e5..ad7b5344da4c 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -203,7 +203,7 @@ class ScriptTransformer { const HasteMapClass = HasteMap.getStatic(this._config); const baseCacheDir = HasteMapClass.getCacheFilePath( this._config.cacheDirectory, - 'jest-transform-cache-' + this._config.name, + 'jest-transform-cache-' + this._config.id, VERSION, ); // Create sub folders based on the cacheKey to avoid creating one diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index d94e4296b5f5..1d91b42d576a 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -173,6 +173,7 @@ export type InitialOptions = Partial<{ globalSetup: string | null | undefined; globalTeardown: string | null | undefined; haste: HasteConfig; + id: string; injectGlobals: boolean; reporters: Array; logHeapUsage: boolean; @@ -188,7 +189,6 @@ export type InitialOptions = Partial<{ }; modulePathIgnorePatterns: Array; modulePaths: Array; - name: string; noStackTrace: boolean; notify: boolean; notifyMode: string; @@ -369,6 +369,7 @@ export type ProjectConfig = { globalTeardown?: string; globals: ConfigGlobals; haste: HasteConfig; + id: string; injectGlobals: boolean; moduleDirectories: Array; moduleFileExtensions: Array; @@ -376,7 +377,6 @@ export type ProjectConfig = { moduleNameMapper: Array<[string, string]>; modulePathIgnorePatterns: Array; modulePaths?: Array; - name: string; prettierPath: string; resetMocks: boolean; resetModules: boolean; diff --git a/packages/test-utils/src/config.ts b/packages/test-utils/src/config.ts index 9a97135d8d77..aac0149c2293 100644 --- a/packages/test-utils/src/config.ts +++ b/packages/test-utils/src/config.ts @@ -84,6 +84,7 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = { globalTeardown: undefined, globals: {}, haste: {}, + id: 'test_name', injectGlobals: true, moduleDirectories: [], moduleFileExtensions: ['js'], @@ -91,7 +92,6 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = { moduleNameMapper: [], modulePathIgnorePatterns: [], modulePaths: [], - name: 'test_name', prettierPath: 'prettier', resetMocks: false, resetModules: false,