UNPKG

mocha-chai-jest-snapshot

Version:
51 lines 2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports._replaceRootDirTags = exports.replaceRootDirInObject = exports.replaceRootDirInPath = void 0; /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ const node_path_1 = __importDefault(require("node:path")); const replaceRootDirInPath = (rootDir, filePath) => { if (!/^<rootDir>/.test(filePath)) { return filePath; } return node_path_1.default.resolve(rootDir, node_path_1.default.normalize(`./${filePath.substring("<rootDir>".length)}`)); }; exports.replaceRootDirInPath = replaceRootDirInPath; const replaceRootDirInObject = (rootDir, config) => { const newConfig = {}; for (const configKey in config) { newConfig[configKey] = configKey === "rootDir" ? config[configKey] : (0, exports._replaceRootDirTags)(rootDir, config[configKey]); } return newConfig; }; exports.replaceRootDirInObject = replaceRootDirInObject; const _replaceRootDirTags = (rootDir, config) => { if (config == null) { return config; } switch (typeof config) { case "object": if (Array.isArray(config)) { /// can be string[] or {}[] return config.map((item) => (0, exports._replaceRootDirTags)(rootDir, item)); } if (config instanceof RegExp) { return config; } return (0, exports.replaceRootDirInObject)(rootDir, config); case "string": return (0, exports.replaceRootDirInPath)(rootDir, config); } }; exports._replaceRootDirTags = _replaceRootDirTags; //# sourceMappingURL=jest-config-helper.js.map