From f9a645b1ee5d83b69ca38a80ace47fcef3198c0b Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Thu, 18 Oct 2018 14:43:53 -0700 Subject: [PATCH 1/8] Add shorthand for plugins and runners --- .../__snapshots__/normalize.test.js.snap | 20 +++ .../src/__tests__/normalize.test.js | 125 +++++++++++++++- packages/jest-config/src/normalize.js | 17 ++- packages/jest-config/src/utils.js | 136 +++++++++++++++--- 4 files changed, 266 insertions(+), 32 deletions(-) diff --git a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap index 19770435b020..0a733da3bf58 100644 --- a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap +++ b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap @@ -47,6 +47,16 @@ exports[`rootDir throws if the options is missing a rootDir property 1`] = ` " `; +exports[`runner throw error when a runner is not found 1`] = ` +"Validation Error: + + Jest Runner missing-runner cannot be found. Make sure the runner configuration option points to an existing node module. + + Configuration Documentation: + https://jestjs.io/docs/configuration.html +" +`; + exports[`testEnvironment throws on invalid environment names 1`] = ` "Validation Error: @@ -70,3 +80,13 @@ exports[`testMatch throws if testRegex and testMatch are both specified 1`] = ` exports[`testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern a( supplied. Running all tests instead."`; exports[`testPathPattern --testPathPattern ignores invalid regular expressions and logs a warning 1`] = `" Invalid testPattern a( supplied. Running all tests instead."`; + +exports[`watchPlugins throw error when a watch plugin is not found 1`] = ` +"Validation Error: + + Watch plugin missing-plugin cannot be found. Make sure the each element in watchPlugins configuration option points to an existing node module. + + Configuration Documentation: + https://jestjs.io/docs/configuration.html +" +`; diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 801ab1f0318b..366fec7c8151 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1125,15 +1125,90 @@ describe('preset without setupFiles', () => { }); }); +describe('runner', () => { + let Resolver; + beforeEach(() => { + Resolver = require('jest-resolve'); + Resolver.findNodeModule = jest.fn(name => { + if (name === 'eslint') { + return 'node_modules/eslint'; + } + if (name === 'jest-runner-eslint') { + return 'node_modules/jest-runner-eslint'; + } + + if (name === 'my-runner-foo') { + return 'node_modules/my-runner-foo'; + } + if (name.startsWith('/root')) { + return name; + } + return findNodeModule(name); + }); + }); + + it('defaults to `jest-runner`', () => { + const {options} = normalize({rootDir: '/root'}, {}); + + expect(options.runner).toBe('jest-runner'); + }); + + it('resolves to runners that do not have the prefix', () => { + const {options} = normalize( + { + rootDir: '/root/', + runner: 'my-runner-foo', + }, + {}, + ); + + expect(options.runner).toBe('node_modules/my-runner-foo'); + }); + + it('resolves to runners and prefers jest-runner-`name`', () => { + const {options} = normalize( + { + rootDir: '/root/', + runner: 'eslint', + }, + {}, + ); + + expect(options.runner).toBe('node_modules/jest-runner-eslint'); + }); + + it('throw error when a runner is not found', () => { + expect(() => + normalize( + { + rootDir: '/root/', + runner: 'missing-runner', + }, + {}, + ), + ).toThrowErrorMatchingSnapshot(); + }); +}); + describe('watchPlugins', () => { let Resolver; beforeEach(() => { Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => { - if (name.startsWith(path.sep)) { + if (name === 'typeahead') { + return 'node_modules/typeahead'; + } + if (name === 'jest-watch-typeahead') { + return 'node_modules/jest-watch-typeahead'; + } + + if (name === 'my-watch-plugin') { + return 'node_modules/my-watch-plugin'; + } + if (name.startsWith('/root')) { return name; } - return path.sep + 'node_modules' + path.sep + name; + return findNodeModule(name); }); }); @@ -1143,20 +1218,60 @@ describe('watchPlugins', () => { expect(options.watchPlugins).toEqual(undefined); }); - it('normalizes watchPlugins', () => { + it('resolves to watch plugins and prefers jest-watch-`name`', () => { + const {options} = normalize( + { + rootDir: '/root/', + watchPlugins: ['typeahead'], + }, + {}, + ); + + expect(options.watchPlugins).toEqual([ + {config: {}, path: 'node_modules/jest-watch-typeahead'}, + ]); + }); + + it('resolves watch plugins that do not have the prefix', () => { const {options} = normalize( { rootDir: '/root/', - watchPlugins: ['my-watch-plugin', '/path/to/plugin'], + watchPlugins: ['my-watch-plugin'], }, {}, ); expect(options.watchPlugins).toEqual([ - {config: {}, path: '/node_modules/my-watch-plugin'}, + {config: {}, path: 'node_modules/my-watch-plugin'}, + ]); + }); + + it('normalizes multiple watchPlugins', () => { + const {options} = normalize( + { + rootDir: '/root/', + watchPlugins: ['jest-watch-typeahead', '/path/to/plugin'], + }, + {}, + ); + + expect(options.watchPlugins).toEqual([ + {config: {}, path: 'node_modules/jest-watch-typeahead'}, {config: {}, path: '/root/path/to/plugin'}, ]); }); + + it('throw error when a watch plugin is not found', () => { + expect(() => + normalize( + { + rootDir: '/root/', + watchPlugins: ['missing-plugin'], + }, + {}, + ), + ).toThrowErrorMatchingSnapshot(); + }); }); describe('testPathPattern', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index a7da8a1a41d7..db8730afd08e 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -28,6 +28,8 @@ import { _replaceRootDirTags, escapeGlobCharacters, getTestEnvironment, + getRunner, + getWatchPlugin, resolve, } from './utils'; import {DEFAULT_JS_PATTERN, DEFAULT_REPORTER_LABEL} from './constants'; @@ -452,7 +454,6 @@ export default function normalize(options: InitialOptions, argv: Argv) { case 'globalSetup': case 'globalTeardown': case 'moduleLoader': - case 'runner': case 'setupTestFrameworkScriptFile': case 'snapshotResolver': case 'testResultsProcessor': @@ -466,6 +467,14 @@ export default function normalize(options: InitialOptions, argv: Argv) { rootDir: options.rootDir, }); break; + case 'runner': + value = + options[key] && + getRunner(newOptions.resolver, { + filePath: options[key], + rootDir: options.rootDir, + }); + break; case 'prettierPath': // We only want this to throw if "prettierPath" is explicitly passed // from config or CLI, and the requested path isn't found. Otherwise we @@ -634,18 +643,16 @@ export default function normalize(options: InitialOptions, argv: Argv) { if (typeof watchPlugin === 'string') { return { config: {}, - path: resolve(newOptions.resolver, { + path: getWatchPlugin(newOptions.resolver, { filePath: watchPlugin, - key, rootDir: options.rootDir, }), }; } else { return { config: watchPlugin[1] || {}, - path: resolve(newOptions.resolver, { + path: getWatchPlugin(newOptions.resolver, { filePath: watchPlugin[0], - key, rootDir: options.rootDir, }), }; diff --git a/packages/jest-config/src/utils.js b/packages/jest-config/src/utils.js index fb4aae572ae1..97a1665fbdc8 100644 --- a/packages/jest-config/src/utils.js +++ b/packages/jest-config/src/utils.js @@ -102,43 +102,135 @@ export const _replaceRootDirTags = (rootDir: string, config: any) => { return config; }; -/** - * Finds the test environment to use: - * - * 1. looks for jest-environment- relative to project. - * 1. looks for jest-environment- relative to Jest. - * 1. looks for relative to project. - * 1. looks for relative to Jest. - */ -export const getTestEnvironment = (config: Object) => { - const env = replaceRootDirInPath(config.rootDir, config.testEnvironment); - let module = Resolver.findNodeModule(`jest-environment-${env}`, { - basedir: config.rootDir, +export const resolveWithPrefix = ( + resolver: ?string, + { + rootDir, + filePath, + prefix, + }: { + rootDir: string, + filePath: string, + prefix: string, + }, +) => { + const fileName = replaceRootDirInPath(rootDir, filePath); + let module = Resolver.findNodeModule(`${prefix}${fileName}`, { + basedir: rootDir, + resolver, }); if (module) { return module; } try { - return require.resolve(`jest-environment-${env}`); + return require.resolve(`${prefix}${fileName}`); } catch (e) {} - module = Resolver.findNodeModule(env, {basedir: config.rootDir}); + module = Resolver.findNodeModule(fileName, { + basedir: rootDir, + resolver, + }); if (module) { return module; } try { - return require.resolve(env); + return require.resolve(fileName); } catch (e) {} +}; - throw createValidationError( - ` Test environment ${chalk.bold( - env, - )} cannot be found. Make sure the ${chalk.bold( - 'testEnvironment', - )} configuration option points to an existing node module.`, - ); +/** + * Finds the test environment to use: + * + * 1. looks for jest-environment- relative to project. + * 1. looks for jest-environment- relative to Jest. + * 1. looks for relative to project. + * 1. looks for relative to Jest. + */ +export const getTestEnvironment = ({ + rootDir, + testEnvironment: filePath, +}: Object) => { + const module = resolveWithPrefix(null, { + filePath, + prefix: 'jest-environment-', + rootDir, + }); + + if (!module) { + throw createValidationError( + ` Test environment ${chalk.bold( + replaceRootDirInPath(rootDir, filePath), + )} cannot be found. Make sure the ${chalk.bold( + 'testEnvironment', + )} configuration option points to an existing node module.`, + ); + } + + return module; +}; + +/** + * Finds the watch plugins to use: + * + * 1. looks for jest-watch- relative to project. + * 1. looks for jest-watch- relative to Jest. + * 1. looks for relative to project. + * 1. looks for relative to Jest. + */ +export const getWatchPlugin = ( + resolver: ?string, + {filePath, rootDir}: {filePath: string, rootDir: string}, +) => { + const module = resolveWithPrefix(resolver, { + filePath, + prefix: 'jest-watch-', + rootDir, + }); + + if (!module) { + throw createValidationError( + ` Watch plugin ${chalk.bold( + replaceRootDirInPath(rootDir, filePath), + )} cannot be found. Make sure the each element in ${chalk.bold( + 'watchPlugins', + )} configuration option points to an existing node module.`, + ); + } + + return module; +}; + +/** + * Finds the runner to use: + * + * 1. looks for jest-runner- relative to project. + * 1. looks for jest-runner- relative to Jest. + * 1. looks for relative to project. + * 1. looks for relative to Jest. + */ +export const getRunner = ( + resolver: ?string, + {filePath, rootDir}: {filePath: string, rootDir: string}, +) => { + const module = resolveWithPrefix(resolver, { + filePath, + prefix: 'jest-runner-', + rootDir, + }); + + if (!module) { + throw createValidationError( + ` Jest Runner ${chalk.bold( + replaceRootDirInPath(rootDir, filePath), + )} cannot be found. Make sure the ${chalk.bold( + 'runner', + )} configuration option points to an existing node module.`, + ); + } + + return module; }; export const isJSONString = (text: ?string) => From 6061d5ccef5a13608144aec625c8f0f856fe716c Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Thu, 18 Oct 2018 16:23:31 -0700 Subject: [PATCH 2/8] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a03e365c23c..91d68f198eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-config]` Add shorthand for watch plugins and runners ([#7213](https://github.com/facebook/jest/pull/7213)) - `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996)) - `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661)) - `[jest-haste-map]` Add `getFileIterator` to `HasteFS` for faster file iteration ([#7010](https://github.com/facebook/jest/pull/7010)). From c640423a0a9e5c464845a76e7f5343c17d373c69 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Fri, 19 Oct 2018 09:33:27 -0700 Subject: [PATCH 3/8] Use `.includes` while resolving modules in normalization tests --- .../src/__tests__/normalize.test.js | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 366fec7c8151..0f4a6f270cea 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -627,11 +627,8 @@ describe('testEnvironment', () => { beforeEach(() => { Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => { - if (name === 'jsdom') { - return 'node_modules/jsdom'; - } - if (name === 'jest-environment-jsdom') { - return 'node_modules/jest-environment-jsdom'; + if (['jsdom', 'jest-environment-jsdom'].includes(name)) { + return `node_modules/${name}`; } if (name.startsWith('/root')) { return name; @@ -1130,15 +1127,8 @@ describe('runner', () => { beforeEach(() => { Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => { - if (name === 'eslint') { - return 'node_modules/eslint'; - } - if (name === 'jest-runner-eslint') { - return 'node_modules/jest-runner-eslint'; - } - - if (name === 'my-runner-foo') { - return 'node_modules/my-runner-foo'; + if (['eslint', 'jest-runner-eslint', 'my-runner-foo'].includes(name)) { + return `node_modules/${name}`; } if (name.startsWith('/root')) { return name; @@ -1195,16 +1185,12 @@ describe('watchPlugins', () => { beforeEach(() => { Resolver = require('jest-resolve'); Resolver.findNodeModule = jest.fn(name => { - if (name === 'typeahead') { - return 'node_modules/typeahead'; - } - if (name === 'jest-watch-typeahead') { - return 'node_modules/jest-watch-typeahead'; + if ( + ['typeahead', 'jest-watch-typeahead', 'my-watch-plugin'].includes(name) + ) { + return `node_modules/${name}`; } - if (name === 'my-watch-plugin') { - return 'node_modules/my-watch-plugin'; - } if (name.startsWith('/root')) { return name; } From 4cdcdc1dc4e6e6160ac73ecb4a0a9c47656ba671 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sat, 20 Oct 2018 08:47:58 -0700 Subject: [PATCH 4/8] Simplify implementation of resolve with prefix --- .../__snapshots__/normalize.test.js.snap | 2 +- packages/jest-config/src/utils.js | 76 +++++++------------ 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap index 0a733da3bf58..4f2e379c9251 100644 --- a/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap +++ b/packages/jest-config/src/__tests__/__snapshots__/normalize.test.js.snap @@ -84,7 +84,7 @@ exports[`testPathPattern --testPathPattern ignores invalid regular expressions a exports[`watchPlugins throw error when a watch plugin is not found 1`] = ` "Validation Error: - Watch plugin missing-plugin cannot be found. Make sure the each element in watchPlugins configuration option points to an existing node module. + Watch plugin missing-plugin cannot be found. Make sure the watchPlugins configuration option points to an existing node module. Configuration Documentation: https://jestjs.io/docs/configuration.html diff --git a/packages/jest-config/src/utils.js b/packages/jest-config/src/utils.js index 97a1665fbdc8..95f3b0a976ab 100644 --- a/packages/jest-config/src/utils.js +++ b/packages/jest-config/src/utils.js @@ -105,13 +105,17 @@ export const _replaceRootDirTags = (rootDir: string, config: any) => { export const resolveWithPrefix = ( resolver: ?string, { - rootDir, filePath, + humanOptionName, + optionName, prefix, + rootDir, }: { - rootDir: string, filePath: string, + humanOptionName: string, + optionName: string, prefix: string, + rootDir: string, }, ) => { const fileName = replaceRootDirInPath(rootDir, filePath); @@ -138,6 +142,14 @@ export const resolveWithPrefix = ( try { return require.resolve(fileName); } catch (e) {} + + throw createValidationError( + ` ${humanOptionName} ${chalk.bold( + fileName, + )} cannot be found. Make sure the ${chalk.bold( + optionName, + )} configuration option points to an existing node module.`, + ); }; /** @@ -151,26 +163,18 @@ export const resolveWithPrefix = ( export const getTestEnvironment = ({ rootDir, testEnvironment: filePath, -}: Object) => { - const module = resolveWithPrefix(null, { +}: { + rootDir: string, + testEnvironment: string, +}) => + resolveWithPrefix(null, { filePath, + humanOptionName: 'Test environment', + optionName: 'testEnvironment', prefix: 'jest-environment-', rootDir, }); - if (!module) { - throw createValidationError( - ` Test environment ${chalk.bold( - replaceRootDirInPath(rootDir, filePath), - )} cannot be found. Make sure the ${chalk.bold( - 'testEnvironment', - )} configuration option points to an existing node module.`, - ); - } - - return module; -}; - /** * Finds the watch plugins to use: * @@ -182,26 +186,15 @@ export const getTestEnvironment = ({ export const getWatchPlugin = ( resolver: ?string, {filePath, rootDir}: {filePath: string, rootDir: string}, -) => { - const module = resolveWithPrefix(resolver, { +) => + resolveWithPrefix(resolver, { filePath, + humanOptionName: 'Watch plugin', + optionName: 'watchPlugins', prefix: 'jest-watch-', rootDir, }); - if (!module) { - throw createValidationError( - ` Watch plugin ${chalk.bold( - replaceRootDirInPath(rootDir, filePath), - )} cannot be found. Make sure the each element in ${chalk.bold( - 'watchPlugins', - )} configuration option points to an existing node module.`, - ); - } - - return module; -}; - /** * Finds the runner to use: * @@ -213,26 +206,15 @@ export const getWatchPlugin = ( export const getRunner = ( resolver: ?string, {filePath, rootDir}: {filePath: string, rootDir: string}, -) => { - const module = resolveWithPrefix(resolver, { +) => + resolveWithPrefix(resolver, { filePath, + humanOptionName: 'Jest Runner', + optionName: 'runner', prefix: 'jest-runner-', rootDir, }); - if (!module) { - throw createValidationError( - ` Jest Runner ${chalk.bold( - replaceRootDirInPath(rootDir, filePath), - )} cannot be found. Make sure the ${chalk.bold( - 'runner', - )} configuration option points to an existing node module.`, - ); - } - - return module; -}; - export const isJSONString = (text: ?string) => text && typeof text === 'string' && From 867960ae6c19e3236f850dc9c7e95ec0a5c8ecb4 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sat, 20 Oct 2018 09:03:28 -0700 Subject: [PATCH 5/8] update docs update docs --- docs/Configuration.md | 18 ++++++++++++++++++ .../version-23.6/Configuration.md | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/docs/Configuration.md b/docs/Configuration.md index 4cb938e87af2..07d43e44cf8d 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -609,6 +609,8 @@ This option allows you to use a custom runner instead of Jest's default test run - [`jest-runner-tsc`](https://github.com/azz/jest-runner-tsc) - [`jest-runner-prettier`](https://github.com/keplersj/jest-runner-prettier) +_Note: The `runner` property value can omit the `jest-runner-` prefix of the package name._ + To write a test-runner, export a class with which accepts `globalConfig` in the constructor, and has a `runTests` method with the signature: ```ts @@ -960,3 +962,19 @@ Default: `[]` An array of RegExp patterns that are matched against all source file paths before re-running tests in watch mode. If the file path matches any of the patterns, when it is updated, it will not trigger a re-run of tests. These patterns match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/node_modules/"]`. + +### `watchPlugins` [array] + +Default: `[]` + +This option allows you to use a custom watch plugins. Read more about watch plugins [here](watch-plugins). + +Examples of watch plugins include: + +- [`jest-watch-master`](https://github.com/rickhanlonii/jest-watch-master) +- [`jest-watch-select-projects`](https://github.com/rogeliog/jest-watch-select-projects) +- [`jest-watch-suspend`](https://github.com/unional/jest-watch-suspend) +- [`jest-watch-typeahead`](https://github.com/jest-community/jest-watch-typeahead) +- [`jest-watch-yarn-workspaces`](https://github.com/cameronhunter/jest-watch-directories/tree/master/packages/jest-watch-yarn-workspaces) + +_Note: The values in the `watchPlugins` property value can omit the `jest-watch-` prefix of the package name._ diff --git a/website/versioned_docs/version-23.6/Configuration.md b/website/versioned_docs/version-23.6/Configuration.md index 430741801ac9..f344d354d949 100644 --- a/website/versioned_docs/version-23.6/Configuration.md +++ b/website/versioned_docs/version-23.6/Configuration.md @@ -938,3 +938,17 @@ Default: `[]` An array of RegExp patterns that are matched against all source file paths before re-running tests in watch mode. If the file path matches any of the patterns, when it is updated, it will not trigger a re-run of tests. These patterns match against the full path. Use the `` string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: `["/node_modules/"]`. + +### `watchPlugins` [array] + +Default: `[]` + +This option allows you to use a custom watch plugins. Read more about watch plugins [here](watch-plugins). + +Examples of watch plugins include: + +- [`jest-watch-master`](https://github.com/rickhanlonii/jest-watch-master) +- [`jest-watch-select-projects`](https://github.com/rogeliog/jest-watch-select-projects) +- [`jest-watch-suspend`](https://github.com/unional/jest-watch-suspend) +- [`jest-watch-typeahead`](https://github.com/jest-community/jest-watch-typeahead) +- [`jest-watch-yarn-workspaces`](https://github.com/cameronhunter/jest-watch-directories/tree/master/packages/jest-watch-yarn-workspaces) From 38bb0888cfad6768557f074570617623aaba9aa0 Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sun, 21 Oct 2018 09:21:06 -0700 Subject: [PATCH 6/8] Fix Flow for testEnvironment --- packages/jest-config/src/normalize.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index db8730afd08e..d527ae308c2b 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -374,7 +374,10 @@ export default function normalize(options: InitialOptions, argv: Argv) { } if (options.testEnvironment) { - options.testEnvironment = getTestEnvironment(options); + options.testEnvironment = getTestEnvironment({ + rootDir: options.rootDir, + testEnvironment: options.testEnvironment, + }); } if (!options.roots && options.testPathDirs) { From 7f6a135dfb6ae30e220c1c168cc4a2370ae2c27d Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sun, 21 Oct 2018 09:29:19 -0700 Subject: [PATCH 7/8] Update run_test to only pass the first test env --- packages/jest-runner/src/run_test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-runner/src/run_test.js b/packages/jest-runner/src/run_test.js index bba71b2c2dfe..c0a36ed94efb 100644 --- a/packages/jest-runner/src/run_test.js +++ b/packages/jest-runner/src/run_test.js @@ -55,10 +55,10 @@ async function runTestInternal( let testEnvironment = config.testEnvironment; - if (customEnvironment) { + if (customEnvironment && customEnvironment[0]) { testEnvironment = getTestEnvironment( Object.assign({}, config, { - testEnvironment: customEnvironment, + testEnvironment: customEnvironment[0], }), ); } From 3d7207503d11ab98efc78b45b1a649f5282bab8d Mon Sep 17 00:00:00 2001 From: Rogelio Guzman Date: Sun, 21 Oct 2018 09:45:07 -0700 Subject: [PATCH 8/8] Revert customEnviroment change --- packages/jest-runner/src/run_test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/jest-runner/src/run_test.js b/packages/jest-runner/src/run_test.js index c0a36ed94efb..4292349ec8e3 100644 --- a/packages/jest-runner/src/run_test.js +++ b/packages/jest-runner/src/run_test.js @@ -55,10 +55,11 @@ async function runTestInternal( let testEnvironment = config.testEnvironment; - if (customEnvironment && customEnvironment[0]) { + if (customEnvironment) { testEnvironment = getTestEnvironment( Object.assign({}, config, { - testEnvironment: customEnvironment[0], + // $FlowFixMe + testEnvironment: customEnvironment, }), ); }