From d3f74e315e4c0a0e18fe961e5245c6b8751e541c Mon Sep 17 00:00:00 2001 From: Aaron Abramov Date: Sat, 8 Jul 2017 02:19:41 -0700 Subject: [PATCH] skipNodeResolution config option (#3987) --- packages/jest-cli/src/search_source.js | 10 ++-------- packages/jest-config/src/index.js | 1 + packages/jest-config/src/normalize.js | 1 + packages/jest-config/src/valid_config.js | 1 + packages/jest-haste-map/src/index.js | 2 +- packages/jest-resolve/src/index.js | 5 +---- types/Config.js | 2 ++ types/Resolve.js | 9 +++++---- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/jest-cli/src/search_source.js b/packages/jest-cli/src/search_source.js index e396baf4fea7..5b714099661f 100644 --- a/packages/jest-cli/src/search_source.js +++ b/packages/jest-cli/src/search_source.js @@ -10,7 +10,6 @@ import type {Context} from 'types/Context'; import type {Glob, Path} from 'types/Config'; -import type {ResolveModuleConfig} from 'types/Resolve'; import type {Test} from 'types/TestRunner'; import type {ChangedFilesPromise} from 'types/ChangedFiles'; @@ -67,7 +66,6 @@ const toTests = (context, tests) => class SearchSource { _context: Context; - _options: ResolveModuleConfig; _rootPattern: RegExp; _testIgnorePattern: ?RegExp; _testPathCases: { @@ -77,13 +75,9 @@ class SearchSource { testPathIgnorePatterns: (path: Path) => boolean, }; - constructor(context: Context, options?: ResolveModuleConfig) { + constructor(context: Context) { const {config} = context; this._context = context; - this._options = options || { - skipNodeResolution: false, - }; - this._rootPattern = new RegExp( config.roots.map(dir => escapePathForRegex(dir)).join('|'), ); @@ -162,7 +156,7 @@ class SearchSource { allPaths, this.isTestFilePath.bind(this), { - skipNodeResolution: this._options.skipNodeResolution, + skipNodeResolution: this._context.config.skipNodeResolution, }, ), ), diff --git a/packages/jest-config/src/index.js b/packages/jest-config/src/index.js index d9c4f1859113..7cf2ab1fbb5b 100644 --- a/packages/jest-config/src/index.js +++ b/packages/jest-config/src/index.js @@ -108,6 +108,7 @@ const getConfigs = ( roots: options.roots, setupFiles: options.setupFiles, setupTestFrameworkScriptFile: options.setupTestFrameworkScriptFile, + skipNodeResolution: options.skipNodeResolution, snapshotSerializers: options.snapshotSerializers, testEnvironment: options.testEnvironment, testMatch: options.testMatch, diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index b8b42e22a2e1..85575038b577 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -430,6 +430,7 @@ function normalize(options: InitialOptions, argv: Argv) { case 'resetModules': case 'rootDir': case 'silent': + case 'skipNodeResolution': case 'testEnvironment': case 'testNamePattern': case 'testRegex': diff --git a/packages/jest-config/src/valid_config.js b/packages/jest-config/src/valid_config.js index a8c6c0eeea60..60b831b75ce2 100644 --- a/packages/jest-config/src/valid_config.js +++ b/packages/jest-config/src/valid_config.js @@ -69,6 +69,7 @@ module.exports = ({ setupFiles: ['/setup.js'], setupTestFrameworkScriptFile: '/test_setup_file.js', silent: true, + skipNodeResolution: false, snapshotSerializers: ['my-serializer-module'], testEnvironment: 'jest-environment-jsdom', testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'], diff --git a/packages/jest-haste-map/src/index.js b/packages/jest-haste-map/src/index.js index 1ea9b18fa624..4dc3ae4d078a 100644 --- a/packages/jest-haste-map/src/index.js +++ b/packages/jest-haste-map/src/index.js @@ -828,7 +828,7 @@ class HasteMap extends EventEmitter { if (!match) { return true; } - + const filePathInPackage = filePath.substr(matchEndIndex); return filePathInPackage.startsWith(NODE_MODULES); } diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 1938339744d4..b96b80a1bdfc 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -10,6 +10,7 @@ import type {Path} from 'types/Config'; import type {ModuleMap} from 'types/HasteMap'; +import type {ResolveModuleConfig} from 'types/Resolve'; import fs from 'fs'; import path from 'path'; @@ -46,10 +47,6 @@ type ModuleNameMapperConfig = {| type BooleanObject = {[key: string]: boolean}; -export type ResolveModuleConfig = {| - skipNodeResolution?: boolean, -|}; - const NATIVE_PLATFORM = 'native'; // We might be inside a symlink. diff --git a/types/Config.js b/types/Config.js index b99030ea58d9..2bbc23df5729 100644 --- a/types/Config.js +++ b/types/Config.js @@ -102,6 +102,7 @@ export type InitialOptions = {| setupFiles?: Array, setupTestFrameworkScriptFile?: Path, silent?: boolean, + skipNodeResolution: boolean, snapshotSerializers?: Array, testEnvironment?: string, testMatch?: Array, @@ -176,6 +177,7 @@ export type ProjectConfig = {| roots: Array, setupFiles: Array, setupTestFrameworkScriptFile: Path, + skipNodeResolution: boolean, snapshotSerializers: Array, testEnvironment: string, testMatch: Array, diff --git a/types/Resolve.js b/types/Resolve.js index b945a6c0dfd2..2d1818bf419f 100644 --- a/types/Resolve.js +++ b/types/Resolve.js @@ -8,9 +8,10 @@ * @flow */ -import type _Resolver, { - ResolveModuleConfig as _ResolveModuleConfig, -} from 'jest-resolve'; +import type _Resolver from 'jest-resolve'; + +export type ResolveModuleConfig = {| + skipNodeResolution?: boolean, +|}; export type Resolver = _Resolver; -export type ResolveModuleConfig = _ResolveModuleConfig;