-
Notifications
You must be signed in to change notification settings - Fork 250
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(Jest): support overriding config #2197
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d306622
fix(react config): don't override testEnvironment config with jsdom
simondel b8b4e4d
Merge branch 'master' into 2155-jest-custom-params
simondel ddf559c
Merge branch 'master' into 2155-jest-custom-params
simondel 23072c1
feat(OptionEditor): Remove JestOptionsEditor
simondel cd63cea
Merge branch 'master' into 2155-jest-custom-params
simondel 16de4bc
test: fix test compilation
simondel 8f5a3fc
test: remove jsdom as default env
simondel d1cba05
test: Fix unit tests
simondel b41fcd4
test: rename integration test
simondel 1e772d4
test: Remove duplicate tests
simondel c89c2cd
Merge branch 'master' into 2155-jest-custom-params
simondel 7021fe6
Reset test environment dom
nicojs 911847a
Fix test
nicojs 3598984
fix test
nicojs 6e791aa
docs: explain new Jest config
simondel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simondel this made the test succeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it turns out
react-scripts
does use'jsdom'
as a default (facebook/create-react-app#5074) butreact-scripts-ts
was forked before that change was made and it hasn't really been updated for two years...