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

#10013 Rename ProjectConfig.name to ProjectConfig.id #12235

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -66,6 +66,7 @@ const initialOptions: Config.InitialOptions = {
platforms: ['ios', 'android'],
throwOnModuleCollision: false,
},
id: 'string',
injectGlobals: true,
json: false,
lastCommit: false,
Expand All @@ -81,7 +82,6 @@ const initialOptions: Config.InitialOptions = {
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
name: 'string',
noStackTrace: false,
notify: false,
notifyMode: 'failure-change',
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/__tests__/normalize.test.ts
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -193,14 +193,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
10 changes: 6 additions & 4 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -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 || '')
Expand Down Expand Up @@ -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' +
Expand Down Expand Up @@ -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':
Expand Down
42 changes: 21 additions & 21 deletions packages/jest-core/src/__tests__/SearchSource.test.ts
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 @@ -50,7 +50,7 @@ describe('SearchSource', () => {
config = (
await normalize(
{
name,
id,
rootDir: '.',
roots: [],
},
Expand All @@ -71,7 +71,7 @@ describe('SearchSource', () => {
config = (
await normalize(
{
name,
id,
rootDir: '.',
roots: [],
testMatch: undefined,
Expand Down Expand Up @@ -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',
Expand All @@ -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: '',
Expand All @@ -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?',
Expand All @@ -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: '',
Expand All @@ -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)',
Expand All @@ -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,
Expand All @@ -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: '',
Expand All @@ -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: ['<rootDir>**/__testtests__/**/*'],
testRegex: undefined,
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -387,7 +387,7 @@ describe('SearchSource', () => {
it('finds tests using a glob only', async () => {
const {options: config} = await normalize(
{
name,
id,
rootDir,
testMatch,
testRegex: '',
Expand All @@ -411,7 +411,7 @@ describe('SearchSource', () => {
const config = (
await normalize(
{
name,
id,
rootDir: '.',
roots: [],
},
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('SearchSource', () => {
'haste_impl.js',
),
},
name: 'SearchSource-findRelatedTests-tests',
id: 'SearchSource-findRelatedTests-tests',
rootDir,
},
{} as Config.Argv,
Expand Down Expand Up @@ -564,8 +564,8 @@ describe('SearchSource', () => {
beforeEach(async () => {
const {options: config} = await normalize(
{
id,
moduleFileExtensions: ['js', 'jsx', 'foobar'],
name,
rootDir,
testMatch,
},
Expand Down Expand Up @@ -623,7 +623,7 @@ describe('SearchSource', () => {
const config = (
await normalize(
{
name,
id,
rootDir: '.',
roots: ['/foo/bar/prefix'],
},
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-runner/src/index.ts
Expand Up @@ -160,8 +160,8 @@ export default class TestRunner {
) {
const resolvers: Map<string, SerializableResolver> = 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(),
});
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-runner/src/testWorker.ts
Expand Up @@ -59,9 +59,9 @@ const formatError = (error: string | ErrorWithCode): SerializableError => {

const resolvers = new Map<string, Resolver>();
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;
};
Expand All @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-test-sequencer/src/index.ts
Expand Up @@ -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,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-transform/src/ScriptTransformer.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-types/src/Config.ts
Expand Up @@ -173,6 +173,7 @@ export type InitialOptions = Partial<{
globalSetup: string | null | undefined;
globalTeardown: string | null | undefined;
haste: HasteConfig;
id: string;
injectGlobals: boolean;
reporters: Array<string | ReporterConfig>;
logHeapUsage: boolean;
Expand All @@ -188,7 +189,6 @@ export type InitialOptions = Partial<{
};
modulePathIgnorePatterns: Array<string>;
modulePaths: Array<string>;
name: string;
noStackTrace: boolean;
notify: boolean;
notifyMode: string;
Expand Down Expand Up @@ -369,14 +369,14 @@ export type ProjectConfig = {
globalTeardown?: string;
globals: ConfigGlobals;
haste: HasteConfig;
id: string;
injectGlobals: boolean;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleLoader?: Path;
moduleNameMapper: Array<[string, string]>;
modulePathIgnorePatterns: Array<string>;
modulePaths?: Array<string>;
name: string;
prettierPath: string;
resetMocks: boolean;
resetModules: boolean;
Expand Down