Skip to content

Commit 96e799c

Browse files
authored
Merge pull request #200 from kulshekhar/jest-20
Upgrade to Jest 20.0.0 closes #199
2 parents 49c2127 + 043e9b6 commit 96e799c

32 files changed

Lines changed: 3380 additions & 389 deletions

File tree

README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,11 @@ Modify your project's `package.json` so that the `jest` section looks something
5252
```
5353
This setup should allow you to write Jest tests in Typescript and be able to locate errors without any additional gymnastics.
5454

55-
By default `jest` does not provide code coverage remapping for transpiled codes, so if you'd like to have code coverage it needs additional coverage remapping. This can be done via writing custom processing script, or configure `testResultsProcessor` to use built-in coverage remapping in `ts-jest`.
56-
```json
57-
{
58-
"jest": {
59-
"transform": {
60-
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
61-
},
62-
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js"
63-
}
64-
}
65-
```
55+
### Coverage
56+
57+
Prior to version `20.0.0`, coverage reports could be obtained using the inbuilt coverage processor in `ts-jest`. Starting with version `20.0.0`, `ts-jest` delegates coverage processing to jest and no longer includes a coverage processor.
6658

67-
> **Notes:**
68-
> * If you're experiencing remapping failure with source lookup, it may due to pre-created cache from `jest`. It can be manually deleted, or execute with [`--no-cache`](https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues) to not use those.
69-
> * Remapped reports will be copied to `remapped` directory in coverage directory (e.g. `coverage/remapped`).
59+
To generate coverage results, set the `mapCoverage` property in the `jest` configuration section to `true`.
7060

7161
### React Native
7262

coverageprocessor.js

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

package.json

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-jest",
3-
"version": "19.0.14",
3+
"version": "20.0.0",
44
"main": "index.js",
55
"types": "./dist/index.d.ts",
66
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
@@ -55,41 +55,32 @@
5555
]
5656
},
5757
"dependencies": {
58-
"babel-jest": "^19.0.0",
58+
"babel-jest": "^20.0.0",
5959
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
6060
"fs-extra": "^3.0.0",
6161
"glob-all": "^3.1.0",
62-
"istanbul-lib-instrument": "^1.2.0",
63-
"jest-config": "^19.0.0",
64-
"jest-util": "^19.0.0",
65-
"lodash.assign": "^4.2.0",
66-
"lodash.includes": "^4.3.0",
67-
"lodash.partition": "^4.6.0",
68-
"lodash.pickby": "^4.6.0",
69-
"remap-istanbul": "^0.9.5",
62+
"jest-config": "^20.0.0",
63+
"jest-util": "^20.0.0",
64+
"pkg-dir": "^2.0.0",
7065
"source-map-support": "^0.4.4",
7166
"tsconfig": "^6.0.0",
7267
"yargs": "^8.0.1"
7368
},
7469
"peerDependencies": {
75-
"jest": "^19.0.0",
70+
"jest": "^20.0.0",
7671
"typescript": "^2.1.0"
7772
},
7873
"devDependencies": {
7974
"@types/es6-shim": "latest",
8075
"@types/fs-extra": "^3.0.0",
8176
"@types/jest": "latest",
82-
"@types/lodash.assign": "latest",
83-
"@types/lodash.includes": "latest",
84-
"@types/lodash.partition": "latest",
85-
"@types/lodash.pickby": "latest",
8677
"@types/node": "latest",
8778
"@types/react": "latest",
8879
"@types/source-map-support": "latest",
8980
"cross-spawn": "latest",
9081
"cross-spawn-with-kill": "latest",
9182
"doctoc": "latest",
92-
"jest": "^19.0.0",
83+
"jest": "^20.0.0",
9384
"react": "latest",
9485
"react-test-renderer": "latest",
9586
"rimraf": "latest",

src/coverageprocessor.ts

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

src/preprocessor.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { getTSConfig } from './utils';
55
const glob = require('glob-all');
66
const nodepath = require('path');
77
const babelJest = require('babel-jest')
8-
.createTransformer({
9-
presets: [],
10-
plugins: ['transform-es2015-modules-commonjs']
11-
});
8+
.createTransformer({
9+
presets: [],
10+
plugins: ['transform-es2015-modules-commonjs']
11+
});
1212

1313
export function process(src, path, config, transformOptions) {
14-
const root = require('jest-util').getPackageRoot();
14+
const root = require('pkg-dir').sync();
1515
const compilerOptions = getTSConfig(config.globals, config.collectCoverage);
1616

1717
const isTsFile = path.endsWith('.ts') || path.endsWith('.tsx');
@@ -37,11 +37,11 @@ export function process(src, path, config, transformOptions) {
3737

3838
const outputText = compilerOptions.allowSyntheticDefaultImports
3939
? babelJest.process(
40-
tsTranspiled.outputText,
41-
path + '.js', // babel-jest only likes .js files ¯\_(ツ)_/¯
42-
config,
43-
transformOptions
44-
)
40+
tsTranspiled.outputText,
41+
path + '.js', // babel-jest only likes .js files ¯\_(ツ)_/¯
42+
config,
43+
transformOptions
44+
)
4545
: tsTranspiled.outputText;
4646

4747
// strip root part from path

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as path from 'path';
33
import * as fs from 'fs';
44
import * as tsconfig from 'tsconfig';
55

6-
import assign = require('lodash.assign');
76
const normalize = require('jest-config').normalize;
87
const setFromArgv = require('jest-config/build/setFromArgv');
98

@@ -48,7 +47,7 @@ function readRawConfig(argv, root) {
4847
}
4948

5049
if (typeof rawConfig === 'object') {
51-
const config = assign({}, rawConfig);
50+
const config = Object.assign({}, rawConfig);
5251
config.rootDir = config.rootDir || root;
5352
return normalize(config, argv);
5453
}

tests/__tests__/import.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { } from 'jest';
22
import { } from 'node';
3-
import * as path from 'path';
3+
import * as path from 'path';
44
import runJest from '../__helpers__/runJest';
55

66
describe('import with relative and absolute paths', () => {
@@ -15,16 +15,16 @@ describe('import with relative and absolute paths', () => {
1515
expect(result.status).toBe(1);
1616
expect(output).toContain('4 failed, 4 total');
1717

18-
expect(stderr).toContain('at new Hello (src' + path.sep + 'classes' + path.sep + 'Hello.ts:11:11)');
18+
expect(stderr).toContain('Hello.ts:11:11)');
1919

20-
expect(stderr).toContain('at Object.<anonymous> (__tests__' + path.sep + 'classes' + path.sep + 'Hello.test.ts:9:19)');
21-
expect(stderr).toContain('at Object.<anonymous> (__tests__' + path.sep + 'classes' + path.sep + 'Hello-relative.test.ts:9:19)');
20+
expect(stderr).toContain('Hello.test.ts:9:19)');
21+
expect(stderr).toContain('Hello-relative.test.ts:9:19)');
2222

23-
expect(stderr).toContain('at Object.simpleFunction (src' + path.sep + 'absolute-import.ts:4:17)');
24-
expect(stderr).toContain('at Object.<anonymous> (__tests__' + path.sep + 'absolute-import.test.ts:8:9)');
23+
expect(stderr).toContain('absolute-import.ts:4:17)');
24+
expect(stderr).toContain('absolute-import.test.ts:8:9)');
2525

26-
expect(stderr).toContain('at Object.simpleFunction (src' + path.sep + 'relative-import.ts:4:17)');
27-
expect(stderr).toContain('at Object.<anonymous> (__tests__' + path.sep + 'relative-import.test.ts:8:9)');
26+
expect(stderr).toContain('relative-import.ts:4:17)');
27+
expect(stderr).toContain('relative-import.test.ts:8:9)');
2828
});
2929

30-
});
30+
});

tests/__tests__/jestconfig-json.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const getPackageRoot = require('jest-util').getPackageRoot;
2-
31
describe('get json jest config', () => {
2+
const pkgDir = require('pkg-dir');
43
let yargsMock;
54
let getJestConfig;
65

@@ -20,10 +19,10 @@ describe('get json jest config', () => {
2019
}
2120
});
2221

23-
const jestConfig = getJestConfig(getPackageRoot());
22+
const jestConfig = getJestConfig(pkgDir.sync());
2423

2524
const { collectCoverage } = jestConfig;
26-
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
25+
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;
2726

2827
expect(collectCoverage).toBeUndefined();
2928
expect(coverageReporters).toEqual(['html', 'json', 'text']);
@@ -41,14 +40,14 @@ describe('get json jest config', () => {
4140
}
4241
});
4342

44-
const jestConfig = getJestConfig(getPackageRoot());
43+
const jestConfig = getJestConfig(pkgDir.sync());
4544

4645
const { collectCoverage } = jestConfig;
47-
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
46+
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;
4847

4948
expect(collectCoverage).toBeTruthy();
5049
expect(coverageReporters).toEqual(['html', 'json', 'text']);
5150
expect(coverageDirectory).toContain('test_coverage_dir');
5251
expect(collectCoverageFrom).toEqual(['src/**/*.tsx', 'src/**/*.ts']);
5352
});
54-
});
53+
});

tests/__tests__/jestconfig-package.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const getPackageRoot = require('jest-util').getPackageRoot;
2-
31
describe('get package json config', () => {
2+
const pkgDir = require('pkg-dir');
43
let yargsMock;
54
let getJestConfig;
65

@@ -19,10 +18,10 @@ describe('get package json config', () => {
1918
}
2019
});
2120

22-
const jestConfig = getJestConfig(getPackageRoot());
21+
const jestConfig = getJestConfig(pkgDir.sync());
2322

2423
const { collectCoverage } = jestConfig;
25-
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
24+
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;
2625

2726
expect(collectCoverage).toBeUndefined();
2827
expect(coverageReporters).toEqual(['text']);
@@ -38,13 +37,13 @@ describe('get package json config', () => {
3837
}
3938
});
4039

41-
const jestConfig = getJestConfig(getPackageRoot());
40+
const jestConfig = getJestConfig(pkgDir.sync());
4241

4342
const { collectCoverage } = jestConfig;
44-
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
43+
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;
4544

4645
expect(collectCoverage).toBeTruthy();
4746
expect(coverageReporters).toEqual(['text']);
4847
expect(collectCoverageFrom).toEqual(['src/**/*.tsx', 'src/**/*.ts']);
4948
});
50-
});
49+
});

tests/__tests__/long-path.spec.ts

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

0 commit comments

Comments
 (0)