kcd-scripts
Version:
CLI for common scripts for my projects
49 lines (47 loc) • 1.78 kB
JavaScript
;
const path = require('path');
const {
ifAnyDep,
hasFile,
hasPkgProp
} = require('../utils');
const here = p => path.join(__dirname, p);
const useBuiltInBabelConfig = !hasFile('.babelrc') && !hasPkgProp('babel');
const ignores = ['/node_modules/', '/__fixtures__/', '/fixtures/', '/__tests__/helpers/', '/__tests__/utils/', '__mocks__'];
/** @type {import('@jest/types').Config.InitialOptions} */
const jestConfig = {
roots: ['<rootDir>/src'],
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react', 'preact'], 'jsdom', 'node'),
testEnvironmentOptions: {
url: 'http://localhost'
},
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
modulePaths: ['<rootDir>/src', 'shared', '<rootDir>/tests'],
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
testPathIgnorePatterns: [...ignores],
coveragePathIgnorePatterns: [...ignores, 'src/(umd|cjs|esm)-entry.js$'],
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
watchPlugins: [require.resolve('jest-watch-typeahead/filename'), require.resolve('jest-watch-typeahead/testname')],
snapshotSerializers: [require.resolve('jest-serializer-path'), require.resolve('jest-snapshot-serializer-raw/always')]
};
const setupFiles = ['tests/setup-env.js', 'tests/setup-env.ts', 'tests/setup-env.tsx'];
for (const setupFile of setupFiles) {
if (hasFile(setupFile)) {
jestConfig.setupFilesAfterEnv = [`<rootDir>/${setupFile}`];
}
}
if (useBuiltInBabelConfig) {
jestConfig.transform = {
'^.+\\.(js|jsx|ts|tsx)$': here('./babel-transform')
};
}
module.exports = jestConfig;