Skip to content

Commit 341fdc8

Browse files
committed
Generate Jest config with custom TypeScript target
1 parent b116989 commit 341fdc8

File tree

5 files changed

+51
-28
lines changed

5 files changed

+51
-28
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Created by https://www.gitignore.io/api/node,visualstudiocode,macos
22

3-
# Generated dirs
3+
# Generated stuff
44
.code
55
dist
66
lib

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"--no-cache",
1313
"--runInBand",
1414
"--env=node-debug",
15-
"--config=jest.config.json"
15+
"--config=$(node jest.config.js)"
1616
],
1717
"skipFiles": [
1818
"<node_internals>/**/*.js",

jest.config.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
var semver = require('semver');
3+
4+
function getSupportedTypescriptTarget() {
5+
var nodeVersion = process.versions.node;
6+
7+
if (semver.gt(nodeVersion, '7.6.0')) {
8+
return 'es2017'
9+
} else if (semver.gt(nodeVersion, '7.0.0')) {
10+
return 'es2016';
11+
} else if (semver.gt(nodeVersion, '6.0.0')) {
12+
return 'es2015';
13+
} else if (semver.gt(nodeVersion, '4.0.0')) {
14+
return 'es5';
15+
} else {
16+
return 'es3';
17+
}
18+
}
19+
20+
var jestConfig = {
21+
transform: {
22+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
23+
},
24+
testResultsProcessor: "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
25+
testRegex: "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
26+
testPathIgnorePatterns: [
27+
"<rootDir>[/\\\\](dist|coverage|node_modules)[/\\\\]",
28+
"_\\w*.\\w+$"
29+
],
30+
moduleFileExtensions: ["ts", "tsx", "js"],
31+
globals: {
32+
__TS_CONFIG__: {
33+
target: getSupportedTypescriptTarget(),
34+
inlineSourceMap: true
35+
}
36+
}
37+
};
38+
39+
module.exports = jestConfig;
40+
41+
// If this file is run as an executable, print the config stringified to JSON
42+
if (require.main === module) {
43+
console.log(JSON.stringify(jestConfig));
44+
}

jest.config.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"clean": "rimraf dist es lib coverage",
1818
"typecheck": "tsc --noEmit",
1919
"lint": "tslint --project tsconfig.json --type-check --format stylish",
20-
"test": "jest --config jest.config.json --coverage --no-cache",
21-
"test:watch": "jest --config jest.config.json --watch --updateSnapshot",
20+
"test": "jest --coverage --no-cache --config $(node jest.config.js)",
21+
"test:watch": "jest --watch --updateSnapshot --config $(node jest.config.js)",
2222
"prepare": "npm run build",
2323
"prebuild": "npm run clean",
2424
"postbuild": "rimraf {lib,es}/**/__tests__",
@@ -46,7 +46,7 @@
4646
"dts-bundle": "^0.7.2",
4747
"jest": "^19.0.2",
4848
"jest-environment-node-debug": "^2.0.0",
49-
"pascal-case": "^2.0.0",
49+
"pascal-case": "^2.0.1",
5050
"rimraf": "^2.6.1",
5151
"rollup": "^0.41.6",
5252
"rollup-plugin-commonjs": "^8.0.2",
@@ -55,7 +55,8 @@
5555
"rollup-plugin-node-resolve": "^2.0.0",
5656
"rollup-plugin-sourcemaps": "^0.4.1",
5757
"rollup-plugin-uglify": "^1.0.1",
58-
"ts-jest": "^19.0.1",
58+
"semver": "^5.3.0",
59+
"ts-jest": "^19.0.2",
5960
"tslint": "^4.5.1",
6061
"typescript": "^2.2.1"
6162
}

0 commit comments

Comments
 (0)