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: config silently ignored in projects #13565

Merged
merged 6 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
115 changes: 113 additions & 2 deletions packages/jest-config/src/ValidConfig.ts
Expand Up @@ -13,7 +13,7 @@ import {NODE_MODULES} from './constants';

const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);

const initialOptions: Config.InitialOptions = {
export const initialOptions: Config.InitialOptions = {
automock: false,
bail: multipleValidOptions(false, 0),
cache: true,
Expand Down Expand Up @@ -188,4 +188,115 @@ const initialOptions: Config.InitialOptions = {
workerIdleMemoryLimit: multipleValidOptions(0.2, '50%'),
};

export default initialOptions;
export const initialProjectOptions: Config.InitialProjectOptions = {
automock: false,
cache: true,
cacheDirectory: '/tmp/user/jest',
clearMocks: false,
coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],
dependencyExtractor: '<rootDir>/dependencyExtractor.js',
detectLeaks: false,
detectOpenHandles: false,
displayName: multipleValidOptions('test-config', {
color: 'blue',
name: 'test-config',
} as const),
errorOnDeprecated: false,
extensionsToTreatAsEsm: [],
fakeTimers: {
advanceTimers: multipleValidOptions(40, true),
doNotFake: [
'Date',
'hrtime',
'nextTick',
'performance',
'queueMicrotask',
'requestAnimationFrame',
'cancelAnimationFrame',
'requestIdleCallback',
'cancelIdleCallback',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
enableGlobally: true,
legacyFakeTimers: false,
now: 1483228800000,
timerLimit: 1000,
},
filter: '<rootDir>/filter.js',
forceCoverageMatch: ['**/*.t.js'],
globalSetup: 'setup.js',
globalTeardown: 'teardown.js',
globals: {__DEV__: true},
haste: {
computeSha1: true,
defaultPlatform: 'ios',
enableSymlinks: false,
forceNodeFilesystemAPI: true,
hasteImplModulePath: '<rootDir>/haste_impl.js',
hasteMapModulePath: '',
platforms: ['ios', 'android'],
retainAllFiles: false,
throwOnModuleCollision: false,
},
id: 'string',
injectGlobals: true,
moduleDirectories: ['node_modules'],
moduleFileExtensions: [
'js',
'mjs',
'cjs',
'json',
'jsx',
'ts',
'tsx',
'node',
],
moduleNameMapper: {
'^React$': '<rootDir>/node_modules/react',
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
modulePaths: ['/shared/vendor/modules'],
prettierPath: '<rootDir>/node_modules/prettier',
resetMocks: false,
resetModules: false,
resolver: '<rootDir>/resolver.js',
restoreMocks: false,
rootDir: '/',
roots: ['<rootDir>'],
runner: 'jest-runner',
runtime: '<rootDir>',
sandboxInjectedGlobals: [],
setupFiles: ['<rootDir>/setup.js'],
setupFilesAfterEnv: ['<rootDir>/testSetupFile.js'],
skipFilter: false,
skipNodeResolution: false,
slowTestThreshold: 5,
snapshotFormat: PRETTY_FORMAT_DEFAULTS,
snapshotResolver: '<rootDir>/snapshotResolver.js',
snapshotSerializers: ['my-serializer-module'],
testEnvironment: 'jest-environment-node',
testEnvironmentOptions: {
url: 'http://localhost',
userAgent: 'Agent/007',
},
testLocationInResults: false,
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
testPathIgnorePatterns: [NODE_MODULES_REGEXP],
testRegex: multipleValidOptions(
'(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
['/__tests__/\\.test\\.[jt]sx?$', '/__tests__/\\.spec\\.[jt]sx?$'],
),
testRunner: 'circus',
transform: {
'\\.js$': '<rootDir>/preprocessor.js',
},
transformIgnorePatterns: [NODE_MODULES_REGEXP],
unmockedModulePathPatterns: ['mock'],
watchPathIgnorePatterns: ['<rootDir>/e2e/'],
workerIdleMemoryLimit: multipleValidOptions(0.2, '50%'),
};
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Expand Up @@ -58,6 +58,7 @@ export async function readConfig(
argv,
configPath,
projectIndex,
skipArgvConfigOption && !(packageRootOrConfig === parentConfigDirname),
);

const {globalConfig, projectConfig} = groupOptions(options);
Expand Down
8 changes: 6 additions & 2 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -31,7 +31,10 @@ import {ValidationError, validate} from 'jest-validate';
import DEFAULT_CONFIG from './Defaults';
import DEPRECATED_CONFIG from './Deprecated';
import {validateReporters} from './ReporterValidationErrors';
import VALID_CONFIG from './ValidConfig';
import {
initialOptions as VALID_CONFIG,
initialProjectOptions as VALID_PROJECT_CONFIG,
} from './ValidConfig';
import {getDisplayNameColor} from './color';
import {DEFAULT_JS_PATTERN} from './constants';
import getMaxWorkers from './getMaxWorkers';
Expand Down Expand Up @@ -487,14 +490,15 @@ export default async function normalize(
argv: Config.Argv,
configPath?: string | null,
projectIndex = Infinity,
isProjectOptions?: boolean,
): Promise<{
hasDeprecationWarnings: boolean;
options: AllOptions;
}> {
const {hasDeprecationWarnings} = validate(initialOptions, {
comment: DOCUMENTATION_NOTE,
deprecatedConfig: DEPRECATED_CONFIG,
exampleConfig: VALID_CONFIG,
exampleConfig: isProjectOptions ? VALID_PROJECT_CONFIG : VALID_CONFIG,
recursiveDenylist: [
// 'coverageThreshold' allows to use 'global' and glob strings on the same
// level, there's currently no way we can deal with such config
Expand Down