-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
35 lines (29 loc) · 1.04 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* --------------------
* is-it-type module
* Jest config
* ------------------*/
'use strict';
// Exports
module.exports = {
testEnvironment: 'node',
coverageDirectory: 'coverage',
collectCoverageFrom: ['src/**/*.js'],
setupFilesAfterEnv: ['jest-extended/all'],
// Resolve `import from 'is-it-type'` to src or build, depending on env variable
moduleNameMapper: {
'^is-it-type$': resolvePath()
},
// Transform ESM helpers to CJS
transformIgnorePatterns: ['<rootDir>/node_modules/(?!@babel/runtime/helpers/esm/)']
};
function resolvePath() {
const testEnv = (process.env.TEST_ENV || '').toLowerCase(),
isProd = process.env.NODE_ENV === 'production';
if (!testEnv) return '<rootDir>/src/index.js';
if (testEnv === 'cjs') return '<rootDir>/index.js';
if (testEnv === 'esm') return `<rootDir>/dist/esm/is-it-type${isProd ? '.min' : ''}.js`;
if (testEnv === 'umd') return `<rootDir>/dist/umd/is-it-type${isProd ? '.min' : ''}.js`;
throw new Error(
`Invalid TEST_ENV '${testEnv}' - valid options are 'cjs', 'esm', 'umd' or undefined`
);
}