UNPKG

@airbnb/config-jest

Version:
74 lines (73 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@beemo/core"); const nimbus_common_1 = require("@airbnb/nimbus-common"); const exts = nimbus_common_1.EXTS.map((ext) => ext.slice(1)); const extsWithoutJSON = exts.filter((ext) => ext !== 'json'); function fromHere(filePath) { return `<rootDir>/${new core_1.Path(process.cwd()).relativeTo(new core_1.Path(__dirname, '..', filePath).resolve())}`; } function createCoveragePattern(folder) { return `**/${folder}/**/*.{${extsWithoutJSON.join(',')}}`; } /** * Create a root project config for a project. */ function getConfig({ graphql = false, react = false, srcFolder, testFolder, threshold = 75, workspaces = [], }) { const roots = []; const setupFiles = [fromHere('setup/shims.js'), fromHere('setup/console.js')]; const setupFilesAfterEnv = [fromHere('bootstrap/consumer.js')]; if (workspaces.length > 0) { workspaces.forEach((wsPath) => { roots.push(new core_1.Path('<rootDir>', wsPath.replace('/*', '')).path()); }); } else { roots.push('<rootDir>'); } if (react) { setupFiles.push(fromHere('setup/dom.js')); setupFilesAfterEnv.unshift(fromHere('bootstrap/react.js')); } if (graphql) { setupFilesAfterEnv.unshift(fromHere('bootstrap/graphql.js')); } const config = { bail: false, collectCoverageFrom: [createCoveragePattern(srcFolder), createCoveragePattern(testFolder)], coverageDirectory: './coverage', coveragePathIgnorePatterns: nimbus_common_1.IGNORE_PATHS.filter((ignore) => !ignore.startsWith('*')), coverageReporters: ['lcov', 'json-summary', 'html'], coverageThreshold: { global: { branches: threshold, functions: threshold, lines: threshold, statements: threshold, }, }, globals: { __DEV__: true, }, // Add custom mock extension so libs can export mocks moduleFileExtensions: ['mock.js', ...exts, 'node'], moduleNameMapper: { [`^.+${nimbus_common_1.ASSET_EXT_PATTERN.source}`]: fromHere('mocks/file.js'), }, roots, setupFiles, setupFilesAfterEnv, testEnvironment: react ? 'jsdom' : 'node', testURL: 'http://localhost', timers: 'fake', verbose: false, }; if (graphql) { config.transform = { [`^.+${nimbus_common_1.GQL_EXT_PATTERN.source}`]: fromHere('transformers/graphql.js'), [`^.+${nimbus_common_1.TJSX_EXT_PATTERN.source}`]: 'babel-jest', }; } return config; } exports.getConfig = getConfig;