| | |
| | | return data; |
| | | } |
| | | |
| | | function _parseJson() { |
| | | const data = _interopRequireDefault(require('parse-json')); |
| | | |
| | | _parseJson = function () { |
| | | return data; |
| | | }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | function _stripJsonComments() { |
| | | const data = _interopRequireDefault(require('strip-json-comments')); |
| | | |
| | | _stripJsonComments = function () { |
| | | return data; |
| | | }; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | function _jestUtil() { |
| | | const data = require('jest-util'); |
| | | |
| | |
| | | } |
| | | |
| | | var _constants = require('./constants'); |
| | | |
| | | var _jsonlint = _interopRequireDefault(require('./vendor/jsonlint')); |
| | | |
| | | function _interopRequireDefault(obj) { |
| | | return obj && obj.__esModule ? obj : {default: obj}; |
| | |
| | | * This source code is licensed under the MIT license found in the |
| | | * LICENSE file in the root directory of this source tree. |
| | | */ |
| | | // @ts-expect-error: vendored |
| | | // Read the configuration and set its `rootDir` |
| | | // 1. If it's a `package.json` file, we look into its "jest" property |
| | | // 2. If it's a `jest.config.ts` file, we use `ts-node` to transpile & require it |
| | |
| | | try { |
| | | if (isTS) { |
| | | configObject = await loadTSConfigFile(configPath); |
| | | } else if (isJSON) { |
| | | const fileContent = fs().readFileSync(configPath, 'utf8'); |
| | | configObject = (0, _parseJson().default)( |
| | | (0, _stripJsonComments().default)(fileContent), |
| | | configPath |
| | | ); |
| | | } else { |
| | | configObject = await (0, _jestUtil().requireOrImportModule)(configPath); |
| | | } |
| | | } catch (error) { |
| | | if (isJSON) { |
| | | throw new Error( |
| | | `Jest: Failed to parse config file ${configPath}\n` + |
| | | ` ${_jsonlint.default.errors(fs().readFileSync(configPath, 'utf8'))}` |
| | | ); |
| | | } else if (isTS) { |
| | | if (isTS) { |
| | | throw new Error( |
| | | `Jest: Failed to parse the TypeScript config file ${configPath}\n` + |
| | | ` ${error}` |
| | | ); |
| | | } else { |
| | | throw error; |
| | | } |
| | | |
| | | throw error; |
| | | } |
| | | |
| | | if (configPath.endsWith(_constants.PACKAGE_JSON)) { |
| | |
| | | } |
| | | |
| | | return configObject; |
| | | } // Load the TypeScript configuration |
| | | } |
| | | |
| | | let registerer; // Load the TypeScript configuration |
| | | |
| | | const loadTSConfigFile = async configPath => { |
| | | let registerer; // Register TypeScript compiler instance |
| | | |
| | | // Register TypeScript compiler instance |
| | | try { |
| | | registerer = require('ts-node').register({ |
| | | compilerOptions: { |
| | | module: 'CommonJS' |
| | | } |
| | | }); |
| | | registerer || |
| | | (registerer = require('ts-node').register({ |
| | | compilerOptions: { |
| | | module: 'CommonJS' |
| | | } |
| | | })); |
| | | } catch (e) { |
| | | if (e.code === 'MODULE_NOT_FOUND') { |
| | | throw new Error( |