diff --git a/package.json b/package.json
index 501a3327ef..5a44dae15b 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build:watch": "tsc -p tsconfig.build.json -w",
- "test:nolint": "npm run clean-build && node scripts/tests.js",
+ "test:nolint": "npm run clean-build && jest --clearCache && node scripts/tests.js",
"clean": "rimraf dist/**/* && rimraf tests/*/coverage && rimraf tests/*/debug.txt && rimraf tests/*/node_modules",
"clean-build": "npm run clean && npm run build",
"pretest": "npm run tslint && npm run clean-build",
diff --git a/src/index.ts b/src/index.ts
index c49fd4fb34..3cc76e8b77 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -31,5 +31,6 @@ const createTransformer = (options?: any): jest.Transformer => {
};
};
-export default createTransformer();
-export { createTransformer };
+const mod = createTransformer();
+mod.createTransformer = createTransformer;
+export = mod;
diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts
index d471bfe28d..9302b791ba 100644
--- a/src/utils/get-cache-key.ts
+++ b/src/utils/get-cache-key.ts
@@ -9,7 +9,12 @@ export default function getCacheKey(
args: JestCacheKeyArguments,
ctx: TsJestContext,
): string {
- const [fileData, filePath, jestConfigString, { instrument, rootDir }] = args;
+ const [
+ fileData,
+ filePath,
+ jestConfigString,
+ { instrument = false, rootDir = process.cwd() } = {},
+ ] = args;
const glob = JSON.parse(jestConfigString).globals || {};
return createHash('md5')
.update(MY_PACKAGE_CONTENT)
diff --git a/src/utils/logger.ts b/src/utils/logger.ts
index 094d64ee88..b7f44876a0 100644
--- a/src/utils/logger.ts
+++ b/src/utils/logger.ts
@@ -31,7 +31,7 @@ export function flushLogs(): void {
return; // only output stuff for the first invocation and if logging is enabled.
}
logsFlushed = true;
- const rootPath = path.resolve(__dirname, '../');
+ const rootPath = path.resolve(__dirname, '..', '..');
const JSONifiedLogs = logs.map(convertToJSONIfPossible);
const logString = JSONifiedLogs.join('\n');
const filePath = path.resolve(rootPath, 'debug.txt');
diff --git a/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap b/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap
new file mode 100644
index 0000000000..0eb8e0a7cc
--- /dev/null
+++ b/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap
@@ -0,0 +1,12 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Typescript async coverage Should generate the correct async coverage numbers 1`] = `
+"
+=============================== Coverage summary ===============================
+Statements : 68.75% ( 11/16 )
+Branches : 33.33% ( 2/6 )
+Functions : 66.67% ( 4/6 )
+Lines : 73.33% ( 11/15 )
+================================================================================
+"
+`;
diff --git a/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap b/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap
new file mode 100644
index 0000000000..aa24548bb4
--- /dev/null
+++ b/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap
@@ -0,0 +1,12 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Typescript coverage Should generate the correct coverage numbers. 1`] = `
+"
+=============================== Coverage summary ===============================
+Statements : 68.75% ( 11/16 )
+Branches : 33.33% ( 2/6 )
+Functions : 66.67% ( 4/6 )
+Lines : 73.33% ( 11/15 )
+================================================================================
+"
+`;
diff --git a/tests/__tests__/html-transform.spec.ts b/tests/__tests__/html-transform.spec.ts
index ec00cd8e09..744d44dadf 100644
--- a/tests/__tests__/html-transform.spec.ts
+++ b/tests/__tests__/html-transform.spec.ts
@@ -1,7 +1,7 @@
-import { process } from '../../src/preprocessor';
+import * as tsJest from '../..';
const path = '/path/to/file.html';
-const config = { globals: {} as any };
+const config: jest.ProjectConfig = { globals: {} } as any;
// wrap a transformed source so that we can fake a `require()` on it by calling the returned wrapper
const wrap = (src: string) =>
new Function(`var module={}; ${src} return module.exports;`) as any;
@@ -14,10 +14,10 @@ const source = `
describe('Html transforms', () => {
it('transforms html if config.globals.__TRANSFORM_HTML__ is set', () => {
// get the untransformed version
- const untransformed = process(source, path, config);
+ const untransformed = tsJest.process(source, path, config);
// ... then the one which should be transformed
- config.globals.__TRANSFORM_HTML__ = true;
- const transformed = process(source, path, config) as string;
+ (config.globals as any).__TRANSFORM_HTML__ = true;
+ const transformed = tsJest.process(source, path, config) as string;
// ... finally the result of a `require('module-with-transformed-version')`
const exported = wrap(transformed)();
diff --git a/tests/__tests__/postprocess.spec.ts b/tests/__tests__/postprocess.spec.ts
index 0f6df65189..bd368cf65b 100644
--- a/tests/__tests__/postprocess.spec.ts
+++ b/tests/__tests__/postprocess.spec.ts
@@ -9,13 +9,18 @@ jest.mock('@babel/core', () => {
import { getPostProcessHook } from '../../src/postprocess';
describe('postprocess', () => {
- function runHook(tsCompilerOptions = {}, jestConfig = {}, tsJestConfig = {}) {
- return getPostProcessHook(tsCompilerOptions, jestConfig, tsJestConfig)(
- { code: 'input_code', map: 'input_source_map' },
- 'fake_file',
- {},
- { instrument: null },
- );
+ function runHook(
+ tsCompilerOptions = {},
+ jestConfig: Partial = {},
+ tsJestConfig = {},
+ ) {
+ return getPostProcessHook(
+ tsCompilerOptions,
+ jestConfig as any,
+ tsJestConfig,
+ )({ code: 'input_code', map: 'input_source_map' }, 'fake_file', {} as any, {
+ instrument: null,
+ });
}
it('skips postprocess when skipBabel=true', () => {
@@ -29,10 +34,10 @@ describe('postprocess', () => {
const transformMock = require.requireMock('@babel/core').transform;
runHook();
- getPostProcessHook({}, {}, {})(
+ getPostProcessHook({}, {} as any, {})(
{ code: 'input_code', map: 'input_source_map' },
'fake_file',
- {},
+ {} as any,
{ instrument: null },
);
expect(transformMock).lastCalledWith(
diff --git a/tests/__tests__/transpile-if-ts.spec.ts b/tests/__tests__/transpile-if-ts.spec.ts
deleted file mode 100644
index 3bb07b18d0..0000000000
--- a/tests/__tests__/transpile-if-ts.spec.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { transpileIfTypescript } from '../../src/transpile-if-ts';
-
-describe('transpileIfTypescript', () => {
- it('should ignore anything non-TS', () => {
- const contents = 'unaltered';
- expect(transpileIfTypescript('some.js', contents)).toBe(contents);
- });
- it('should be able to transpile some TS', () => {
- const ts = 'const x:string = "anything";';
- expect(transpileIfTypescript('some.ts', ts)).toMatch('var x = "anything";');
- expect(transpileIfTypescript('some.tsx', ts)).toMatch(
- 'var x = "anything";',
- );
- });
-
- it('should be possible to pass a custom config', () => {
- const customTsConfigFile = 'not-existant.json';
- const customConfig = { 'ts-jest': { tsConfigFile: customTsConfigFile } };
- expect(() =>
- transpileIfTypescript('some.ts', '', customConfig),
- ).toThrowError();
- });
-});
diff --git a/tests/__tests__/ts-coverage-async.spec.ts b/tests/__tests__/ts-coverage-async.spec.ts
index d88bbde8c9..1de647b91f 100644
--- a/tests/__tests__/ts-coverage-async.spec.ts
+++ b/tests/__tests__/ts-coverage-async.spec.ts
@@ -6,9 +6,6 @@ describe('Typescript async coverage', () => {
const output = result.stdout;
- expect(output).toContain('Statements : 71.43% ( 10/14 )');
- expect(output).toContain('Branches : 33.33% ( 2/6 )');
- expect(output).toContain('Functions : 66.67% ( 4/6 )');
- expect(output).toContain('Lines : 66.67% ( 8/12 )');
+ expect(output).toMatchSnapshot();
});
});
diff --git a/tests/__tests__/ts-coverage.spec.ts b/tests/__tests__/ts-coverage.spec.ts
index b607bb60cd..88f435c455 100644
--- a/tests/__tests__/ts-coverage.spec.ts
+++ b/tests/__tests__/ts-coverage.spec.ts
@@ -6,9 +6,6 @@ describe('Typescript coverage', () => {
const output = result.stdout;
- expect(output).toContain('Statements : 71.43% ( 10/14 )');
- expect(output).toContain('Branches : 33.33% ( 2/6 )');
- expect(output).toContain('Functions : 66.67% ( 4/6 )');
- expect(output).toContain('Lines : 66.67% ( 8/12 )');
+ expect(output).toMatchSnapshot();
});
});
diff --git a/tests/button/package.json b/tests/button/package.json
index 3c6d32dd17..9a38773d3e 100644
--- a/tests/button/package.json
+++ b/tests/button/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
diff --git a/tests/coverage-simple/.gitignore b/tests/coverage-simple/.gitignore
deleted file mode 100644
index 9e233d795a..0000000000
--- a/tests/coverage-simple/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-coverage-custom
diff --git a/tests/coverage-simple/Hello.ts b/tests/coverage-simple/Hello.ts
deleted file mode 100644
index 3eaae5c40d..0000000000
--- a/tests/coverage-simple/Hello.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-interface FooInterface {
- foo: string;
- bar: number; //This interface should be stripped and the line numbers should still fit.
-}
-
-export class Hello {
- constructor() {
- const greeting = `
- this
- is
- a
- multiline
- greeting
- `;
-
- this.unexcuted(() => {});
-
- throw new Error('Hello error!');
- }
-
- unexcuted(action: () => void = () => {}): void {
- if (action) {
- action();
- } else {
- console.log('unexcuted');
- }
- }
-}
diff --git a/tests/coverage-simple/NullCoverage.js b/tests/coverage-simple/NullCoverage.js
deleted file mode 100644
index c59dbbdef3..0000000000
--- a/tests/coverage-simple/NullCoverage.js
+++ /dev/null
@@ -1,6 +0,0 @@
-function nullCoverageFunction(value) {
- if (value) {
- return value;
- }
- return null;
-}
diff --git a/tests/coverage-simple/__tests__/Hello.test.ts b/tests/coverage-simple/__tests__/Hello.test.ts
deleted file mode 100644
index 3df75018f9..0000000000
--- a/tests/coverage-simple/__tests__/Hello.test.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-declare var jest, describe, it, expect;
-
-import { Hello } from '../Hello';
-
-describe('Hello Class', () => {
- it('should throw an error on line 18', () => {
- expect(() => new Hello()).toThrow();
- });
-});
diff --git a/tests/coverage-simple/package.json b/tests/coverage-simple/package.json
deleted file mode 100644
index c577a32b44..0000000000
--- a/tests/coverage-simple/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "jest": {
- "transform": {
- "^.+\\.tsx?$": "ts-jest"
- },
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
- "coverageReporters": [
- "lcov"
- ],
- "collectCoverageFrom": [
- "Hello.ts",
- "NullCoverage.js"
- ],
- "moduleFileExtensions": [
- "ts",
- "tsx",
- "js",
- "jsx",
- "json"
- ]
- }
-}
diff --git a/tests/coverage-simple/tsconfig.json b/tests/coverage-simple/tsconfig.json
deleted file mode 100644
index 55f8667f97..0000000000
--- a/tests/coverage-simple/tsconfig.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "compilerOptions": {
- "target": "ES5",
- "module": "commonjs",
- "moduleResolution": "node",
- "noEmitOnError": false,
- "jsx": "react",
- "allowJs": true
- }
-}
diff --git a/tests/coverage-simple/yarn.lock b/tests/coverage-simple/yarn.lock
deleted file mode 100644
index fb57ccd13a..0000000000
--- a/tests/coverage-simple/yarn.lock
+++ /dev/null
@@ -1,4 +0,0 @@
-# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
-# yarn lockfile v1
-
-
diff --git a/tests/dynamic-imports/jest.allowdefaultimports.json b/tests/dynamic-imports/jest.allowdefaultimports.json
index e99202cbdc..7b6dca0e97 100644
--- a/tests/dynamic-imports/jest.allowdefaultimports.json
+++ b/tests/dynamic-imports/jest.allowdefaultimports.json
@@ -6,7 +6,7 @@
}
},
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
diff --git a/tests/dynamic-imports/package.json b/tests/dynamic-imports/package.json
index da4ca2764d..629580a5c3 100644
--- a/tests/dynamic-imports/package.json
+++ b/tests/dynamic-imports/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
diff --git a/tests/hoist-errors/package.json b/tests/hoist-errors/package.json
index c303bdc8bb..bd5ac5950e 100644
--- a/tests/hoist-errors/package.json
+++ b/tests/hoist-errors/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"coverageReporters": [
diff --git a/tests/hoist-test/package.json b/tests/hoist-test/package.json
index da7414e70f..c247ae1d78 100644
--- a/tests/hoist-test/package.json
+++ b/tests/hoist-test/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": ["node_modules", "src"],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
diff --git a/tests/imports-test/package.json b/tests/imports-test/package.json
index be12d7069a..b199be6bfc 100644
--- a/tests/imports-test/package.json
+++ b/tests/imports-test/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": [
"node_modules",
diff --git a/tests/metadata-emit/package.json b/tests/metadata-emit/package.json
index 8fe30ad48a..091c3daa5a 100644
--- a/tests/metadata-emit/package.json
+++ b/tests/metadata-emit/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": ["node_modules", "src"],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
diff --git a/tests/no-synthetic-default/package.json b/tests/no-synthetic-default/package.json
index da7414e70f..c247ae1d78 100644
--- a/tests/no-synthetic-default/package.json
+++ b/tests/no-synthetic-default/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": ["node_modules", "src"],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
diff --git a/tests/simple-async/package.json b/tests/simple-async/package.json
index 8aae224457..5c775048ef 100644
--- a/tests/simple-async/package.json
+++ b/tests/simple-async/package.json
@@ -2,7 +2,7 @@
"jest": {
"rootDir": "./",
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"coverageReporters": [
diff --git a/tests/simple-long-path/package.json b/tests/simple-long-path/package.json
index 0b4b74c76f..b352c8c040 100644
--- a/tests/simple-long-path/package.json
+++ b/tests/simple-long-path/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"coverageReporters": [
diff --git a/tests/skip-babelrc/package.json b/tests/skip-babelrc/package.json
index c303bdc8bb..bd5ac5950e 100644
--- a/tests/skip-babelrc/package.json
+++ b/tests/skip-babelrc/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"coverageReporters": [
diff --git a/tests/synthetic-default/package.json b/tests/synthetic-default/package.json
index eee0ad2384..06ae571d76 100644
--- a/tests/synthetic-default/package.json
+++ b/tests/synthetic-default/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": [
"node_modules",
diff --git a/tests/ts-diagnostics/package.json b/tests/ts-diagnostics/package.json
index 569aeaa778..c4fb8e5cca 100644
--- a/tests/ts-diagnostics/package.json
+++ b/tests/ts-diagnostics/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": [
"node_modules",
diff --git a/tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts b/tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts
index 7f63667e82..fb1e52a2b8 100644
--- a/tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts
+++ b/tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts
@@ -1,4 +1,4 @@
-import * as tsJest from 'ts-jest';
+import * as tsJest from '../../..';
describe('ts-jest module interface', () => {
it('is an object', () => {
@@ -10,4 +10,10 @@ describe('ts-jest module interface', () => {
it('has a getCacheKey function', () => {
expect(typeof tsJest.getCacheKey).toBe('function');
});
+ it('has a canInstrument property', () => {
+ expect(tsJest).toHaveProperty('canInstrument', true);
+ });
+ it('has a createTransformer function', () => {
+ expect(typeof tsJest.createTransformer).toBe('function');
+ });
});
diff --git a/tests/use-babelrc/package.json b/tests/use-babelrc/package.json
index df8c03a58a..a852e05bdb 100644
--- a/tests/use-babelrc/package.json
+++ b/tests/use-babelrc/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"moduleDirectories": [
"node_modules",
diff --git a/tests/use-strict/package.json b/tests/use-strict/package.json
index da4ca2764d..629580a5c3 100644
--- a/tests/use-strict/package.json
+++ b/tests/use-strict/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
diff --git a/tests/watch-test/package.json b/tests/watch-test/package.json
index ce61e59e39..38eaac4de2 100644
--- a/tests/watch-test/package.json
+++ b/tests/watch-test/package.json
@@ -1,7 +1,7 @@
{
"jest": {
"transform": {
- "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js"
+ "^.+\\.tsx?$": "/node_modules/ts-jest/dist/index.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"coverageReporters": [
diff --git a/tslint.json b/tslint.json
index 4c6b028a3c..2fd6de0110 100644
--- a/tslint.json
+++ b/tslint.json
@@ -31,5 +31,11 @@
],
"no-empty": false,
"member-access": false
+ },
+ "linterOptions": {
+ "exclude": [
+ "dist/**/*",
+ "**/node_modules/**/*"
+ ]
}
}