Skip to content

Commit

Permalink
skipNodeResolution config option (jestjs#3987)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored and cpojer committed Jul 8, 2017
1 parent ad0cac1 commit d3f74e3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
10 changes: 2 additions & 8 deletions packages/jest-cli/src/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -67,7 +66,6 @@ const toTests = (context, tests) =>

class SearchSource {
_context: Context;
_options: ResolveModuleConfig;
_rootPattern: RegExp;
_testIgnorePattern: ?RegExp;
_testPathCases: {
Expand All @@ -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('|'),
);
Expand Down Expand Up @@ -162,7 +156,7 @@ class SearchSource {
allPaths,
this.isTestFilePath.bind(this),
{
skipNodeResolution: this._options.skipNodeResolution,
skipNodeResolution: this._context.config.skipNodeResolution,
},
),
),
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function normalize(options: InitialOptions, argv: Argv) {
case 'resetModules':
case 'rootDir':
case 'silent':
case 'skipNodeResolution':
case 'testEnvironment':
case 'testNamePattern':
case 'testRegex':
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/valid_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = ({
setupFiles: ['<rootDir>/setup.js'],
setupTestFrameworkScriptFile: '<rootDir>/test_setup_file.js',
silent: true,
skipNodeResolution: false,
snapshotSerializers: ['my-serializer-module'],
testEnvironment: 'jest-environment-jsdom',
testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)'],
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class HasteMap extends EventEmitter {
if (!match) {
return true;
}

const filePathInPackage = filePath.substr(matchEndIndex);
return filePathInPackage.startsWith(NODE_MODULES);
}
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type InitialOptions = {|
setupFiles?: Array<Path>,
setupTestFrameworkScriptFile?: Path,
silent?: boolean,
skipNodeResolution: boolean,
snapshotSerializers?: Array<Path>,
testEnvironment?: string,
testMatch?: Array<Glob>,
Expand Down Expand Up @@ -176,6 +177,7 @@ export type ProjectConfig = {|
roots: Array<Path>,
setupFiles: Array<Path>,
setupTestFrameworkScriptFile: Path,
skipNodeResolution: boolean,
snapshotSerializers: Array<Path>,
testEnvironment: string,
testMatch: Array<Glob>,
Expand Down
9 changes: 5 additions & 4 deletions types/Resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit d3f74e3

Please sign in to comment.