Skip to content

Commit 9e61969

Browse files
authored
Merge pull request #626 from huafu/feature/upgrade-babel-and-fix-tsconfig
upgrade deps - coverage, caching and source-mapping fixes, ...
2 parents c67ba4d + ef21f50 commit 9e61969

File tree

94 files changed

+1887
-1485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1887
-1485
lines changed

.github/ISSUE_TEMPLATE

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

.github/ISSUE_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- First of all, check the troubleshooting wiki page for common issues at:
2+
https://github.com/kulshekhar/ts-jest/wiki/Troubleshooting -->
3+
4+
## Issue <!-- describe the issue below -->:
5+
6+
7+
## Expected behavior <!-- describe the expected behavior below -->:
8+
9+
10+
## Output from debug log <!-- You can activate the debug logger by setting the environment variable TS_JEST_DEBUG="true" before running yarn test. The output of the logger will be in **<your_project_dir>/node_modules/ts-jest/debug.txt**, paste it below -->:
11+
```bash
12+
# content of debug.txt :
13+
14+
```
15+
16+
17+
## Minimal repo <!-- If you haven't already, create the smallest possible repo that reproduces this issue by running `npm install` and `npm test`. This will speed up any fixes that this issue might need. Paste the minimal repo URL below -->:
18+
19+
20+
<!-- Optional (but highly recommended): Configure Travis (or your favorite system) with the minimal repo. This allows potential solutions to be tested against the minimal repo. This saves everyone time and avoids a lot of back and forth. -->

COLLABORATORS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3-
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
3+
**Table of Contents**
44

55
- [Collaborator Guidelines](#collaborator-guidelines)
66
- [Installing and building the project](#installing-and-building-the-project)
77
- [Merging PRs](#merging-prs)
88
- [Versioning](#versioning)
9+
- [Tests](#tests)
10+
- [How to add tests](#how-to-add-tests)
11+
- [How to run tests](#how-to-run-tests)
912

1013
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1114

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
# ts-jest
1+
# ts-jest [![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest) [![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest) [![Greenkeeper badge](https://badges.greenkeeper.io/kulshekhar/ts-jest.svg)](https://greenkeeper.io/) [![Build Status for linux](https://travis-ci.org/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.org/kulshekhar/ts-jest) [![Build Status for Windows](https://ci.appveyor.com/api/projects/status/g8tt9qd7usv0tolb/branch/master?svg=true)](https://ci.appveyor.com/project/kulshekhar/ts-jest/branch/master)
22

3-
[![npm version](https://badge.fury.io/js/ts-jest.svg)](https://badge.fury.io/js/ts-jest)
4-
[![NPM downloads](https://img.shields.io/npm/dm/ts-jest.svg?style=flat)](https://npmjs.org/package/ts-jest)
5-
[![Greenkeeper badge](https://badges.greenkeeper.io/kulshekhar/ts-jest.svg)](https://greenkeeper.io/)
3+
**Important note**: Before reporting any issue, be sure to check the [troubleshooting page](https://github.com/kulshekhar/ts-jest/wiki/Troubleshooting).
64

7-
[![Build Status for linux](https://travis-ci.org/kulshekhar/ts-jest.svg?branch=master)](https://travis-ci.org/kulshekhar/ts-jest)
8-
[![Build Status for Windows](https://ci.appveyor.com/api/projects/status/g8tt9qd7usv0tolb/branch/master?svg=true)](https://ci.appveyor.com/project/kulshekhar/ts-jest/branch/master)
9-
10-
**Important note: When using React 16 with Node version 8, you might see wrong line numbers for errors originating from tsx files. There's [an issue with more details on this](https://github.com/kulshekhar/ts-jest/issues/334)**
115

126
> Note: Looking for collaborators. [Want to help improve ts-jest?](https://github.com/kulshekhar/ts-jest/issues/223)
137
14-
ts-jest is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript.
8+
**ts-jest** is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript.
159

1610
## Table of Contents
1711
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -233,7 +227,7 @@ In some cases, projects may not want to have a `.babelrc` file, but still need t
233227
"globals": {
234228
"ts-jest": {
235229
"babelConfig": {
236-
"presets": ["env"]
230+
"presets": ["@babel/env"]
237231
}
238232
}
239233
}
@@ -404,7 +398,6 @@ By default Jest ignores everything in `node_modules`. This setting prevents Jest
404398
## Known Limitations
405399
### Known limitations for TS compiler options
406400
- You can't use `"target": "ES6"` while using `node v4` in your test environment;
407-
- You can't use `"jsx": "preserve"` for now (see [progress of this issue](https://github.com/kulshekhar/ts-jest/issues/63));
408401
- If you use `"baseUrl": "<path_to_your_sources>"`, you also have to change `jest config` a little bit (also check [Module path mapping](#module-path-mapping) section):
409402
```json
410403
"jest": {

index.d.ts

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

index.js

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

package.json

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "ts-jest",
33
"version": "23.0.1",
4-
"main": "index.js",
4+
"main": "dist/index.js",
55
"types": "./dist/index.d.ts",
66
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
77
"scripts": {
8-
"build": "cpx index.d.ts dist/ && tsc -p .",
9-
"build:watch": "cpx index.d.ts dist/ && tsc -p . -w",
10-
"test:nolint": "npm run clean-build && node scripts/tests.js",
11-
"clean": "rimraf dist/**/* && rimraf tests/simple/coverage && rimraf tests/simple-async/coverage && rimraf tests/**/*/debug.txt && rimraf tests/**/node_modules",
8+
"build": "tsc -p tsconfig.build.json",
9+
"build:watch": "tsc -p tsconfig.build.json -w",
10+
"test:nolint": "npm run clean-build && jest --clearCache && node scripts/tests.js",
11+
"clean": "rimraf dist/**/* && rimraf tests/*/coverage && rimraf tests/*/debug.txt && rimraf tests/*/node_modules",
1212
"clean-build": "npm run clean && npm run build",
1313
"pretest": "npm run tslint && npm run clean-build",
1414
"test": "node scripts/tests.js",
15-
"tslint": "tslint src/*.ts",
15+
"tslint": "tslint 'src/**/*.ts'",
1616
"doc": "doctoc .",
1717
"prepublish": "npm run clean-build",
1818
"precommit": "lint-staged",
@@ -38,7 +38,7 @@
3838
"homepage": "https://github.com/kulshekhar/ts-jest#readme",
3939
"jest": {
4040
"transform": {
41-
"^.+\\.tsx?$": "<rootDir>/dist/preprocessor.js"
41+
"^.+\\.tsx?$": "<rootDir>/dist/index.js"
4242
},
4343
"testRegex": "tests/__tests__/.*\\.spec\\.ts$",
4444
"testPathIgnorePatterns": [
@@ -59,47 +59,54 @@
5959
"js",
6060
"jsx",
6161
"json"
62-
]
62+
],
63+
"globals": {
64+
"ts-jest": {
65+
"tsConfigFile": "tsconfig.base.json"
66+
}
67+
}
6368
},
6469
"dependencies": {
65-
"babel-plugin-istanbul": "^4.1.6",
66-
"babel-preset-jest": "^23.0.0",
70+
"closest-file-data": "^0.1.4",
6771
"fs-extra": "6.0.1",
6872
"lodash": "^4.17.10"
6973
},
7074
"peerDependencies": {
71-
"babel-core": "^6.26.3 || ^7.0.0-0",
75+
"babel-core": "^6.0.0 || ^7.0.0-0",
76+
"babel-jest": "^23.0.0 || ^24.0.0",
7277
"jest": "^23.0.0 || ^24.0.0",
7378
"typescript": "^2.0.0 || ^3.0.0"
7479
},
7580
"devDependencies": {
76-
"@types/babel-core": "latest",
81+
"@babel/core": "^7.0.0-beta.54",
82+
"@babel/preset-env": "^7.0.0-beta.54",
83+
"@types/babel-core": "^6.25.5",
7784
"@types/es6-shim": "0.31.37",
7885
"@types/fs-extra": "5.0.4",
79-
"@types/jest": "^23.1.0",
86+
"@types/jest": "^23.3.0",
8087
"@types/lodash": "^4.14.109",
8188
"@types/node": "10.5.5",
8289
"@types/react": "16.4.7",
8390
"@types/yargs": "^11.0.0",
84-
"babel-core": "^6.26.3",
85-
"babel-preset-env": "^1.7.0",
91+
"babel-jest": "^23.4.0",
92+
"babel-preset-jest": "^23.2.0",
93+
"babel-core": "^7.0.0-0",
8694
"cpx": "^1.5.0",
8795
"cross-spawn": "latest",
8896
"cross-spawn-with-kill": "latest",
8997
"doctoc": "latest",
9098
"husky": "^0.14.3",
91-
"jest": "^23.0.0",
92-
"jest-config": "^23.0.0",
99+
"jest": "^23.4.1",
100+
"jest-config": "^23.4.1",
93101
"lint-staged": "^7.1.2",
94102
"pkg-dir": "^3.0.0",
95103
"prettier": "^1.12.1",
96104
"react": "16.4.2",
97105
"react-test-renderer": "16.4.2",
98106
"reflect-metadata": "^0.1.12",
99107
"rimraf": "^2.6.2",
100-
"ts-jest": "23.0.0",
101-
"tslint": "^5.10.0",
102-
"typescript": "^2.8.3",
108+
"tslint": "^5.11.0",
109+
"typescript": "^2.9.2",
103110
"yargs": "^12.0.1"
104111
},
105112
"lint-staged": {

preprocessor.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/tests.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@ function getDirectories(rootDir) {
1313
});
1414
}
1515

16+
function isJestFolder(basename) {
17+
return basename.startsWith('__') && basename.endsWith('__');
18+
}
19+
20+
// TODO: later we could add a `.test-case-keep` empty file in each folder?
21+
// ...or move all into a `test-cases` dedicated directory
22+
function isTestCaseFolder(basename) {
23+
return !isJestFolder(basename);
24+
}
25+
1626
function createIntegrationMock() {
1727
const testsRoot = 'tests';
18-
const testCaseFolders = getDirectories(testsRoot).filter(function(testDir) {
19-
return !(testDir.startsWith('__') && testDir.endsWith('__'));
20-
});
28+
const testCaseFolders = getDirectories(testsRoot).filter(isTestCaseFolder);
2129

2230
testCaseFolders.forEach(directory => {
2331
const testCaseNodeModules = path.join(testsRoot, directory, 'node_modules');
2432

2533
const rootDir = path.resolve('.');
2634
const testCaseModuleFolder = path.join(testCaseNodeModules, 'ts-jest');
2735

28-
// Copy javascript files
29-
fs.copySync(
30-
path.resolve(rootDir, 'index.js'),
31-
path.resolve(testCaseModuleFolder, 'index.js')
32-
);
33-
fs.copySync(
34-
path.resolve(rootDir, 'preprocessor.js'),
35-
path.resolve(testCaseModuleFolder, 'preprocessor.js')
36-
);
37-
3836
// Copy package.json
3937
fs.copySync(
4038
path.resolve(rootDir, 'package.json'),

src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import getCacheKey from './utils/get-cache-key';
2+
import preprocess from './preprocess';
3+
4+
const createTransformer = (options?: any): jest.Transformer => {
5+
// options are always empty, must be the older jest API giving options here
6+
return {
7+
canInstrument: true,
8+
getCacheKey,
9+
process: preprocess,
10+
createTransformer: undefined as any,
11+
};
12+
};
13+
14+
const mod = createTransformer();
15+
mod.createTransformer = createTransformer;
16+
export = mod;

src/jest-types.ts

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

0 commit comments

Comments
 (0)