Skip to content

Commit 98235be

Browse files
committedSep 7, 2021
feat(tesbb): Update jest config.
1 parent bddbfae commit 98235be

File tree

3 files changed

+62
-36
lines changed

3 files changed

+62
-36
lines changed
 

‎packages/tsbb/src/jest/babelTransform.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@ import babelJest from 'babel-jest';
22

33
module.exports = babelJest.createTransformer({
44
presets: [
5-
require.resolve('@babel/preset-env'),
6-
require.resolve('@babel/preset-typescript'),
7-
require.resolve('@babel/preset-react'),
5+
[
6+
require('@babel/preset-env').default,
7+
{
8+
targets: {
9+
node: 'current',
10+
},
11+
},
12+
],
13+
require('@babel/preset-typescript').default,
14+
require('@babel/preset-react').default,
815
],
916
plugins: [
10-
require.resolve('@babel/plugin-transform-runtime'),
11-
require.resolve('@babel/plugin-proposal-class-properties'),
12-
require.resolve('@babel/plugin-proposal-object-rest-spread'),
17+
require('@babel/plugin-transform-runtime').default,
18+
// require('babel-plugin-add-module-exports').default,
19+
// require('@babel/plugin-proposal-object-rest-spread').default,
20+
// require('babel-plugin-transform-typescript-metadata').default,
21+
// [require('@babel/plugin-proposal-decorators').default],
22+
// [require('@babel/plugin-transform-classes').default],
23+
// // ["@babel/plugin-proposal-private-property-in-object", { "loose": false }],
24+
// [require('@babel/plugin-proposal-private-property-in-object').default, {
25+
// loose: false,
26+
// }],
27+
// [require('@babel/plugin-proposal-class-properties').default, {
28+
// loose: false,
29+
// }]
1330
],
1431
});

‎packages/tsbb/src/jest/jest.config.ts

+34-28
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,71 @@ interface IJestConfig extends Jest.Config.InitialOptions {
88
export default (resolve: Function, rootDir: string) => {
99
const conf: IJestConfig = {
1010
rootDir: rootDir,
11-
/**
12-
* Alias: -w. Specifies the maximum number of workers the worker-pool will spawn for running tests.
13-
* In single run mode, this defaults to the number of the cores available on your machine minus one for the main thread.
14-
* In watch mode, this defaults to half of the available cores on your machine to ensure Jest is unobtrusive and does not grind your machine to a halt.
15-
* It may be useful to adjust this in resource limited environments like CIs but the defaults should be adequate for most use-cases.
16-
* For environments with variable CPUs available, you can use percentage based configuration: --maxWorkers=50%
17-
*/
18-
maxWorkers: '50%',
19-
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'],
20-
testMatch: ['<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/**/?(*.)(spec|test).{js,jsx,ts,tsx}'],
21-
testURL: 'http://localhost',
11+
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
12+
testMatch: ['<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
13+
testEnvironment: 'jsdom',
14+
testRunner: require.resolve('jest-circus/runner'),
2215
transform: {
23-
'^.+\\.(js|jsx|ts|tsx)$': resolve('lib/jest/babelTransform.js'),
24-
'^.+\\.(css|less|sass|scss)$': resolve('lib/jest/cssTransform.js'),
25-
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': resolve('lib/jest/fileTransform.js'),
16+
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': resolve('lib/jest/babelTransform.js'),
17+
'^.+\\.css$': resolve('lib/jest/cssTransform.js'),
18+
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': resolve('lib/jest/fileTransform.js'),
2619
},
27-
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$'],
20+
transformIgnorePatterns: [
21+
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
22+
'^.+\\.module\\.(css|less|styl|sass|scss)$',
23+
],
2824
moduleNameMapper: {
29-
'^.+\\.module\\.(css|less|sass|scss)$': 'identity-obj-proxy',
25+
'^react-native$': 'react-native-web',
26+
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
3027
},
28+
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
29+
resetMocks: true,
3130
};
3231

3332
const overrides: IJestConfig = Object.assign({}, require(path.join(rootDir, 'package.json')).jest);
3433

3534
if (overrides) {
3635
const supportedKeys: string[] = [
36+
'clearMocks',
3737
'collectCoverageFrom',
38+
'coveragePathIgnorePatterns',
3839
'coverageReporters',
3940
'coverageThreshold',
40-
'globals',
41-
'mapCoverage',
42-
'moduleFileExtensions',
43-
'modulePathIgnorePatterns',
41+
'displayName',
42+
'extraGlobals',
43+
'globalSetup',
44+
'globalTeardown',
4445
'moduleNameMapper',
45-
'modulePaths',
46+
'resetMocks',
47+
'resetModules',
48+
'restoreMocks',
4649
'snapshotSerializers',
47-
'setupFiles',
4850
'testMatch',
49-
'testEnvironmentOptions',
50-
'testResultsProcessor',
5151
'transform',
5252
'transformIgnorePatterns',
53-
'reporters',
53+
'watchPathIgnorePatterns',
5454
];
5555
supportedKeys.forEach((key: string) => {
5656
if (overrides.hasOwnProperty(key)) {
57-
conf[key] = overrides[key];
57+
if (Array.isArray(conf[key]) || typeof conf[key] !== 'object') {
58+
// for arrays or primitive types, directly override the config key
59+
conf[key] = overrides[key];
60+
} else {
61+
// for object types, extend gracefully
62+
conf[key] = Object.assign({}, conf[key], overrides[key]);
63+
}
5864
delete overrides[key];
5965
}
6066
});
6167
const unsupportedKeys = Object.keys(overrides);
6268
if (unsupportedKeys.length) {
6369
console.error(
64-
'\x1b[1;31mOut of the box, kkt only supports overriding \x1b[0m' +
70+
'\x1b[1;31mOut of the box, TSBB only supports overriding \x1b[0m' +
6571
'\x1b[1;31mthese Jest options:\x1b[0m\n\n' +
6672
supportedKeys.map((key) => ' \u2022 ' + key).join('\n') +
6773
'.\n\n' +
6874
'\x1b[1;31mThese options in your package.json Jest configuration \x1b[0m' +
69-
'\x1b[1;31mare not currently supported by kkt:\x1b[0m\n\n' +
75+
'\x1b[1;31mare not currently supported by TSBB App:\x1b[0m\n\n' +
7076
unsupportedKeys.map((key) => ' \u2022 ' + key).join('\n'),
7177
);
7278
process.exit(1);

‎packages/tsbb/src/utils/output.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function copyFiles(src: string, dest: string) {
1818
}
1919

2020
export function outputLog(filename: string) {
21+
filename = path.relative(process.cwd(), filename);
2122
const pkg = getPkg();
2223
const extname = path.extname(filename).replace('.', '');
2324
const name = `\x1b[35m ${pkg.name}\x1b[0m`;
@@ -30,12 +31,14 @@ export function outputLog(filename: string) {
3031
} else if (extname == 'js') {
3132
console.log(`♻️ ${name}\x1b[33;1m JS \x1b[0m ┈┈▶ \x1b[32;1m${filename}\x1b[0m`);
3233
} else {
33-
console.log(`♻️ ${name}\x1b[37;1m ${(extname || '***').toLocaleUpperCase()} \x1b[0m ┈┈▶ \x1b[32;1m${filename}\x1b[0m`);
34+
console.log(
35+
`♻️ ${name}\x1b[37;1m ${(extname || '***').toLocaleUpperCase()} \x1b[0m ┈┈▶ \x1b[32;1m${filename}\x1b[0m`,
36+
);
3437
}
3538
}
3639

3740
function getPkg() {
3841
const dir = ts.sys.getCurrentDirectory();
3942
const pkgPath = path.resolve(dir, 'package.json');
4043
return FS.readJSONSync(pkgPath) || {};
41-
}
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.