Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Jest 20.0.0 #200

Merged
merged 14 commits into from
May 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,11 @@ Modify your project's `package.json` so that the `jest` section looks something
```
This setup should allow you to write Jest tests in Typescript and be able to locate errors without any additional gymnastics.

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`.
```json
{
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js"
}
}
```
### Coverage

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.

> **Notes:**
> * 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.
> * Remapped reports will be copied to `remapped` directory in coverage directory (e.g. `coverage/remapped`).
To generate coverage results, set the `mapCoverage` property in the `jest` configuration section to `true`.

### React Native

Expand Down
1 change: 0 additions & 1 deletion coverageprocessor.js

This file was deleted.

23 changes: 7 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-jest",
"version": "19.0.14",
"version": "20.0.0",
"main": "index.js",
"types": "./dist/index.d.ts",
"description": "A preprocessor with sourcemap support to help use Typescript with Jest",
Expand Down Expand Up @@ -55,41 +55,32 @@
]
},
"dependencies": {
"babel-jest": "^19.0.0",
"babel-jest": "^20.0.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"fs-extra": "^3.0.0",
"glob-all": "^3.1.0",
"istanbul-lib-instrument": "^1.2.0",
"jest-config": "^19.0.0",
"jest-util": "^19.0.0",
"lodash.assign": "^4.2.0",
"lodash.includes": "^4.3.0",
"lodash.partition": "^4.6.0",
"lodash.pickby": "^4.6.0",
"remap-istanbul": "^0.9.5",
"jest-config": "^20.0.0",
"jest-util": "^20.0.0",
"pkg-dir": "^2.0.0",
"source-map-support": "^0.4.4",
"tsconfig": "^6.0.0",
"yargs": "^8.0.1"
},
"peerDependencies": {
"jest": "^19.0.0",
"jest": "^20.0.0",
"typescript": "^2.1.0"
},
"devDependencies": {
"@types/es6-shim": "latest",
"@types/fs-extra": "^3.0.0",
"@types/jest": "latest",
"@types/lodash.assign": "latest",
"@types/lodash.includes": "latest",
"@types/lodash.partition": "latest",
"@types/lodash.pickby": "latest",
"@types/node": "latest",
"@types/react": "latest",
"@types/source-map-support": "latest",
"cross-spawn": "latest",
"cross-spawn-with-kill": "latest",
"doctoc": "latest",
"jest": "^19.0.0",
"jest": "^20.0.0",
"react": "latest",
"react-test-renderer": "latest",
"rimraf": "latest",
Expand Down
115 changes: 0 additions & 115 deletions src/coverageprocessor.ts

This file was deleted.

20 changes: 10 additions & 10 deletions src/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { getTSConfig } from './utils';
const glob = require('glob-all');
const nodepath = require('path');
const babelJest = require('babel-jest')
.createTransformer({
presets: [],
plugins: ['transform-es2015-modules-commonjs']
});
.createTransformer({
presets: [],
plugins: ['transform-es2015-modules-commonjs']
});

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

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

const outputText = compilerOptions.allowSyntheticDefaultImports
? babelJest.process(
tsTranspiled.outputText,
path + '.js', // babel-jest only likes .js files ¯\_(ツ)_/¯
config,
transformOptions
)
tsTranspiled.outputText,
path + '.js', // babel-jest only likes .js files ¯\_(ツ)_/¯
config,
transformOptions
)
: tsTranspiled.outputText;

// strip root part from path
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from 'path';
import * as fs from 'fs';
import * as tsconfig from 'tsconfig';

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

Expand Down Expand Up @@ -48,7 +47,7 @@ function readRawConfig(argv, root) {
}

if (typeof rawConfig === 'object') {
const config = assign({}, rawConfig);
const config = Object.assign({}, rawConfig);
config.rootDir = config.rootDir || root;
return normalize(config, argv);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/__tests__/import.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { } from 'jest';
import { } from 'node';
import * as path from 'path';
import * as path from 'path';
import runJest from '../__helpers__/runJest';

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

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

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

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

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

});
});
13 changes: 6 additions & 7 deletions tests/__tests__/jestconfig-json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const getPackageRoot = require('jest-util').getPackageRoot;

describe('get json jest config', () => {
const pkgDir = require('pkg-dir');
let yargsMock;
let getJestConfig;

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

const jestConfig = getJestConfig(getPackageRoot());
const jestConfig = getJestConfig(pkgDir.sync());

const { collectCoverage } = jestConfig;
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;

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

const jestConfig = getJestConfig(getPackageRoot());
const jestConfig = getJestConfig(pkgDir.sync());

const { collectCoverage } = jestConfig;
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;

expect(collectCoverage).toBeTruthy();
expect(coverageReporters).toEqual(['html', 'json', 'text']);
expect(coverageDirectory).toContain('test_coverage_dir');
expect(collectCoverageFrom).toEqual(['src/**/*.tsx', 'src/**/*.ts']);
});
});
});
13 changes: 6 additions & 7 deletions tests/__tests__/jestconfig-package.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const getPackageRoot = require('jest-util').getPackageRoot;

describe('get package json config', () => {
const pkgDir = require('pkg-dir');
let yargsMock;
let getJestConfig;

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

const jestConfig = getJestConfig(getPackageRoot());
const jestConfig = getJestConfig(pkgDir.sync());

const { collectCoverage } = jestConfig;
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;

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

const jestConfig = getJestConfig(getPackageRoot());
const jestConfig = getJestConfig(pkgDir.sync());

const { collectCoverage } = jestConfig;
const { coverageReporters, coverageDirectory, collectCoverageFrom} = jestConfig.config;
const { coverageReporters, coverageDirectory, collectCoverageFrom } = jestConfig.options;

expect(collectCoverage).toBeTruthy();
expect(coverageReporters).toEqual(['text']);
expect(collectCoverageFrom).toEqual(['src/**/*.tsx', 'src/**/*.ts']);
});
});
});
27 changes: 0 additions & 27 deletions tests/__tests__/long-path.spec.ts

This file was deleted.

Loading