diff --git a/src/__tests__/resolver.test.js b/src/__tests__/resolver.test.js index f04978e..649fb65 100644 --- a/src/__tests__/resolver.test.js +++ b/src/__tests__/resolver.test.js @@ -178,15 +178,16 @@ describe('Jest resolver', () => { }); test('Throws when specified config file does not exist', () => { - expect(() => { - jestResolver.resolve( - 'resolveme', - '/path/to/project/__tests__/iamtest.js', - { - jestConfigFile: '__tests__/idonotexist.json', - } - ); - }).toThrow(/not\sfound/); + const result = jestResolver.resolve( + 'resolveme', + '/path/to/project/__tests__/iamtest.js', + { + jestConfigFile: '__tests__/idonotexist.json', + } + ); + expect(result).toEqual({ + found: false, + }); }); test('Resolves when is in testMatch', () => { diff --git a/src/index.js b/src/index.js index e08fdbf..bc10e88 100644 --- a/src/index.js +++ b/src/index.js @@ -48,7 +48,7 @@ exports.resolve = function resolver( config?: ResolverConfig ): ResolverResult { const jestConfig = getJestConfig(config, file); - if (!isTestFile(jestConfig, file)) { + if (jestConfig == null || !isTestFile(jestConfig, file)) { return NOTFOUND; } const pathToResolve = applyModuleNameMapper(jestConfig, source) || source; @@ -67,7 +67,7 @@ exports.resolve = function resolver( * Will use jest configuration from package.json if no jestConfigFile is defined * Applies default configuration for any required properties that are undeclared */ -function getJestConfig(config?: ResolverConfig = {}, file: Path): JestConfig { +function getJestConfig(config?: ResolverConfig = {}, file: Path): ?JestConfig { let jestConfig; const root = findRoot(file); if (config.jestConfigFile) { @@ -75,7 +75,7 @@ function getJestConfig(config?: ResolverConfig = {}, file: Path): JestConfig { try { jestConfig = require(configFilePath); } catch (e) { - throw new Error(`jestConfigFile not found in ${configFilePath}`); + return undefined; } } else { const packageJson = require(path.resolve(root, 'package.json'));