-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (46 loc) · 1.68 KB
/
test.js
File metadata and controls
51 lines (46 loc) · 1.68 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { run as jestRun } from 'jest';
import chalk from 'chalk';
import { paths } from '../paths';
import { checkTypescriptSetup, readPackageJsonOfPackage } from '../utils';
export function test(cleanArgs) {
try {
process.env.NODE_ENV = 'test';
process.env.BABEL_ENV = 'test'; // because we're using babel for transforming JSX
const isTypescriptConfigured = checkTypescriptSetup();
const packagePackageJSON = readPackageJsonOfPackage();
const jestConfig = {
testEnvironment: 'jsdom',
transform: {
'.(js|jsx)$': require.resolve('../jest/babelTransform.js'),
...(isTypescriptConfigured && {
'.(ts|tsx)$': require.resolve('ts-jest'),
}),
'.(css|scss|sass|styl|stylus|less)$': require.resolve(
'../jest/cssTransform.js'
),
},
// transformIgnorePatterns already includes node_modules
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'], // it is default, explicitly specifying
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
testMatch: [
'<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/**/*.(spec|test).{ts,tsx,js,jsx}',
],
rootDir: paths.packageRoot,
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
};
cleanArgs.push(
'--config',
JSON.stringify({ ...jestConfig, ...packagePackageJSON.jest })
);
// pass any other options directly to jest
jestRun(cleanArgs);
} catch (error) {
console.error(chalk.red(`Failed to run tests: ${error.message}`));
console.error('error', error);
process.exit(1);
}
}