-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Jest): support overriding config (#2197)
* Adds support for overriding config in your package.json/jest.config.js and/or react-scripts node_modules. * Added config setting `jest.configFile` to specify a path to your config file. This file will be loaded using `require` * The `jest.config` setting now works together with `jest.configFile` to allow you to override the config in your `configFile` Fixes #2155
- Loading branch information
Showing
22 changed files
with
284 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { tokens, commonTokens, Injector, OptionsContext } from '@stryker-mutator/api/plugin'; | ||
import { StrykerOptions } from '@stryker-mutator/api/core'; | ||
import { Logger } from '@stryker-mutator/api/logging'; | ||
|
||
import { JestRunnerOptionsWithStrykerOptions } from '../JestRunnerOptionsWithStrykerOptions'; | ||
import { loaderToken, resolveToken, projectRootToken } from '../pluginTokens'; | ||
|
||
import CustomJestConfigLoader from './CustomJestConfigLoader'; | ||
import ReactScriptsJestConfigLoader from './ReactScriptsJestConfigLoader'; | ||
import ReactScriptsTSJestConfigLoader from './ReactScriptsTSJestConfigLoader'; | ||
|
||
configLoaderFactory.inject = tokens(commonTokens.options, commonTokens.injector, commonTokens.logger); | ||
export function configLoaderFactory(options: StrykerOptions, injector: Injector<OptionsContext>, log: Logger) { | ||
const warnAboutConfigFile = (projectType: string, configFile: string | undefined) => { | ||
if (configFile) { | ||
log.warn(`Config setting "configFile" is not supported for projectType "${projectType}"`); | ||
} | ||
}; | ||
const optionsWithJest: JestRunnerOptionsWithStrykerOptions = options as JestRunnerOptionsWithStrykerOptions; | ||
|
||
const configLoaderInjector = injector | ||
.provideValue(loaderToken, require) | ||
.provideValue(resolveToken, require.resolve) | ||
.provideValue(projectRootToken, process.cwd()); | ||
|
||
switch (optionsWithJest.jest.projectType) { | ||
case 'custom': | ||
return configLoaderInjector.injectClass(CustomJestConfigLoader); | ||
case 'create-react-app': | ||
warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); | ||
return configLoaderInjector.injectClass(ReactScriptsJestConfigLoader); | ||
case 'create-react-app-ts': | ||
warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); | ||
return configLoaderInjector.injectClass(ReactScriptsTSJestConfigLoader); | ||
case 'react': | ||
log.warn( | ||
'DEPRECATED: The projectType "react" is deprecated. Use projectType "create-react-app" for react projects created by "create-react-app" or use "custom" for other react projects.' | ||
); | ||
warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); | ||
return configLoaderInjector.injectClass(ReactScriptsJestConfigLoader); | ||
case 'react-ts': | ||
log.warn( | ||
'DEPRECATED: The projectType "react-ts" is deprecated. Use projectType "create-react-app-ts" for react projects created by "create-react-app" or use "custom" for other react projects.' | ||
); | ||
warnAboutConfigFile(optionsWithJest.jest.projectType, optionsWithJest.jest.configFile); | ||
return configLoaderInjector.injectClass(ReactScriptsTSJestConfigLoader); | ||
default: | ||
throw new Error(`No configLoader available for ${optionsWithJest.jest.projectType}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { declareClassPlugin, declareFactoryPlugin, PluginKind } from '@stryker-mutator/api/plugin'; | ||
import { declareFactoryPlugin, PluginKind } from '@stryker-mutator/api/plugin'; | ||
|
||
import strykerValidationSchema from '../schema/jest-runner-options.json'; | ||
|
||
import JestOptionsEditor from './JestOptionsEditor'; | ||
import { jestTestRunnerFactory } from './JestTestRunner'; | ||
|
||
process.env.BABEL_ENV = 'test'; | ||
|
||
export const strykerPlugins = [ | ||
declareClassPlugin(PluginKind.OptionsEditor, 'jest', JestOptionsEditor), | ||
declareFactoryPlugin(PluginKind.TestRunner, 'jest', jestTestRunnerFactory), | ||
]; | ||
export * as strykerValidationSchema from '../schema/jest-runner-options.json'; | ||
export const strykerPlugins = [declareFactoryPlugin(PluginKind.TestRunner, 'jest', jestTestRunnerFactory)]; | ||
|
||
export { strykerValidationSchema }; |
Oops, something went wrong.