From 895b919adb9133a05f48096fd1ad7b26932268b3 Mon Sep 17 00:00:00 2001 From: Martijn The Date: Sun, 12 Nov 2017 13:31:44 +0100 Subject: [PATCH 1/5] Re-Revert "Change the package entry point to preprocessor.js itself" (46e15da9e1ee040f1d8220ec4c9289ce35bdeb53) --- AUTHORS | 1 + README.md | 8 ++++---- index.js | 1 - package.json | 4 ++-- src/{index.ts => install.ts} | 1 - src/preprocessor.ts | 7 ++++++- tests/__tests__/transpile-if-ts.spec.ts | 2 +- tests/jestconfig-test/jest.json | 2 +- 8 files changed, 15 insertions(+), 11 deletions(-) delete mode 100644 index.js rename src/{index.ts => install.ts} (90%) diff --git a/AUTHORS b/AUTHORS index 8b0d738c5f..60a328c6cf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -31,6 +31,7 @@ Justin Bay Kulshekhar Kabra Kyle Roach Marshall Bowers +Martijn The Matheus Gambati Maxim Samoilov Mohammad Rajabifard diff --git a/README.md b/README.md index 4995a97e5a..13b2b0c3a0 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Modify your project's `package.json` so that the `jest` section looks something { "jest": { "transform": { - "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" + "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ @@ -225,7 +225,7 @@ In `package.json`, inside `jest` section, the `transform` should be like this: ```json "transform": { "^.+\\.jsx?$": "/node_modules/babel-jest", - "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" + "^.+\\.tsx?$": "ts-jest" } ``` @@ -236,7 +236,7 @@ Fully completed jest section should look like this: "preset": "react-native", "transform": { "^.+\\.jsx?$": "/node_modules/babel-jest", - "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" + "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ @@ -268,7 +268,7 @@ You'll also need to extend your `transform` regex with `html` extension: { "jest": { "transform": { - "^.+\\.(tsx?|html)$": "/node_modules/ts-jest/preprocessor.js" + "^.+\\.(tsx?|html)$": "ts-jest" } } } diff --git a/index.js b/index.js deleted file mode 100644 index b91eb3834e..0000000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/index'); \ No newline at end of file diff --git a/package.json b/package.json index 92b43ecd20..1da330311e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-jest", "version": "21.2.2", - "main": "index.js", + "main": "preprocessor.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { @@ -78,7 +78,7 @@ "yargs": "^10.0.3" }, "peerDependencies": { - "jest": "^21.1.0 || ^21.1.0-alpha.1 || ^22.0.0-alpha.1", + "jest": "^21.1.0 || ^21.3.0-alpha.1 || ^22.0.0-alpha.1", "typescript": "2.x" }, "devDependencies": { diff --git a/src/index.ts b/src/install.ts similarity index 90% rename from src/index.ts rename to src/install.ts index cb243ee447..78921eb731 100644 --- a/src/index.ts +++ b/src/install.ts @@ -1,7 +1,6 @@ import * as sourceMapSupport from 'source-map-support'; import { defaultRetrieveFileHandler } from './default-retrieve-file-handler'; -export { transpileIfTypescript } from './transpile-if-ts'; export function install() { const options: sourceMapSupport.Options = {}; diff --git a/src/preprocessor.ts b/src/preprocessor.ts index c3a3f3d82f..906d0a9aa0 100644 --- a/src/preprocessor.ts +++ b/src/preprocessor.ts @@ -6,6 +6,8 @@ import { JestConfig, Path, TransformOptions } from './jest-types'; import { getPostProcessHook } from './postprocess'; import { getTSConfig, getTSJestConfig } from './utils'; +export { install } from './install'; + export function process( src: string, path: Path, @@ -51,7 +53,10 @@ export function process( const outputFilePath = nodepath.join( config.cacheDirectory, '/ts-jest/', - crypto.createHash('md5').update(path).digest('hex'), + crypto + .createHash('md5') + .update(path) + .digest('hex'), ); fs.outputFileSync(outputFilePath, outputText); diff --git a/tests/__tests__/transpile-if-ts.spec.ts b/tests/__tests__/transpile-if-ts.spec.ts index c19947d5c3..d55a015218 100644 --- a/tests/__tests__/transpile-if-ts.spec.ts +++ b/tests/__tests__/transpile-if-ts.spec.ts @@ -1,4 +1,4 @@ -import { transpileIfTypescript } from '../../src'; +import { transpileIfTypescript } from '../../src/transpile-if-ts'; describe('transpileIfTypescript', () => { it('should ignore anything non-TS', () => { diff --git a/tests/jestconfig-test/jest.json b/tests/jestconfig-test/jest.json index fa8c2a07ef..3041ff5c7b 100644 --- a/tests/jestconfig-test/jest.json +++ b/tests/jestconfig-test/jest.json @@ -1,7 +1,7 @@ { "rootDir": "./", "transform": { - "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" + "^.+\\.tsx?$": "ts-jest" }, "mapCoverage": true, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", From b7eb1811a927fe1e870d095a43e80e333248d1d4 Mon Sep 17 00:00:00 2001 From: Martijn The Date: Sun, 12 Nov 2017 16:38:20 +0100 Subject: [PATCH 2/5] - Fix #367: work-around bug in babel-core (/~https://github.com/babel/babel/pull/6524) to avoid hitting "Cannot find module '../../package' from 'node.js'" error - Change scripts/tests.js to copy the package sources, replacing the require('../../../../etc') hack (which for some reason caused #367 not to trip!?) --- index.js | 11 ++++++++ package.json | 4 +-- scripts/tests.js | 25 ++++++++++--------- src/preprocessor.ts | 2 -- .../__tests__/no-json-module-file-ext.spec.ts | 10 ++++++++ tests/babel-config-invalid/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- tests/babel-config/package.json | 2 +- tests/button/package.json | 2 +- tests/deprecated-tsconfig/package.json | 2 +- .../jest.allowdefaultimports.json | 2 +- tests/dynamic-imports/package.json | 2 +- tests/hoist-errors/package.json | 2 +- tests/hoist-test/package.json | 2 +- tests/imports-test/package.json | 7 ++++-- .../__tests__/transpile-me.test.ts | 1 + tests/no-json-module-file-ext/package.json | 19 ++++++++++++++ tests/no-json-module-file-ext/tsconfig.json | 11 ++++++++ tests/no-synthetic-default/package.json | 2 +- tests/simple-async/package.json | 2 +- tests/simple-long-path/package.json | 2 +- tests/simple/package.json | 2 +- tests/skip-babelrc/package.json | 2 +- tests/synthetic-default/package.json | 2 +- tests/use-babelrc/package.json | 2 +- tests/use-strict/package.json | 2 +- tests/watch-test/package.json | 2 +- yarn.lock | 4 +-- 29 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 index.js create mode 100644 tests/__tests__/no-json-module-file-ext.spec.ts create mode 100644 tests/no-json-module-file-ext/__tests__/transpile-me.test.ts create mode 100644 tests/no-json-module-file-ext/package.json create mode 100644 tests/no-json-module-file-ext/tsconfig.json diff --git a/index.js b/index.js new file mode 100644 index 0000000000..278fa174c5 --- /dev/null +++ b/index.js @@ -0,0 +1,11 @@ +module.exports = { + process: function() { + // Avoid require()'ing the preprocessor when index.js gets loaded as part + // of the transpiled test file output, to avoid tripping this bug in + // babel-core: /~https://github.com/babel/babel/pull/6524 which is to be + // fixed in babel-core 7.0. + // Related ts-jest issue: /~https://github.com/kulshekhar/ts-jest/issues/367 + return require('./dist/preprocessor').process.apply(null, arguments); + }, + install: require('./dist/install').install, +}; diff --git a/package.json b/package.json index 1da330311e..d25431aab6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ts-jest", "version": "21.2.2", - "main": "preprocessor.js", + "main": "index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { @@ -70,7 +70,7 @@ "babel-plugin-istanbul": "^4.1.4", "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", "babel-preset-jest": "^21.2.0", - "fs-extra": "^4.0.0", + "fs-extra": "^4.0.2", "jest-config": "^21.2.1", "jest-util": "^21.2.1", "pkg-dir": "^2.0.0", diff --git a/scripts/tests.js b/scripts/tests.js index 96b09f1981..0232ec0900 100644 --- a/scripts/tests.js +++ b/scripts/tests.js @@ -5,6 +5,7 @@ process.env.PUBLIC_URL = ''; const jest = require('jest'); const fs = require('fs'); +const fsx = require('fs-extra'); const path = require('path'); function dirExists(dirPath) { @@ -38,9 +39,6 @@ function createIntegrationMock() { const testCaseFolders = getDirectories(testsRoot).filter(function(testDir) { return !(testDir.startsWith('__') && testDir.endsWith('__')); }); - const filesToMock = getFiles('dist').filter(function(fileName) { - return fileName.endsWith('.js'); - }); for (let i = 0; i < testCaseFolders.length; i++) { const testCaseNodeModules = path.join( testsRoot, @@ -49,16 +47,19 @@ function createIntegrationMock() { ); if (!dirExists(testCaseNodeModules)) { fs.mkdirSync(testCaseNodeModules); - const testCaseModuleFolder = path.join(testCaseNodeModules, 'ts-jest'); - fs.mkdirSync(testCaseModuleFolder); - filesToMock.forEach(function(fileName) { - const integrationMockPath = path.join(testCaseModuleFolder, fileName); - fs.appendFileSync( - integrationMockPath, - getIntegrationMockContent(fileName) - ); - }); } + const testCaseModuleFolder = path.join(testCaseNodeModules, 'ts-jest'); + fsx.copySync('.', testCaseModuleFolder, { + overwrite: true, + filter: function(src, dest) { + const shouldCopy = + src === '.' || + src.startsWith('dist') || + src === 'package.json' || + src.endsWith('.js'); + return shouldCopy; + }, + }); } } diff --git a/src/preprocessor.ts b/src/preprocessor.ts index 906d0a9aa0..6a86b0034c 100644 --- a/src/preprocessor.ts +++ b/src/preprocessor.ts @@ -6,8 +6,6 @@ import { JestConfig, Path, TransformOptions } from './jest-types'; import { getPostProcessHook } from './postprocess'; import { getTSConfig, getTSJestConfig } from './utils'; -export { install } from './install'; - export function process( src: string, path: Path, diff --git a/tests/__tests__/no-json-module-file-ext.spec.ts b/tests/__tests__/no-json-module-file-ext.spec.ts new file mode 100644 index 0000000000..a01197869b --- /dev/null +++ b/tests/__tests__/no-json-module-file-ext.spec.ts @@ -0,0 +1,10 @@ +import runJest from '../__helpers__/runJest'; + +// Regression test for +// /~https://github.com/kulshekhar/ts-jest/issues/367 +describe('no json in moduleFileExtensions', () => { + it('should run successfully', () => { + const result = runJest('../no-json-module-file-ext', ['--no-cache']); + expect(result.status).toBe(0); + }); +}); diff --git a/tests/babel-config-invalid/package.json b/tests/babel-config-invalid/package.json index f37ba46fd5..509fb6ebf6 100644 --- a/tests/babel-config-invalid/package.json +++ b/tests/babel-config-invalid/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - ".(ts|tsx)": "../../preprocessor.js" + ".(ts|tsx)": "ts-jest" }, "moduleDirectories": [ "node_modules", diff --git a/tests/babel-config-merge-ignore-babelrc/package.json b/tests/babel-config-merge-ignore-babelrc/package.json index 92300b7d27..5faee4f9e1 100644 --- a/tests/babel-config-merge-ignore-babelrc/package.json +++ b/tests/babel-config-merge-ignore-babelrc/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - ".(ts|tsx)": "../../preprocessor.js" + ".(ts|tsx)": "ts-jest" }, "moduleDirectories": [ "node_modules", diff --git a/tests/babel-config-merge-with-babelrc/package.json b/tests/babel-config-merge-with-babelrc/package.json index e8595dd3d8..8660f6eb9c 100644 --- a/tests/babel-config-merge-with-babelrc/package.json +++ b/tests/babel-config-merge-with-babelrc/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - ".(ts|tsx)": "../../preprocessor.js" + ".(ts|tsx)": "ts-jest" }, "moduleDirectories": [ "node_modules", diff --git a/tests/babel-config/package.json b/tests/babel-config/package.json index 59bbeaf952..7e2ecc37c8 100644 --- a/tests/babel-config/package.json +++ b/tests/babel-config/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - ".(ts|tsx)": "../../preprocessor.js" + ".(ts|tsx)": "ts-jest" }, "moduleDirectories": [ "node_modules", diff --git a/tests/button/package.json b/tests/button/package.json index 691af28ec3..3c6d32dd17 100644 --- a/tests/button/package.json +++ b/tests/button/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ diff --git a/tests/deprecated-tsconfig/package.json b/tests/deprecated-tsconfig/package.json index 7ef6c897ac..a467c52f3c 100644 --- a/tests/deprecated-tsconfig/package.json +++ b/tests/deprecated-tsconfig/package.json @@ -4,7 +4,7 @@ "__TS_CONFIG__": "tsconfig.json" }, "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "coverageReporters": [ diff --git a/tests/dynamic-imports/jest.allowdefaultimports.json b/tests/dynamic-imports/jest.allowdefaultimports.json index 6916ba629d..91f4164974 100644 --- a/tests/dynamic-imports/jest.allowdefaultimports.json +++ b/tests/dynamic-imports/jest.allowdefaultimports.json @@ -6,7 +6,7 @@ } }, "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ diff --git a/tests/dynamic-imports/package.json b/tests/dynamic-imports/package.json index d3d2dda0e5..da4ca2764d 100644 --- a/tests/dynamic-imports/package.json +++ b/tests/dynamic-imports/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ diff --git a/tests/hoist-errors/package.json b/tests/hoist-errors/package.json index f5eead7638..d2d426d10d 100644 --- a/tests/hoist-errors/package.json +++ b/tests/hoist-errors/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "coverageReporters": [ diff --git a/tests/hoist-test/package.json b/tests/hoist-test/package.json index 417a0f0199..da7414e70f 100644 --- a/tests/hoist-test/package.json +++ b/tests/hoist-test/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.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 86dcdbcfe3..be12d7069a 100644 --- a/tests/imports-test/package.json +++ b/tests/imports-test/package.json @@ -1,9 +1,12 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, - "moduleDirectories": ["node_modules", "src"], + "moduleDirectories": [ + "node_modules", + "src" + ], "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", diff --git a/tests/no-json-module-file-ext/__tests__/transpile-me.test.ts b/tests/no-json-module-file-ext/__tests__/transpile-me.test.ts new file mode 100644 index 0000000000..4fb1464536 --- /dev/null +++ b/tests/no-json-module-file-ext/__tests__/transpile-me.test.ts @@ -0,0 +1 @@ +test('no json in moduleFileExtensions', () => {}); diff --git a/tests/no-json-module-file-ext/package.json b/tests/no-json-module-file-ext/package.json new file mode 100644 index 0000000000..57c0c175ba --- /dev/null +++ b/tests/no-json-module-file-ext/package.json @@ -0,0 +1,19 @@ +{ + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "moduleDirectories": [ + "node_modules", + "src" + ], + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "the.important.thing.is.that.json.is.missing.here" + ] + } +} diff --git a/tests/no-json-module-file-ext/tsconfig.json b/tests/no-json-module-file-ext/tsconfig.json new file mode 100644 index 0000000000..6a8b14571b --- /dev/null +++ b/tests/no-json-module-file-ext/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "moduleResolution": "node", + "noEmitOnError": false, + "jsx": "react", + "allowJs": true, + "baseUrl": "src" + } +} \ No newline at end of file diff --git a/tests/no-synthetic-default/package.json b/tests/no-synthetic-default/package.json index 417a0f0199..da7414e70f 100644 --- a/tests/no-synthetic-default/package.json +++ b/tests/no-synthetic-default/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.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 6e385a394c..cca7acd1d2 100644 --- a/tests/simple-async/package.json +++ b/tests/simple-async/package.json @@ -2,7 +2,7 @@ "jest": { "rootDir": "./", "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.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 ad247e9580..0b4b74c76f 100644 --- a/tests/simple-long-path/package.json +++ b/tests/simple-long-path/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "coverageReporters": [ diff --git a/tests/simple/package.json b/tests/simple/package.json index 4b10ef648c..9529a0f3ab 100644 --- a/tests/simple/package.json +++ b/tests/simple/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "coverageReporters": [ diff --git a/tests/skip-babelrc/package.json b/tests/skip-babelrc/package.json index f5eead7638..d2d426d10d 100644 --- a/tests/skip-babelrc/package.json +++ b/tests/skip-babelrc/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "coverageReporters": [ diff --git a/tests/synthetic-default/package.json b/tests/synthetic-default/package.json index 5ec1bfb8d9..eee0ad2384 100644 --- a/tests/synthetic-default/package.json +++ b/tests/synthetic-default/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "moduleDirectories": [ "node_modules", diff --git a/tests/use-babelrc/package.json b/tests/use-babelrc/package.json index eca1887afd..df8c03a58a 100644 --- a/tests/use-babelrc/package.json +++ b/tests/use-babelrc/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "moduleDirectories": [ "node_modules", diff --git a/tests/use-strict/package.json b/tests/use-strict/package.json index a0b913d1a6..4d13cfeca8 100644 --- a/tests/use-strict/package.json +++ b/tests/use-strict/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "mapCoverage": true, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", diff --git a/tests/watch-test/package.json b/tests/watch-test/package.json index ae6d82a9ef..b3bdfd5346 100644 --- a/tests/watch-test/package.json +++ b/tests/watch-test/package.json @@ -1,7 +1,7 @@ { "jest": { "transform": { - "^.+\\.tsx?$": "../../preprocessor.js" + "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" }, "mapCoverage": true, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", diff --git a/yarn.lock b/yarn.lock index 3856c04b10..2942c79193 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1404,7 +1404,7 @@ from@~0: version "0.1.7" resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" -fs-extra@^4.0.0: +fs-extra@^4.0.0, fs-extra@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.2.tgz#f91704c53d1b461f893452b0c307d9997647ab6b" dependencies: @@ -2279,7 +2279,7 @@ levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -lint-staged@5.0.0: +lint-staged@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-5.0.0.tgz#f1c670e03e2fdf3f3d0eb81f72d3bcf658770e54" dependencies: From 4346702afd80fcbd95cd2b83adecd09b70eb19ff Mon Sep 17 00:00:00 2001 From: Martijn The Date: Sun, 12 Nov 2017 20:00:01 +0100 Subject: [PATCH 3/5] Bump version patch to 21.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d25431aab6..ab2aaf9909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-jest", - "version": "21.2.2", + "version": "21.2.3", "main": "index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", From f17bf817c6b6800d23f5b8b9a93e42b154444ee5 Mon Sep 17 00:00:00 2001 From: Martijn The Date: Mon, 13 Nov 2017 10:50:52 +0100 Subject: [PATCH 4/5] - Address code review from @kulshekhar: -- Add missing getCacheKey() to the ts-jest module interface -- Fix missing newlines at end of tsconfig.json - Add integration test case to test the interface of the ts-jest module - Add missing index.d.ts, this no longer gets generated automatically because there is no longer a index.ts --- index.d.ts | 11 ++++++++++ index.js | 21 ++++++++++++------- package.json | 2 +- .../ts-jest-module-interface.spec.ts | 8 +++++++ tests/imports-test/tsconfig.json | 2 +- tests/no-json-module-file-ext/tsconfig.json | 2 +- .../ts-jest-module-interface.test.ts | 16 ++++++++++++++ tests/ts-jest-module-interface/package.json | 19 +++++++++++++++++ tests/ts-jest-module-interface/tsconfig.json | 11 ++++++++++ 9 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 index.d.ts create mode 100644 tests/__tests__/ts-jest-module-interface.spec.ts create mode 100644 tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts create mode 100644 tests/ts-jest-module-interface/package.json create mode 100644 tests/ts-jest-module-interface/tsconfig.json diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000000..206d91423f --- /dev/null +++ b/index.d.ts @@ -0,0 +1,11 @@ +import * as _install from './install'; +import * as preprocessor from './preprocessor'; + +interface TsJestModule { + install: typeof _install.install; + process: typeof preprocessor.process; + getCacheKey: typeof preprocessor.getCacheKey; +} + +declare const tsJestModule: TsJestModule; +export = tsJestModule; diff --git a/index.js b/index.js index 278fa174c5..2e02965210 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,16 @@ +// Avoid require()'ing the preprocessor when index.js gets loaded as part +// of the transpiled test file output, to avoid tripping this bug in +// babel-core: /~https://github.com/babel/babel/pull/6524 which is to be +// fixed in babel-core 7.0. +// Related ts-jest issue: /~https://github.com/kulshekhar/ts-jest/issues/367 +function lazyRequire(fnName) { + return function() { + return require('./dist/preprocessor')[fnName].apply(null, arguments); + }; +} + module.exports = { - process: function() { - // Avoid require()'ing the preprocessor when index.js gets loaded as part - // of the transpiled test file output, to avoid tripping this bug in - // babel-core: /~https://github.com/babel/babel/pull/6524 which is to be - // fixed in babel-core 7.0. - // Related ts-jest issue: /~https://github.com/kulshekhar/ts-jest/issues/367 - return require('./dist/preprocessor').process.apply(null, arguments); - }, + process: lazyRequire('process'), + getCacheKey: lazyRequire('getCacheKey'), install: require('./dist/install').install, }; diff --git a/package.json b/package.json index ab2aaf9909..04e13bc020 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { - "build": "tsc -p .", + "build": "cp index.d.ts dist/ && tsc -p .", "build:watch": "tsc -p . -w", "clean": "rimraf dist/**/* && rimraf tests/simple/coverage && rimraf tests/simple-async/coverage", "clean-build": "npm run clean && npm run build", diff --git a/tests/__tests__/ts-jest-module-interface.spec.ts b/tests/__tests__/ts-jest-module-interface.spec.ts new file mode 100644 index 0000000000..724dd0fe4f --- /dev/null +++ b/tests/__tests__/ts-jest-module-interface.spec.ts @@ -0,0 +1,8 @@ +import runJest from '../__helpers__/runJest'; + +describe('ts-jest module interface', () => { + it('should run successfully', () => { + const result = runJest('../ts-jest-module-interface', ['--no-cache']); + expect(result.status).toBe(0); + }); +}); diff --git a/tests/imports-test/tsconfig.json b/tests/imports-test/tsconfig.json index 6a8b14571b..5319633fc9 100644 --- a/tests/imports-test/tsconfig.json +++ b/tests/imports-test/tsconfig.json @@ -8,4 +8,4 @@ "allowJs": true, "baseUrl": "src" } -} \ No newline at end of file +} diff --git a/tests/no-json-module-file-ext/tsconfig.json b/tests/no-json-module-file-ext/tsconfig.json index 6a8b14571b..5319633fc9 100644 --- a/tests/no-json-module-file-ext/tsconfig.json +++ b/tests/no-json-module-file-ext/tsconfig.json @@ -8,4 +8,4 @@ "allowJs": true, "baseUrl": "src" } -} \ No newline at end of file +} 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 new file mode 100644 index 0000000000..3b9e80d7dc --- /dev/null +++ b/tests/ts-jest-module-interface/__tests__/ts-jest-module-interface.test.ts @@ -0,0 +1,16 @@ +import * as tsJest from 'ts-jest'; + +describe('ts-jest module interface', () => { + it('is an object', () => { + expect(typeof tsJest).toBe('object'); + }); + it('has a process function', () => { + expect(typeof tsJest.process).toBe('function'); + }); + it('has an install function', () => { + expect(typeof tsJest.install).toBe('function'); + }); + it('has a getCacheKey function', () => { + expect(typeof tsJest.getCacheKey).toBe('function'); + }); +}); diff --git a/tests/ts-jest-module-interface/package.json b/tests/ts-jest-module-interface/package.json new file mode 100644 index 0000000000..0ea5fdee34 --- /dev/null +++ b/tests/ts-jest-module-interface/package.json @@ -0,0 +1,19 @@ +{ + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "moduleDirectories": [ + "node_modules", + "src" + ], + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ] + } +} diff --git a/tests/ts-jest-module-interface/tsconfig.json b/tests/ts-jest-module-interface/tsconfig.json new file mode 100644 index 0000000000..5319633fc9 --- /dev/null +++ b/tests/ts-jest-module-interface/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES5", + "module": "commonjs", + "moduleResolution": "node", + "noEmitOnError": false, + "jsx": "react", + "allowJs": true, + "baseUrl": "src" + } +} From 91a1f0e8997c13314e200d78194a259b0785dc0f Mon Sep 17 00:00:00 2001 From: Martijn The Date: Tue, 14 Nov 2017 09:36:56 +0100 Subject: [PATCH 5/5] Use cpx because 1) need to create dist/ folder 2) Windows support --- package.json | 5 +- yarn.lock | 128 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 04e13bc020..3a7171145a 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { - "build": "cp index.d.ts dist/ && tsc -p .", - "build:watch": "tsc -p . -w", + "build": "cpx index.d.ts dist/ && tsc -p .", + "build:watch": "cpx index.d.ts dist/ && tsc -p . -w", "clean": "rimraf dist/**/* && rimraf tests/simple/coverage && rimraf tests/simple-async/coverage", "clean-build": "npm run clean && npm run build", "pretest": "npm run tslint && npm run clean-build", @@ -70,6 +70,7 @@ "babel-plugin-istanbul": "^4.1.4", "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1", "babel-preset-jest": "^21.2.0", + "cpx": "^1.5.0", "fs-extra": "^4.0.2", "jest-config": "^21.2.1", "jest-util": "^21.2.1", diff --git a/yarn.lock b/yarn.lock index 2942c79193..75591c1b51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -199,6 +199,18 @@ array-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" +array-filter@~0.0.0: + version "0.0.1" + resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-0.0.1.tgz#7da8cf2e26628ed732803581fd21f67cacd2eeec" + +array-map@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/array-map/-/array-map-0.0.0.tgz#88a2bab73d1cf7bcd5c1b118a003f66f665fa662" + +array-reduce@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b" + array-unique@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" @@ -227,6 +239,10 @@ astral-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" +async-each@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" + async@^1.4.0: version "1.5.2" resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" @@ -697,7 +713,7 @@ babel-register@^6.26.0: mkdirp "^0.5.1" source-map-support "^0.4.15" -babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: +babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0, babel-runtime@^6.9.2: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" dependencies: @@ -755,6 +771,10 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +binary-extensions@^1.0.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.10.0.tgz#9aeb9a6c5e88638aad171e167f5900abe24835d0" + block-stream@*: version "0.0.9" resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" @@ -886,6 +906,21 @@ character-reference-invalid@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/character-reference-invalid/-/character-reference-invalid-1.1.1.tgz#942835f750e4ec61a308e60c2ef8cc1011202efc" +chokidar@^1.6.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468" + dependencies: + anymatch "^1.3.0" + async-each "^1.0.0" + glob-parent "^2.0.0" + inherits "^2.0.1" + is-binary-path "^1.0.0" + is-glob "^2.0.0" + path-is-absolute "^1.0.0" + readdirp "^2.0.0" + optionalDependencies: + fsevents "^1.0.0" + ci-info@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.1.tgz#47b44df118c48d2597b56d342e7e25791060171a" @@ -996,6 +1031,22 @@ cosmiconfig@^3.1.0: parse-json "^3.0.0" require-from-string "^2.0.1" +cpx@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/cpx/-/cpx-1.5.0.tgz#185be018511d87270dedccc293171e37655ab88f" + dependencies: + babel-runtime "^6.9.2" + chokidar "^1.6.0" + duplexer "^0.1.1" + glob "^7.0.5" + glob2base "^0.0.12" + minimatch "^3.0.2" + mkdirp "^0.5.1" + resolve "^1.1.7" + safe-buffer "^5.0.1" + shell-quote "^1.6.1" + subarg "^1.0.0" + cross-spawn-with-kill@latest: version "1.0.0" resolved "https://registry.yarnpkg.com/cross-spawn-with-kill/-/cross-spawn-with-kill-1.0.0.tgz#6d76b7bbfd148eb10bd0322fceb180ea9b0477a8" @@ -1092,6 +1143,10 @@ detect-indent@^4.0.0: dependencies: repeating "^2.0.0" +detect-libc@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.2.tgz#71ad5d204bf17a6a6ca8f450c61454066ef461e1" + diff@^3.0.1, diff@^3.2.0: version "3.3.1" resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.1.tgz#aa8567a6eed03c531fc89d3f711cd0e5259dec75" @@ -1135,7 +1190,7 @@ domutils@^1.5.1: dom-serializer "0" domelementtype "1" -duplexer@~0.1.1: +duplexer@^0.1.1, duplexer@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1" @@ -1347,6 +1402,10 @@ fill-range@^2.1.0: repeat-element "^1.1.2" repeat-string "^1.5.2" +find-index@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/find-index/-/find-index-0.1.1.tgz#675d358b2ca3892d795a1ab47232f8b6e2e0dde4" + find-parent-dir@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54" @@ -1416,6 +1475,13 @@ fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" +fsevents@^1.0.0: + version "1.1.3" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.1.3.tgz#11f82318f5fe7bb2cd22965a108e9306208216d8" + dependencies: + nan "^2.3.0" + node-pre-gyp "^0.6.39" + fsevents@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.1.2.tgz#3282b713fb3ad80ede0e9fcf4611b5aa6fc033f4" @@ -1488,6 +1554,12 @@ glob-parent@^2.0.0: dependencies: is-glob "^2.0.0" +glob2base@^0.0.12: + version "0.0.12" + resolved "https://registry.yarnpkg.com/glob2base/-/glob2base-0.0.12.tgz#9d419b3e28f12e83a362164a277055922c9c0d56" + dependencies: + find-index "^0.1.1" + glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" @@ -1717,6 +1789,12 @@ is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" +is-binary-path@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" + dependencies: + binary-extensions "^1.0.0" + is-buffer@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" @@ -2496,7 +2574,7 @@ minimist@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" -minimist@^1.1.1, minimist@^1.2.0, minimist@~1.2.0: +minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0, minimist@~1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" @@ -2557,6 +2635,22 @@ node-pre-gyp@^0.6.36: tar "^2.2.1" tar-pack "^3.4.0" +node-pre-gyp@^0.6.39: + version "0.6.39" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.39.tgz#c00e96860b23c0e1420ac7befc5044e1d78d8649" + dependencies: + detect-libc "^1.0.2" + hawk "3.1.3" + mkdirp "^0.5.1" + nopt "^4.0.1" + npmlog "^4.0.2" + rc "^1.1.7" + request "2.81.0" + rimraf "^2.6.1" + semver "^5.3.0" + tar "^2.2.1" + tar-pack "^3.4.0" + nopt@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d" @@ -2972,6 +3066,15 @@ readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4: string_decoder "~1.0.3" util-deprecate "~1.0.1" +readdirp@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.1.0.tgz#4ed0ad060df3073300c48440373f72d1cc642d78" + dependencies: + graceful-fs "^4.1.2" + minimatch "^3.0.2" + readable-stream "^2.0.2" + set-immediate-shim "^1.0.1" + regenerate@^1.2.1: version "1.3.3" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f" @@ -3196,6 +3299,10 @@ set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" +set-immediate-shim@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61" + setimmediate@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" @@ -3210,6 +3317,15 @@ shebang-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" +shell-quote@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767" + dependencies: + array-filter "~0.0.0" + array-map "~0.0.0" + array-reduce "~0.0.0" + jsonify "~0.0.0" + shellwords@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" @@ -3417,6 +3533,12 @@ structured-source@^3.0.2: dependencies: boundary "^1.0.1" +subarg@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" + dependencies: + minimist "^1.1.0" + supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"