forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strict and explicit config resolution logic (jestjs#4122)
* Stricter config resolution logic * glob projects
- Loading branch information
1 parent
b168385
commit 7725f05
Showing
12 changed files
with
417 additions
and
162 deletions.
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
97 changes: 97 additions & 0 deletions
97
packages/jest-config/src/__tests__/resolve_config_path.test.js
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,97 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {cleanup, writeFiles} from '../../../../integration_tests/utils'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
import resolveConfigPath from '../resolve_config_path'; | ||
|
||
import skipOnWindows from '../../../../scripts/skip_on_windows'; | ||
|
||
skipOnWindows.suite(); | ||
|
||
const DIR = path.resolve(os.tmpdir(), 'resolve_config_path_test'); | ||
const ERROR_PATTERN = /Could not find a config file based on provided values/; | ||
const NO_ROOT_DIR_ERROR_PATTERN = /Can\'t find a root directory/; | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
test('file path', () => { | ||
const relativeConfigPath = 'a/b/c/my_config.js'; | ||
const absoluteConfigPath = path.resolve(DIR, relativeConfigPath); | ||
|
||
writeFiles(DIR, {[relativeConfigPath]: ''}); | ||
|
||
// absolute | ||
expect(resolveConfigPath(absoluteConfigPath, DIR)).toBe(absoluteConfigPath); | ||
expect(() => resolveConfigPath('/does_not_exist', DIR)).toThrowError( | ||
NO_ROOT_DIR_ERROR_PATTERN, | ||
); | ||
|
||
// relative | ||
expect(resolveConfigPath(relativeConfigPath, DIR)).toBe(absoluteConfigPath); | ||
expect(() => resolveConfigPath('does_not_exist', DIR)).toThrowError( | ||
NO_ROOT_DIR_ERROR_PATTERN, | ||
); | ||
}); | ||
|
||
test('directory path', () => { | ||
const relativePackageJsonPath = 'a/b/c/package.json'; | ||
const absolutePackageJsonPath = path.resolve(DIR, relativePackageJsonPath); | ||
const relativeJestConfigPath = 'a/b/c/jest.config.js'; | ||
const absoluteJestConfigPath = path.resolve(DIR, relativeJestConfigPath); | ||
|
||
writeFiles(DIR, {'a/b/c/some_random_file.js': ''}); | ||
|
||
// no configs yet. should throw | ||
expect(() => | ||
// absolute | ||
resolveConfigPath(path.dirname(absoluteJestConfigPath), DIR), | ||
).toThrowError(ERROR_PATTERN); | ||
|
||
expect(() => | ||
// relative | ||
resolveConfigPath(path.dirname(relativeJestConfigPath), DIR), | ||
).toThrowError(ERROR_PATTERN); | ||
|
||
writeFiles(DIR, {[relativePackageJsonPath]: ''}); | ||
|
||
// absolute | ||
expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe( | ||
absolutePackageJsonPath, | ||
); | ||
|
||
// relative | ||
expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe( | ||
absolutePackageJsonPath, | ||
); | ||
|
||
writeFiles(DIR, {[relativeJestConfigPath]: ''}); | ||
|
||
// jest.config.js takes presedence | ||
|
||
// absolute | ||
expect(resolveConfigPath(path.dirname(absolutePackageJsonPath), DIR)).toBe( | ||
absoluteJestConfigPath, | ||
); | ||
|
||
// relative | ||
expect(resolveConfigPath(path.dirname(relativePackageJsonPath), DIR)).toBe( | ||
absoluteJestConfigPath, | ||
); | ||
|
||
expect(() => { | ||
resolveConfigPath( | ||
path.join(path.dirname(relativePackageJsonPath), 'j/x/b/m/'), | ||
DIR, | ||
); | ||
}).toThrowError(NO_ROOT_DIR_ERROR_PATTERN); | ||
}); |
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.
Oops, something went wrong.