From 43a31c806ee137a67f89e19bab629a9a26fc0aaf Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 02:40:15 +0200 Subject: [PATCH 01/21] removes circular dependency --- package.json | 1 - yarn.lock | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/package.json b/package.json index 0b38195825..5c5526ce19 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,6 @@ "react-test-renderer": "16.4.1", "reflect-metadata": "^0.1.12", "rimraf": "^2.6.2", - "ts-jest": "23.0.0", "tslint": "^5.10.0", "typescript": "^2.8.3" }, diff --git a/yarn.lock b/yarn.lock index 77725367eb..048c726969 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4592,19 +4592,6 @@ trough@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.1.tgz#a9fd8b0394b0ae8fff82e0633a0a36ccad5b5f86" -ts-jest@23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-23.0.0.tgz#3216310fb51e40789c6e4aa20bfe80198d250e9b" - dependencies: - babel-plugin-istanbul "^4.1.6" - babel-preset-jest "^23.0.0" - cpx "^1.5.0" - fs-extra "6.0.1" - jest-config "^23.0.0" - lodash "^4.17.10" - pkg-dir "^3.0.0" - yargs "^12.0.1" - tslib@^1.8.0, tslib@^1.8.1: version "1.9.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" From 081ffe4a4b464d14a6b9dbe4bf286183b40eff6e Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 07:49:25 +0200 Subject: [PATCH 02/21] style: removes unused imports --- src/transpiler.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/transpiler.ts b/src/transpiler.ts index e6b1247d5f..06ce887b2b 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -1,8 +1,6 @@ -import * as fs from 'fs'; -import { cwd } from 'process'; import * as ts from 'typescript'; import { logOnce } from './logger'; -import { CodeSourceMapPair, TsJestConfig } from './jest-types'; +import { CodeSourceMapPair } from './jest-types'; // Takes the typescript code and by whatever method configured, makes it into javascript code. export function transpileTypescript( @@ -35,7 +33,7 @@ function transpileViaTranspileModule( fileName: filePath, reportDiagnostics: true, }); - const {diagnostics} = transpileOutput; + const { diagnostics } = transpileOutput; if (diagnostics.length > 0) { const errors = formatDiagnostics(diagnostics); @@ -53,9 +51,9 @@ function formatDiagnostics(diagnostics: ts.Diagnostic[]): string { } function createTranspilationError(errors: string): Error { - return Error( - `TypeScript compiler encountered syntax errors while transpiling. Errors: ${errors}`, - ); + return Error( + `TypeScript compiler encountered syntax errors while transpiling. Errors: ${errors}`, + ); } function logMessageForTranspilationErrors(errors: string): string { From a9462eb12e3062a2ac33d3affc8b9a932e6c05ba Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 07:52:46 +0200 Subject: [PATCH 03/21] build: removes some dependencies + upd. jest-config babel-plugin-istanbul and and babel-preset-jest are automatically added by babel-jest, plus we want to allow the user to use their own provided version --- package.json | 6 +- yarn.lock | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 184 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5c5526ce19..11fce508fd 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,9 @@ ] }, "dependencies": { - "babel-plugin-istanbul": "^4.1.6", - "babel-preset-jest": "^23.0.0", "cpx": "^1.5.0", "fs-extra": "6.0.1", - "jest-config": "^23.0.0", + "jest-config": "^23.4.1", "lodash": "^4.17.10", "pkg-dir": "^3.0.0", "yargs": "^12.0.1" @@ -86,7 +84,9 @@ "@types/react": "16.4.6", "@types/yargs": "^11.0.0", "babel-core": "^6.26.3", + "babel-plugin-istanbul": "^4.1.6", "babel-preset-env": "^1.7.0", + "babel-preset-jest": "^23.0.0", "cross-spawn": "latest", "cross-spawn-with-kill": "latest", "doctoc": "latest", diff --git a/yarn.lock b/yarn.lock index 048c726969..0e775cb890 100644 --- a/yarn.lock +++ b/yarn.lock @@ -507,6 +507,13 @@ babel-jest@^23.0.0: babel-plugin-istanbul "^4.1.6" babel-preset-jest "^23.0.0" +babel-jest@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.4.0.tgz#22c34c392e2176f6a4c367992a7fcff69d2e8557" + dependencies: + babel-plugin-istanbul "^4.1.6" + babel-preset-jest "^23.2.0" + babel-messages@^6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" @@ -532,6 +539,10 @@ babel-plugin-jest-hoist@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.0.0.tgz#e61e68799f743391a1e6306ee270477aacf946c8" +babel-plugin-jest-hoist@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.2.0.tgz#e61fae05a1ca8801aadee57a6d66b8cefaf44167" + babel-plugin-syntax-async-functions@^6.8.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" @@ -787,6 +798,13 @@ babel-preset-jest@^23.0.0: babel-plugin-jest-hoist "^23.0.0" babel-plugin-syntax-object-rest-spread "^6.13.0" +babel-preset-jest@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-23.2.0.tgz#8ec7a03a138f001a1a8fb1e8113652bf1a55da46" + dependencies: + babel-plugin-jest-hoist "^23.2.0" + babel-plugin-syntax-object-rest-spread "^6.13.0" + babel-register@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071" @@ -816,7 +834,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0: babylon "^6.18.0" lodash "^4.17.4" -babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: +babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" dependencies: @@ -830,7 +848,7 @@ babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: invariant "^2.2.2" lodash "^4.17.4" -babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: +babel-types@^6.0.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" dependencies: @@ -943,6 +961,12 @@ browser-resolve@^1.11.2: dependencies: resolve "1.1.7" +browser-resolve@^1.11.3: + version "1.11.3" + resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.3.tgz#9b7cbb3d0f510e4cb86bdbd796124d28b5890af6" + dependencies: + resolve "1.1.7" + browserslist@^3.2.6: version "3.2.8" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" @@ -1617,6 +1641,17 @@ expect@^23.0.0: jest-message-util "^23.0.0" jest-regex-util "^23.0.0" +expect@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/expect/-/expect-23.4.0.tgz#6da4ecc99c1471253e7288338983ad1ebadb60c3" + dependencies: + ansi-styles "^3.2.0" + jest-diff "^23.2.0" + jest-get-type "^22.1.0" + jest-matcher-utils "^23.2.0" + jest-message-util "^23.4.0" + jest-regex-util "^23.3.0" + extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -2536,6 +2571,24 @@ jest-config@^23.0.0: jest-validate "^23.0.0" pretty-format "^23.0.0" +jest-config@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.4.1.tgz#3172fa21f0507d7f8a088ed1dbe4157057f201e9" + dependencies: + babel-core "^6.0.0" + babel-jest "^23.4.0" + chalk "^2.0.1" + glob "^7.1.1" + jest-environment-jsdom "^23.4.0" + jest-environment-node "^23.4.0" + jest-get-type "^22.1.0" + jest-jasmine2 "^23.4.1" + jest-regex-util "^23.3.0" + jest-resolve "^23.4.1" + jest-util "^23.4.0" + jest-validate "^23.4.0" + pretty-format "^23.2.0" + jest-diff@^22.4.0: version "22.4.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-22.4.0.tgz#384c2b78519ca44ca126382df53f134289232525" @@ -2554,12 +2607,28 @@ jest-diff@^23.0.0: jest-get-type "^22.1.0" pretty-format "^23.0.0" +jest-diff@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.2.0.tgz#9f2cf4b51e12c791550200abc16b47130af1062a" + dependencies: + chalk "^2.0.1" + diff "^3.2.0" + jest-get-type "^22.1.0" + pretty-format "^23.2.0" + jest-docblock@^22.4.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-22.4.3.tgz#50886f132b42b280c903c592373bb6e93bb68b19" dependencies: detect-newline "^2.1.0" +jest-each@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-each/-/jest-each-23.4.0.tgz#2fa9edd89daa1a4edc9ff9bf6062a36b71345143" + dependencies: + chalk "^2.0.1" + pretty-format "^23.2.0" + jest-environment-jsdom@^22.4.1: version "22.4.1" resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-22.4.1.tgz#754f408872441740100d3917e5ec40c74de6447f" @@ -2576,6 +2645,14 @@ jest-environment-jsdom@^23.0.0: jest-util "^23.0.0" jsdom "^11.5.1" +jest-environment-jsdom@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-23.4.0.tgz#056a7952b3fea513ac62a140a2c368c79d9e6023" + dependencies: + jest-mock "^23.2.0" + jest-util "^23.4.0" + jsdom "^11.5.1" + jest-environment-node@^22.4.1: version "22.4.1" resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-22.4.1.tgz#418850eb654596b8d6e36c2021cbedbc23df8e16" @@ -2590,6 +2667,13 @@ jest-environment-node@^23.0.0: jest-mock "^23.0.0" jest-util "^23.0.0" +jest-environment-node@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-23.4.0.tgz#57e80ed0841dea303167cce8cd79521debafde10" + dependencies: + jest-mock "^23.2.0" + jest-util "^23.4.0" + jest-get-type@^22.1.0: version "22.1.0" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.1.0.tgz#4e90af298ed6181edc85d2da500dbd2753e0d5a9" @@ -2637,6 +2721,22 @@ jest-jasmine2@^23.0.0: jest-util "^23.0.0" pretty-format "^23.0.0" +jest-jasmine2@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-23.4.1.tgz#fa192262430d418e827636e4a98423e5e7ff0fce" + dependencies: + chalk "^2.0.1" + co "^4.6.0" + expect "^23.4.0" + is-generator-fn "^1.0.0" + jest-diff "^23.2.0" + jest-each "^23.4.0" + jest-matcher-utils "^23.2.0" + jest-message-util "^23.4.0" + jest-snapshot "^23.4.1" + jest-util "^23.4.0" + pretty-format "^23.2.0" + jest-leak-detector@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-23.0.0.tgz#ec93d755b21e8b2c4c4e59b8cccab1805a704ab3" @@ -2659,6 +2759,14 @@ jest-matcher-utils@^23.0.0: jest-get-type "^22.1.0" pretty-format "^23.0.0" +jest-matcher-utils@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.2.0.tgz#4d4981f23213e939e3cedf23dc34c747b5ae1913" + dependencies: + chalk "^2.0.1" + jest-get-type "^22.1.0" + pretty-format "^23.2.0" + jest-message-util@^22.4.0: version "22.4.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-22.4.0.tgz#e3d861df16d2fee60cb2bc8feac2188a42579642" @@ -2679,6 +2787,16 @@ jest-message-util@^23.0.0: slash "^1.0.0" stack-utils "^1.0.1" +jest-message-util@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.4.0.tgz#17610c50942349508d01a3d1e0bda2c079086a9f" + dependencies: + "@babel/code-frame" "^7.0.0-beta.35" + chalk "^2.0.1" + micromatch "^2.3.11" + slash "^1.0.0" + stack-utils "^1.0.1" + jest-mock@^22.2.0: version "22.2.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-22.2.0.tgz#444b3f9488a7473adae09bc8a77294afded397a7" @@ -2687,6 +2805,10 @@ jest-mock@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.0.0.tgz#d9d897a1b74dc05c66a737213931496215897dd8" +jest-mock@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.2.0.tgz#ad1c60f29e8719d47c26e1138098b6d18b261134" + jest-regex-util@^22.1.0: version "22.1.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-22.1.0.tgz#5daf2fe270074b6da63e5d85f1c9acc866768f53" @@ -2695,6 +2817,10 @@ jest-regex-util@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.0.0.tgz#dd5c1fde0c46f4371314cf10f7a751a23f4e8f76" +jest-regex-util@^23.3.0: + version "23.3.0" + resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.3.0.tgz#5f86729547c2785c4002ceaa8f849fe8ca471bc5" + jest-resolve-dependencies@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-23.0.0.tgz#c3e1cfee0e543dee10e6ec0628df69cd239244c9" @@ -2717,6 +2843,14 @@ jest-resolve@^23.0.0: chalk "^2.0.1" realpath-native "^1.0.0" +jest-resolve@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-23.4.1.tgz#7f3c17104732a2c0c940a01256025ed745814982" + dependencies: + browser-resolve "^1.11.3" + chalk "^2.0.1" + realpath-native "^1.0.0" + jest-runner@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-23.0.0.tgz#b198a2dd78d57a2c0f3f8d7c7f97b62673922020" @@ -2787,6 +2921,22 @@ jest-snapshot@^23.0.0: natural-compare "^1.4.0" pretty-format "^23.0.0" +jest-snapshot@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.4.1.tgz#090de9acae927f6a3af3005bda40d912b83e9c96" + dependencies: + babel-traverse "^6.0.0" + babel-types "^6.0.0" + chalk "^2.0.1" + jest-diff "^23.2.0" + jest-matcher-utils "^23.2.0" + jest-message-util "^23.4.0" + jest-resolve "^23.4.1" + mkdirp "^0.5.1" + natural-compare "^1.4.0" + pretty-format "^23.2.0" + semver "^5.5.0" + jest-util@^22.4.1: version "22.4.1" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-22.4.1.tgz#dd17c3bdb067f8e90591563ec0c42bf847dc249f" @@ -2811,6 +2961,19 @@ jest-util@^23.0.0: mkdirp "^0.5.1" source-map "^0.6.0" +jest-util@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-23.4.0.tgz#4d063cb927baf0a23831ff61bec2cbbf49793561" + dependencies: + callsites "^2.0.0" + chalk "^2.0.1" + graceful-fs "^4.1.11" + is-ci "^1.0.10" + jest-message-util "^23.4.0" + mkdirp "^0.5.1" + slash "^1.0.0" + source-map "^0.6.0" + jest-validate@^22.4.0, jest-validate@^22.4.2: version "22.4.2" resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-22.4.2.tgz#e789a4e056173bf97fe797a2df2d52105c57d4f4" @@ -2830,6 +2993,15 @@ jest-validate@^23.0.0: leven "^2.1.0" pretty-format "^23.0.0" +jest-validate@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.4.0.tgz#d96eede01ef03ac909c009e9c8e455197d48c201" + dependencies: + chalk "^2.0.1" + jest-get-type "^22.1.0" + leven "^2.1.0" + pretty-format "^23.2.0" + jest-worker@^23.0.0: version "23.0.0" resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-23.0.0.tgz#e6b1378b81f8e6a108f3be33a1faa830c22ea450" @@ -3709,6 +3881,13 @@ pretty-format@^23.0.0: ansi-regex "^3.0.0" ansi-styles "^3.2.0" +pretty-format@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.2.0.tgz#3b0aaa63c018a53583373c1cb3a5d96cc5e83017" + dependencies: + ansi-regex "^3.0.0" + ansi-styles "^3.2.0" + private@^0.1.6, private@^0.1.7, private@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" From 67516963e2b8fffaf9acec1830c20b300ac88e40 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 09:02:52 +0200 Subject: [PATCH 04/21] build: updgrade babel and related dependencies --- README.md | 2 +- index.js | 2 +- package.json | 14 +- src/jest-types.ts | 68 +- src/postprocess.ts | 5 +- tests/__tests__/babel-config.spec.ts | 4 +- tests/__tests__/babelrc.spec.ts | 2 +- .../disable-sourcemap-support.spec.ts | 3 +- tests/__tests__/import.spec.ts | 1 - tests/__tests__/postprocess.spec.ts | 8 +- .../package.json | 2 +- .../package.json | 2 +- tsconfig.json | 15 +- yarn.lock | 1343 +++++++++-------- 14 files changed, 734 insertions(+), 737 deletions(-) diff --git a/README.md b/README.md index 8981c68b4a..3972142522 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ In some cases, projects may not want to have a `.babelrc` file, but still need t "globals": { "ts-jest": { "babelConfig": { - "presets": ["env"] + "presets": ["@babel/env"] } } } diff --git a/index.js b/index.js index 561337af94..13ad594168 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,6 @@ function lazyRequire(fnName) { } module.exports = { - process: lazyRequire('process'), getCacheKey: lazyRequire('getCacheKey'), + process: lazyRequire('process'), }; diff --git a/package.json b/package.json index 11fce508fd..0baed44d32 100644 --- a/package.json +++ b/package.json @@ -70,28 +70,28 @@ "yargs": "^12.0.1" }, "peerDependencies": { - "babel-core": "^6.26.3 || ^7.0.0-0", + "babel-core": "^7.0.0-0", "jest": "^23.0.0 || ^24.0.0", "typescript": "2.x" }, "devDependencies": { - "@types/babel-core": "latest", + "@babel/core": "^7.0.0-beta.54", + "@babel/preset-env": "^7.0.0-beta.54", + "@types/babel-core": "^6.25.5", "@types/es6-shim": "0.31.37", "@types/fs-extra": "5.0.4", - "@types/jest": "^23.1.0", + "@types/jest": "^23.3.0", "@types/lodash": "^4.14.109", "@types/node": "10.5.2", "@types/react": "16.4.6", "@types/yargs": "^11.0.0", - "babel-core": "^6.26.3", "babel-plugin-istanbul": "^4.1.6", - "babel-preset-env": "^1.7.0", - "babel-preset-jest": "^23.0.0", + "babel-preset-jest": "^23.2.0", "cross-spawn": "latest", "cross-spawn-with-kill": "latest", "doctoc": "latest", "husky": "^0.14.3", - "jest": "^23.0.0", + "jest": "^23.4.1", "lint-staged": "^7.1.2", "prettier": "^1.12.1", "react": "16.4.1", diff --git a/src/jest-types.ts b/src/jest-types.ts index 350c75d311..f3ff30693d 100644 --- a/src/jest-types.ts +++ b/src/jest-types.ts @@ -30,74 +30,28 @@ export type PostProcessHook = ( transformOptions: TransformOptions, ) => CodeSourceMapPair; -export type JestConfig = Partial; - -export interface FullJestProjectConfig { - automock: boolean; - browser: boolean; - cache: boolean; - cacheDirectory: Path; - clearMocks: boolean; - coveragePathIgnorePatterns: string[]; - cwd: Path; - detectLeaks: boolean; - detectOpenHandles: boolean; - displayName: string | null; - errorOnDeprecated: boolean; - filter: Path | null; - forceCoverageMatch: Glob[]; - globals: ConfigGlobals; - haste: HasteConfig; - moduleDirectories: string[]; - moduleFileExtensions: string[]; - moduleLoader: Path; - moduleNameMapper: Array<[string, string]>; - modulePathIgnorePatterns: string[]; - modulePaths: string[]; - name: string; - resetMocks: boolean; - resetModules: boolean; - resolver: Path | null; - restoreMocks: boolean; - rootDir: Path; - roots: Path[]; - runner: string; - setupFiles: Path[]; - setupTestFrameworkScriptFile: Path | null; - skipFilter: boolean; - skipNodeResolution: boolean; - snapshotSerializers: Path[]; - testEnvironment: string; - testEnvironmentOptions: object; - testLocationInResults: boolean; - testMatch: Glob[]; - testPathIgnorePatterns: string[]; - testRegex: string; - testRunner: string; - testURL: string; - timers: 'real' | 'fake'; - transform: Array<[string, Path]>; - transformIgnorePatterns: Glob[]; - watchPathIgnorePatterns: string[]; - unmockedModulePathPatterns: string[] | null; -} +export type JestConfig = jest.InitialOptions & { + globals?: jest.ConfigGlobals & { + __TRANSFORM_HTML__?: boolean; + }; +}; export interface TsJestConfig { - skipBabel?: boolean; - useBabelrc?: boolean; babelConfig?: BabelTransformOpts; - tsConfigFile?: string; + disableSourceMapSupport?: boolean; enableInternalCache?: boolean; enableTsDiagnostics?: boolean; - disableSourceMapSupport?: boolean; - ignoreCoverageForDecorators?: boolean; ignoreCoverageForAllDecorators?: boolean; + ignoreCoverageForDecorators?: boolean; + skipBabel?: boolean; + tsConfigFile?: string; + useBabelrc?: boolean; useExperimentalLanguageServer?: boolean; } export interface JestConfigNormalize { hasDeprecationWarnings: boolean; - options: FullJestProjectConfig; + options: jest.DefaultOptions; } export interface CodeSourceMapPair { diff --git a/src/postprocess.ts b/src/postprocess.ts index 181e99d220..b86e72d6cb 100644 --- a/src/postprocess.ts +++ b/src/postprocess.ts @@ -5,7 +5,6 @@ import * as __types__babel from 'babel-core'; import __types__istanbulPlugin from 'babel-plugin-istanbul'; import * as __types__jestPreset from 'babel-preset-jest'; -import * as ts from 'typescript'; let babel: typeof __types__babel; let istanbulPlugin: typeof __types__istanbulPlugin; let jestPreset: typeof __types__jestPreset; @@ -13,7 +12,7 @@ function importBabelDeps() { if (babel) { return; } - babel = require('babel-core'); + babel = require('@babel/core'); istanbulPlugin = require('babel-plugin-istanbul').default; jestPreset = require('babel-preset-jest'); } @@ -21,14 +20,12 @@ import { CompilerOptions } from 'typescript/lib/typescript'; import { BabelTransformOptions, CodeSourceMapPair, - FullJestProjectConfig, JestConfig, PostProcessHook, TransformOptions, TsJestConfig, } from './jest-types'; import { logOnce } from './logger'; -import { BabelFileResult } from 'babel-core'; // Function that takes the transpiled typescript and runs it through babel/whatever. export function postProcessCode( diff --git a/tests/__tests__/babel-config.spec.ts b/tests/__tests__/babel-config.spec.ts index 78ac240f5b..e77d1a0a57 100644 --- a/tests/__tests__/babel-config.spec.ts +++ b/tests/__tests__/babel-config.spec.ts @@ -10,7 +10,7 @@ describe('babelConfig flag', () => { const result = runJest('../babel-config-invalid', ['--no-cache', '-u']); const stderr = result.stderr; expect(result.status).toBe(1); - expect(stderr).toContain('ReferenceError: [BABEL]'); + expect(stderr).toContain('ReferenceError: Unknown option: .foo.'); expect(stderr).toContain( 'Check out http://babeljs.io/docs/usage/options/ for more information about options.', ); @@ -31,6 +31,6 @@ describe('babelConfig flag', () => { ]); const stderr = result.stderr; expect(result.status).toBe(1); - expect(stderr).toContain(`Couldn't find preset "nonexistent"`); + expect(stderr).toContain(`Cannot find module 'babel-preset-nonexistent'`); }); }); diff --git a/tests/__tests__/babelrc.spec.ts b/tests/__tests__/babelrc.spec.ts index 4767c4abf8..337143e7a7 100644 --- a/tests/__tests__/babelrc.spec.ts +++ b/tests/__tests__/babelrc.spec.ts @@ -5,7 +5,7 @@ describe('babelrc flag', () => { const result = runJest('../use-babelrc', ['--no-cache', '-u']); const stderr = result.stderr; expect(result.status).toBe(1); - expect(stderr).toContain('ReferenceError: [BABEL]'); + expect(stderr).toContain('ReferenceError: Unknown option: .foo.'); expect(stderr).toContain( 'Check out http://babeljs.io/docs/usage/options/ for more information about options.', ); diff --git a/tests/__tests__/disable-sourcemap-support.spec.ts b/tests/__tests__/disable-sourcemap-support.spec.ts index a0ac76438b..5594317fce 100644 --- a/tests/__tests__/disable-sourcemap-support.spec.ts +++ b/tests/__tests__/disable-sourcemap-support.spec.ts @@ -8,7 +8,8 @@ describe('Typescript errors', () => { const stderr = result.stderr; // The actual error is on line 18 - the line# being wrong here means sourcemaps are disabled. - expect(stderr).toContain('Hello.ts:8'); + expect(stderr).toMatch(/at .+Hello\.ts:\d+/); + expect(stderr).not.toContain('Hello.ts:18'); expectJestStatus(result, 1); }); }); diff --git a/tests/__tests__/import.spec.ts b/tests/__tests__/import.spec.ts index a1ab94b68d..85f9f83290 100644 --- a/tests/__tests__/import.spec.ts +++ b/tests/__tests__/import.spec.ts @@ -1,5 +1,4 @@ import runJest from '../__helpers__/runJest'; -import { printStdStreams } from '../utils/test-utils'; describe('import with relative and absolute paths', () => { it('should run successfully', () => { diff --git a/tests/__tests__/postprocess.spec.ts b/tests/__tests__/postprocess.spec.ts index 6fa0d77049..0f6df65189 100644 --- a/tests/__tests__/postprocess.spec.ts +++ b/tests/__tests__/postprocess.spec.ts @@ -1,4 +1,4 @@ -jest.mock('babel-core', () => { +jest.mock('@babel/core', () => { return { transform: jest.fn(() => { return { code: 'stubbed_code', map: 'stubbed_map' }; @@ -19,14 +19,14 @@ describe('postprocess', () => { } it('skips postprocess when skipBabel=true', () => { - const transformMock = require.requireMock('babel-core').transform; + const transformMock = require.requireMock('@babel/core').transform; runHook({}, {}, { skipBabel: true }); expect(transformMock).not.toBeCalled(); }); it('Adds no babel plugins by default', () => { - const transformMock = require.requireMock('babel-core').transform; + const transformMock = require.requireMock('@babel/core').transform; runHook(); getPostProcessHook({}, {}, {})( @@ -44,7 +44,7 @@ describe('postprocess', () => { }); it('doesn`t accumulate module transforms on consecutive calls', () => { - const transformMock = require.requireMock('babel-core').transform; + const transformMock = require.requireMock('@babel/core').transform; const tsJestConfig = { babelConfig: { plugins: ['some-plugin'], diff --git a/tests/babel-config-merge-ignore-babelrc/package.json b/tests/babel-config-merge-ignore-babelrc/package.json index cb81a5b885..2dd29123ba 100644 --- a/tests/babel-config-merge-ignore-babelrc/package.json +++ b/tests/babel-config-merge-ignore-babelrc/package.json @@ -18,7 +18,7 @@ "ts-jest": { "babelConfig": { "presets": [ - "env" + "@babel/env" ] } } diff --git a/tests/babel-config-merge-with-babelrc/package.json b/tests/babel-config-merge-with-babelrc/package.json index 9fc205d0bb..e740eb0fdb 100644 --- a/tests/babel-config-merge-with-babelrc/package.json +++ b/tests/babel-config-merge-with-babelrc/package.json @@ -18,7 +18,7 @@ "ts-jest": { "babelConfig": { "presets": [ - "env" + "@babel/env" ] }, "useBabelrc": true diff --git a/tsconfig.json b/tsconfig.json index 92f6d74376..d5b6e37db0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "sourceMap": false, "declaration": true, - "target": "ES5", + "target": "es5", "module": "commonjs", "moduleResolution": "node", "noEmitOnError": true, @@ -18,13 +18,10 @@ "allowSyntheticDefaultImports": false, "outDir": "dist", "rootDir": "src", - "skipLibCheck": true + "skipLibCheck": true, + "lib": ["es2015"], + "types": ["jest"] }, - "include": [ - "src/**/*.ts", - "src/**/*.tsx" - ], - "exclude": [ - "node_modules" - ] + "include": ["src/**/*.ts", "src/**/*.tsx"], + "exclude": ["node_modules"] } diff --git a/yarn.lock b/yarn.lock index 0e775cb890..2cdabcdd45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,12 @@ # yarn lockfile v1 +"@babel/code-frame@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.54.tgz#0024f96fdf7028a21d68e273afd4e953214a1ead" + dependencies: + "@babel/highlight" "7.0.0-beta.54" + "@babel/code-frame@^7.0.0-beta.35": version "7.0.0-beta.35" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.35.tgz#04eeb6dca7efef8f65776a4c214157303b85ad51" @@ -10,15 +16,514 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@babel/core@^7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.0.0-beta.54.tgz#253c54d0095403a5cfa764e7d9b458194692d02b" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/generator" "7.0.0-beta.54" + "@babel/helpers" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + convert-source-map "^1.1.0" + debug "^3.1.0" + json5 "^0.5.0" + lodash "^4.17.5" + resolve "^1.3.2" + semver "^5.4.1" + source-map "^0.5.0" + +"@babel/generator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.54.tgz#c043c7eebeebfd7e665d95c281a4aafc83d4e1c9" + dependencies: + "@babel/types" "7.0.0-beta.54" + jsesc "^2.5.1" + lodash "^4.17.5" + source-map "^0.5.0" + trim-right "^1.0.1" + +"@babel/helper-annotate-as-pure@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0-beta.54.tgz#1626126a3f9fc4ed280ac942372c7d39653d7121" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-builder-binary-assignment-operator-visitor@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.0.0-beta.54.tgz#d0a1967635b9eebcafdba80491917ee4981c12fa" + dependencies: + "@babel/helper-explode-assignable-expression" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-call-delegate@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-call-delegate/-/helper-call-delegate-7.0.0-beta.54.tgz#f6b72cfd832fb26eb2a806e18de05f88d3a8f302" + dependencies: + "@babel/helper-hoist-variables" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-define-map@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.0.0-beta.54.tgz#2036d7c49365987f091db9702ce2f3b55f677730" + dependencies: + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/helper-explode-assignable-expression@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.0.0-beta.54.tgz#cf067f3330965c2048bf087ea06f62c76d94a792" + dependencies: + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-function-name@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.54.tgz#307875507a1eda2482a09a9a4df6a25632ffb34b" + dependencies: + "@babel/helper-get-function-arity" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-get-function-arity@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.54.tgz#757bd189b077074a004028cfde5f083c306cc6c4" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-hoist-variables@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.0.0-beta.54.tgz#8635be8095135ff73f753ed189e449f68b4f43cb" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-member-expression-to-functions@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.0.0-beta.54.tgz#bce9ddc484317b13d2615bafe2b524d0d56d99df" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-module-imports@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0-beta.54.tgz#c2d8e14ff034225bf431356db77ef467b8d35aac" + dependencies: + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/helper-module-transforms@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.0.0-beta.54.tgz#8cc57eb0db5f0945d866524d555abd084e30cc35" + dependencies: + "@babel/helper-module-imports" "7.0.0-beta.54" + "@babel/helper-simple-access" "7.0.0-beta.54" + "@babel/helper-split-export-declaration" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/helper-optimise-call-expression@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.0.0-beta.54.tgz#4af8dd4ff90dbd29b3bcf85fff43952e2ae1016e" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-plugin-utils@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0-beta.54.tgz#61d2a9a0f9a3e31838a458debb9eebd7bdd249b4" + +"@babel/helper-regex@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.0.0-beta.54.tgz#8ac562f855f132fc68dfd10b132552555ac870d9" + dependencies: + lodash "^4.17.5" + +"@babel/helper-remap-async-to-generator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.0.0-beta.54.tgz#39a50052aadd74d40c73b7c58eb963b90fac56d3" + dependencies: + "@babel/helper-annotate-as-pure" "7.0.0-beta.54" + "@babel/helper-wrap-function" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-replace-supers@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.0.0-beta.54.tgz#901f5a1493a410799fd3ab3e0c0d29d18071c89f" + dependencies: + "@babel/helper-member-expression-to-functions" "7.0.0-beta.54" + "@babel/helper-optimise-call-expression" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-simple-access@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.0.0-beta.54.tgz#5f760a19589a9b6f07e80a65ef4bcbd4fba8c253" + dependencies: + "@babel/template" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/helper-split-export-declaration@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.54.tgz#89cd8833c95481a0827ac6a1bfccddb92b75a109" + dependencies: + "@babel/types" "7.0.0-beta.54" + +"@babel/helper-wrap-function@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.0.0-beta.54.tgz#dc1b7a483a3074a3531b36523e03156d910a3a2a" + dependencies: + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/helpers@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.0.0-beta.54.tgz#b86a99a80efd81668caef307610b961197446a74" + dependencies: + "@babel/template" "7.0.0-beta.54" + "@babel/traverse" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + +"@babel/highlight@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0-beta.54.tgz#155d507358329b8e7068970017c3fd74a9b08584" + dependencies: + chalk "^2.0.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + +"@babel/parser@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.0.0-beta.54.tgz#c01aa63b57c9c8dce8744796c81d9df121f20db4" + +"@babel/plugin-proposal-async-generator-functions@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.0.0-beta.54.tgz#19871bd655b5d748b0ae3e9ecebe247be8b7f83b" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-remap-async-to-generator" "7.0.0-beta.54" + "@babel/plugin-syntax-async-generators" "7.0.0-beta.54" + +"@babel/plugin-proposal-object-rest-spread@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.0.0-beta.54.tgz#5481269a020dd0d38715a8094fed015d30ef4c2a" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/plugin-syntax-object-rest-spread" "7.0.0-beta.54" + +"@babel/plugin-proposal-optional-catch-binding@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.0.0-beta.54.tgz#931f69298fa0c411b2596616cf5a1d82925b87a9" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/plugin-syntax-optional-catch-binding" "7.0.0-beta.54" + +"@babel/plugin-proposal-unicode-property-regex@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.0.0-beta.54.tgz#1624631faf688bcbde4918712bd0af7186f7d245" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-regex" "7.0.0-beta.54" + regexpu-core "^4.2.0" + +"@babel/plugin-syntax-async-generators@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.0.0-beta.54.tgz#ffac8f64927614762897cc9643495fd38097dd41" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-syntax-object-rest-spread@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.0.0-beta.54.tgz#e0f445612081ab573e2535adbabc7b710d17940c" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-syntax-optional-catch-binding@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.0.0-beta.54.tgz#2eb8ddde19ddf73a343d087a087159ed44e54809" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-arrow-functions@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.0.0-beta.54.tgz#44a977b8e61e4efcc7658bbbe260f204ca1bcf72" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-async-to-generator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.0.0-beta.54.tgz#d035e65c50884937d64dbe68d16498c032f8bbec" + dependencies: + "@babel/helper-module-imports" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-remap-async-to-generator" "7.0.0-beta.54" + +"@babel/plugin-transform-block-scoped-functions@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.0.0-beta.54.tgz#938a77fb12f0e11661bdf5386e4aeca47f0c053b" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-block-scoping@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.0.0-beta.54.tgz#bcae1c2ffae4cc3b7b3e5455f0a98daecc09a3c6" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/plugin-transform-classes@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-classes/-/plugin-transform-classes-7.0.0-beta.54.tgz#b15781d2e499ce25438e73fea2fa5a09858568ff" + dependencies: + "@babel/helper-annotate-as-pure" "7.0.0-beta.54" + "@babel/helper-define-map" "7.0.0-beta.54" + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/helper-optimise-call-expression" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-replace-supers" "7.0.0-beta.54" + "@babel/helper-split-export-declaration" "7.0.0-beta.54" + globals "^11.1.0" + +"@babel/plugin-transform-computed-properties@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.0.0-beta.54.tgz#b28494942b94fb86d01994763d2b5c43bdd986af" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-destructuring@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.0.0-beta.54.tgz#81f649a3e4fcb62c2b2ad497f783a800b994472f" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-dotall-regex@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.0.0-beta.54.tgz#2835b7f4141b19fa0648eb96ffe3c4fccd1eca20" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-regex" "7.0.0-beta.54" + regexpu-core "^4.1.3" + +"@babel/plugin-transform-duplicate-keys@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.0.0-beta.54.tgz#4b8f4fb349902a800679191f59d0fa53fca49400" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-exponentiation-operator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.0.0-beta.54.tgz#1017096366fb43ebca8ed8d8d0cdd1ebd64febb2" + dependencies: + "@babel/helper-builder-binary-assignment-operator-visitor" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-for-of@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.0.0-beta.54.tgz#261d2992058a9e09234b9ff67820054ffc55f79c" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-function-name@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.0.0-beta.54.tgz#cc722f9973931337def3d1e6c55138581edd371e" + dependencies: + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-literals@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-literals/-/plugin-transform-literals-7.0.0-beta.54.tgz#70f07ecc2f3b7bc9f542a578e82eec18a5504098" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-modules-amd@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.0.0-beta.54.tgz#fb50740741420bb485ee1315d2e1133db4e433d2" + dependencies: + "@babel/helper-module-transforms" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-modules-commonjs@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.0.0-beta.54.tgz#07d912a7a24dad2d9bf5d44ce322ddc457a8db37" + dependencies: + "@babel/helper-module-transforms" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-simple-access" "7.0.0-beta.54" + +"@babel/plugin-transform-modules-systemjs@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.0.0-beta.54.tgz#0923f012ac252e037467245ff27f8954f4ce6803" + dependencies: + "@babel/helper-hoist-variables" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-modules-umd@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.0.0-beta.54.tgz#3af0e2cf8f533b2984a8ca6da316246850c3aeda" + dependencies: + "@babel/helper-module-transforms" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-new-target@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.0.0-beta.54.tgz#634ee57fa805720195cd31086c973f1fc5c9949b" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-object-super@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.0.0-beta.54.tgz#d25fad66eff90de03ee62f8384f0af57bcd065d9" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-replace-supers" "7.0.0-beta.54" + +"@babel/plugin-transform-parameters@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.0.0-beta.54.tgz#76306f19b9acac6cf13721af15ecb9f382864ff7" + dependencies: + "@babel/helper-call-delegate" "7.0.0-beta.54" + "@babel/helper-get-function-arity" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-regenerator@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.0.0-beta.54.tgz#8b46e192f3bfe096bbbf86e27764e7662e5f9a0f" + dependencies: + regenerator-transform "^0.13.3" + +"@babel/plugin-transform-shorthand-properties@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.0.0-beta.54.tgz#50e73c2afc5898b1055510ddf60ee13a6301517f" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-spread@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-spread/-/plugin-transform-spread-7.0.0-beta.54.tgz#4f0852df0f4b1db2426c40facd8fe5f028a3dbc9" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-sticky-regex@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.0.0-beta.54.tgz#568f35eb5118ae96fad82eac36374d7923b47883" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-regex" "7.0.0-beta.54" + +"@babel/plugin-transform-template-literals@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.0.0-beta.54.tgz#cb1f6303cafb8442a6c6c69a0dfbb60699f327bc" + dependencies: + "@babel/helper-annotate-as-pure" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-typeof-symbol@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.0.0-beta.54.tgz#6d068686239c9ebaf534d1c0d8032953f7b521bc" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + +"@babel/plugin-transform-unicode-regex@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.0.0-beta.54.tgz#1dc7e9150b39aaeb19fca1c863e082f6096afc60" + dependencies: + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/helper-regex" "7.0.0-beta.54" + regexpu-core "^4.1.3" + +"@babel/preset-env@^7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.0.0-beta.54.tgz#4b05c4e3aaed64a509098e4e854dfc0e02edf053" + dependencies: + "@babel/helper-module-imports" "7.0.0-beta.54" + "@babel/helper-plugin-utils" "7.0.0-beta.54" + "@babel/plugin-proposal-async-generator-functions" "7.0.0-beta.54" + "@babel/plugin-proposal-object-rest-spread" "7.0.0-beta.54" + "@babel/plugin-proposal-optional-catch-binding" "7.0.0-beta.54" + "@babel/plugin-proposal-unicode-property-regex" "7.0.0-beta.54" + "@babel/plugin-syntax-async-generators" "7.0.0-beta.54" + "@babel/plugin-syntax-object-rest-spread" "7.0.0-beta.54" + "@babel/plugin-syntax-optional-catch-binding" "7.0.0-beta.54" + "@babel/plugin-transform-arrow-functions" "7.0.0-beta.54" + "@babel/plugin-transform-async-to-generator" "7.0.0-beta.54" + "@babel/plugin-transform-block-scoped-functions" "7.0.0-beta.54" + "@babel/plugin-transform-block-scoping" "7.0.0-beta.54" + "@babel/plugin-transform-classes" "7.0.0-beta.54" + "@babel/plugin-transform-computed-properties" "7.0.0-beta.54" + "@babel/plugin-transform-destructuring" "7.0.0-beta.54" + "@babel/plugin-transform-dotall-regex" "7.0.0-beta.54" + "@babel/plugin-transform-duplicate-keys" "7.0.0-beta.54" + "@babel/plugin-transform-exponentiation-operator" "7.0.0-beta.54" + "@babel/plugin-transform-for-of" "7.0.0-beta.54" + "@babel/plugin-transform-function-name" "7.0.0-beta.54" + "@babel/plugin-transform-literals" "7.0.0-beta.54" + "@babel/plugin-transform-modules-amd" "7.0.0-beta.54" + "@babel/plugin-transform-modules-commonjs" "7.0.0-beta.54" + "@babel/plugin-transform-modules-systemjs" "7.0.0-beta.54" + "@babel/plugin-transform-modules-umd" "7.0.0-beta.54" + "@babel/plugin-transform-new-target" "7.0.0-beta.54" + "@babel/plugin-transform-object-super" "7.0.0-beta.54" + "@babel/plugin-transform-parameters" "7.0.0-beta.54" + "@babel/plugin-transform-regenerator" "7.0.0-beta.54" + "@babel/plugin-transform-shorthand-properties" "7.0.0-beta.54" + "@babel/plugin-transform-spread" "7.0.0-beta.54" + "@babel/plugin-transform-sticky-regex" "7.0.0-beta.54" + "@babel/plugin-transform-template-literals" "7.0.0-beta.54" + "@babel/plugin-transform-typeof-symbol" "7.0.0-beta.54" + "@babel/plugin-transform-unicode-regex" "7.0.0-beta.54" + browserslist "^3.0.0" + invariant "^2.2.2" + js-levenshtein "^1.1.3" + semver "^5.3.0" + +"@babel/template@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.54.tgz#d5b0d2d2d55c0e78b048c61a058f36cfd7d91af3" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + lodash "^4.17.5" + +"@babel/traverse@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0-beta.54.tgz#2c17f98dcdbf19aa918fde128f0e1a0bc089e05a" + dependencies: + "@babel/code-frame" "7.0.0-beta.54" + "@babel/generator" "7.0.0-beta.54" + "@babel/helper-function-name" "7.0.0-beta.54" + "@babel/helper-split-export-declaration" "7.0.0-beta.54" + "@babel/parser" "7.0.0-beta.54" + "@babel/types" "7.0.0-beta.54" + debug "^3.1.0" + globals "^11.1.0" + lodash "^4.17.5" + +"@babel/types@7.0.0-beta.54": + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0-beta.54.tgz#025ad68492fed542c13f14c579a44c848e531063" + dependencies: + esutils "^2.0.2" + lodash "^4.17.5" + to-fast-properties "^2.0.0" + "@samverschueren/stream-to-observable@^0.3.0": version "0.3.0" resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f" dependencies: any-observable "^0.3.0" -"@types/babel-core@latest": - version "6.25.3" - resolved "https://registry.yarnpkg.com/@types/babel-core/-/babel-core-6.25.3.tgz#c7fda09007375ae89942307917ed21ed309a1c2a" +"@types/babel-core@^6.25.5": + version "6.25.5" + resolved "https://registry.yarnpkg.com/@types/babel-core/-/babel-core-6.25.5.tgz#7598b1287c2cb5a8e9150d60e4d4a8f2dbe29982" dependencies: "@types/babel-generator" "*" "@types/babel-template" "*" @@ -27,31 +532,31 @@ "@types/babylon" "*" "@types/babel-generator@*": - version "6.25.0" - resolved "https://registry.yarnpkg.com/@types/babel-generator/-/babel-generator-6.25.0.tgz#8255469aa14712f0d1608b99683cabd5b413d96b" + version "6.25.2" + resolved "https://registry.yarnpkg.com/@types/babel-generator/-/babel-generator-6.25.2.tgz#fa13653ec2d34a4037be9c34dec32ae75bea04cc" dependencies: "@types/babel-types" "*" "@types/babel-template@*": - version "6.25.0" - resolved "https://registry.yarnpkg.com/@types/babel-template/-/babel-template-6.25.0.tgz#2505d7b55b88f821d98048b4fdf07b3b22563d30" + version "6.25.1" + resolved "https://registry.yarnpkg.com/@types/babel-template/-/babel-template-6.25.1.tgz#03e23a893c16bab2ec00200ab51feccf488cae78" dependencies: "@types/babel-types" "*" "@types/babylon" "*" "@types/babel-traverse@*": - version "6.25.2" - resolved "https://registry.yarnpkg.com/@types/babel-traverse/-/babel-traverse-6.25.2.tgz#3cfaebe316fec515a964adbb84147b3c8971ba9f" + version "6.25.4" + resolved "https://registry.yarnpkg.com/@types/babel-traverse/-/babel-traverse-6.25.4.tgz#269af6a25c80419b635c8fa29ae42b0d5ce2418c" dependencies: "@types/babel-types" "*" "@types/babel-types@*": - version "6.25.1" - resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-6.25.1.tgz#ce8f126a4403e11e1b0033a424f11638afac7889" + version "7.0.4" + resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.4.tgz#bfd5b0d0d1ba13e351dff65b6e52783b816826c8" "@types/babylon@*": - version "6.16.2" - resolved "https://registry.yarnpkg.com/@types/babylon/-/babylon-6.16.2.tgz#062ce63b693d9af1c246f5aedf928bc9c30589c8" + version "6.16.3" + resolved "https://registry.yarnpkg.com/@types/babylon/-/babylon-6.16.3.tgz#c2937813a89fcb5e79a00062fc4a8b143e7237bb" dependencies: "@types/babel-types" "*" @@ -65,9 +570,9 @@ dependencies: "@types/node" "*" -"@types/jest@^23.1.0": - version "23.1.3" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.3.tgz#4db19b2e7627dc254bbed5781b5609c621b5ad8e" +"@types/jest@^23.3.0": + version "23.3.0" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.0.tgz#5dd70033b616a6228042244ebd992f6426808810" "@types/lodash@^4.14.109": version "4.14.109" @@ -349,30 +854,6 @@ babel-core@^6.0.0, babel-core@^6.26.0: slash "^1.0.0" source-map "^0.5.6" -babel-core@^6.26.3: - version "6.26.3" - resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207" - dependencies: - babel-code-frame "^6.26.0" - babel-generator "^6.26.0" - babel-helpers "^6.24.1" - babel-messages "^6.23.0" - babel-register "^6.26.0" - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - babylon "^6.18.0" - convert-source-map "^1.5.1" - debug "^2.6.9" - json5 "^0.5.1" - lodash "^4.17.4" - minimatch "^3.0.4" - path-is-absolute "^1.0.1" - private "^0.1.8" - slash "^1.0.0" - source-map "^0.5.7" - babel-generator@^6.18.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.0.tgz#ac1ae20070b79f6e3ca1d3269613053774f20dc5" @@ -399,100 +880,6 @@ babel-generator@^6.26.0: source-map "^0.5.7" trim-right "^1.0.1" -babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" - dependencies: - babel-helper-explode-assignable-expression "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-helper-call-delegate@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" - dependencies: - babel-helper-hoist-variables "^6.24.1" - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-define-map@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-helper-define-map/-/babel-helper-define-map-6.26.0.tgz#a5f56dab41a25f97ecb498c7ebaca9819f95be5f" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-helper-explode-assignable-expression@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" - dependencies: - babel-runtime "^6.22.0" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-function-name@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" - dependencies: - babel-helper-get-function-arity "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-get-function-arity@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.24.1.tgz#8f7782aa93407c41d3aa50908f89b031b1b6853d" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-helper-hoist-variables@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-hoist-variables/-/babel-helper-hoist-variables-6.24.1.tgz#1ecb27689c9d25513eadbc9914a73f5408be7a76" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-helper-optimise-call-expression@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-helper-regex@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-helper-regex/-/babel-helper-regex-6.26.0.tgz#325c59f902f82f24b74faceed0363954f6495e72" - dependencies: - babel-runtime "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-helper-remap-async-to-generator@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.24.1.tgz#5ec581827ad723fecdd381f1c928390676e4551b" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-helper-replace-supers@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" - dependencies: - babel-helper-optimise-call-expression "^6.24.1" - babel-messages "^6.23.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - babel-helpers@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.24.1.tgz#3471de9caec388e5c850e597e58a26ddf37602b2" @@ -500,13 +887,6 @@ babel-helpers@^6.24.1: babel-runtime "^6.22.0" babel-template "^6.24.1" -babel-jest@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.0.0.tgz#0e383a2aa6b3535e197db2929570a2182bd084e8" - dependencies: - babel-plugin-istanbul "^4.1.6" - babel-preset-jest "^23.0.0" - babel-jest@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.4.0.tgz#22c34c392e2176f6a4c367992a7fcff69d2e8557" @@ -520,12 +900,6 @@ babel-messages@^6.23.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-check-es2015-constants@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" - dependencies: - babel-runtime "^6.22.0" - babel-plugin-istanbul@^4.1.6: version "4.1.6" resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45" @@ -535,269 +909,14 @@ babel-plugin-istanbul@^4.1.6: istanbul-lib-instrument "^1.10.1" test-exclude "^4.2.1" -babel-plugin-jest-hoist@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.0.0.tgz#e61e68799f743391a1e6306ee270477aacf946c8" - babel-plugin-jest-hoist@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-23.2.0.tgz#e61fae05a1ca8801aadee57a6d66b8cefaf44167" -babel-plugin-syntax-async-functions@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" - -babel-plugin-syntax-exponentiation-operator@^6.8.0: - version "6.13.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" - babel-plugin-syntax-object-rest-spread@^6.13.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" -babel-plugin-syntax-trailing-function-commas@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" - -babel-plugin-transform-async-to-generator@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" - dependencies: - babel-helper-remap-async-to-generator "^6.24.1" - babel-plugin-syntax-async-functions "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-arrow-functions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoped-functions/-/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-block-scoping@^6.23.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" - dependencies: - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-traverse "^6.26.0" - babel-types "^6.26.0" - lodash "^4.17.4" - -babel-plugin-transform-es2015-classes@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" - dependencies: - babel-helper-define-map "^6.24.1" - babel-helper-function-name "^6.24.1" - babel-helper-optimise-call-expression "^6.24.1" - babel-helper-replace-supers "^6.24.1" - babel-messages "^6.23.0" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-computed-properties@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" - dependencies: - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-destructuring@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-duplicate-keys@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-for-of@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-function-name@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" - dependencies: - babel-helper-function-name "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-literals@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-literals/-/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" - dependencies: - babel-plugin-transform-es2015-modules-commonjs "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a" - dependencies: - babel-plugin-transform-strict-mode "^6.24.1" - babel-runtime "^6.26.0" - babel-template "^6.26.0" - babel-types "^6.26.0" - -babel-plugin-transform-es2015-modules-systemjs@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" - dependencies: - babel-helper-hoist-variables "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-modules-umd@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" - dependencies: - babel-plugin-transform-es2015-modules-amd "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - -babel-plugin-transform-es2015-object-super@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" - dependencies: - babel-helper-replace-supers "^6.24.1" - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-parameters@^6.23.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" - dependencies: - babel-helper-call-delegate "^6.24.1" - babel-helper-get-function-arity "^6.24.1" - babel-runtime "^6.22.0" - babel-template "^6.24.1" - babel-traverse "^6.24.1" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-shorthand-properties@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-spread@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-spread/-/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-sticky-regex@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" - dependencies: - babel-helper-regex "^6.24.1" - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-plugin-transform-es2015-template-literals@^6.22.0: - version "6.22.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-typeof-symbol@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" - dependencies: - babel-runtime "^6.22.0" - -babel-plugin-transform-es2015-unicode-regex@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" - dependencies: - babel-helper-regex "^6.24.1" - babel-runtime "^6.22.0" - regexpu-core "^2.0.0" - -babel-plugin-transform-exponentiation-operator@^6.22.0: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" - dependencies: - babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" - babel-plugin-syntax-exponentiation-operator "^6.8.0" - babel-runtime "^6.22.0" - -babel-plugin-transform-regenerator@^6.22.0: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" - dependencies: - regenerator-transform "^0.10.0" - -babel-plugin-transform-strict-mode@^6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" - dependencies: - babel-runtime "^6.22.0" - babel-types "^6.24.1" - -babel-preset-env@^1.7.0: - version "1.7.0" - resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.7.0.tgz#dea79fa4ebeb883cd35dab07e260c1c9c04df77a" - dependencies: - babel-plugin-check-es2015-constants "^6.22.0" - babel-plugin-syntax-trailing-function-commas "^6.22.0" - babel-plugin-transform-async-to-generator "^6.22.0" - babel-plugin-transform-es2015-arrow-functions "^6.22.0" - babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" - babel-plugin-transform-es2015-block-scoping "^6.23.0" - babel-plugin-transform-es2015-classes "^6.23.0" - babel-plugin-transform-es2015-computed-properties "^6.22.0" - babel-plugin-transform-es2015-destructuring "^6.23.0" - babel-plugin-transform-es2015-duplicate-keys "^6.22.0" - babel-plugin-transform-es2015-for-of "^6.23.0" - babel-plugin-transform-es2015-function-name "^6.22.0" - babel-plugin-transform-es2015-literals "^6.22.0" - babel-plugin-transform-es2015-modules-amd "^6.22.0" - babel-plugin-transform-es2015-modules-commonjs "^6.23.0" - babel-plugin-transform-es2015-modules-systemjs "^6.23.0" - babel-plugin-transform-es2015-modules-umd "^6.23.0" - babel-plugin-transform-es2015-object-super "^6.22.0" - babel-plugin-transform-es2015-parameters "^6.23.0" - babel-plugin-transform-es2015-shorthand-properties "^6.22.0" - babel-plugin-transform-es2015-spread "^6.22.0" - babel-plugin-transform-es2015-sticky-regex "^6.22.0" - babel-plugin-transform-es2015-template-literals "^6.22.0" - babel-plugin-transform-es2015-typeof-symbol "^6.23.0" - babel-plugin-transform-es2015-unicode-regex "^6.22.0" - babel-plugin-transform-exponentiation-operator "^6.22.0" - babel-plugin-transform-regenerator "^6.22.0" - browserslist "^3.2.6" - invariant "^2.2.2" - semver "^5.3.0" - -babel-preset-jest@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-23.0.0.tgz#49de0303f1b6875dcad6163eaa7eb8330d54824d" - dependencies: - babel-plugin-jest-hoist "^23.0.0" - babel-plugin-syntax-object-rest-spread "^6.13.0" - babel-preset-jest@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-23.2.0.tgz#8ec7a03a138f001a1a8fb1e8113652bf1a55da46" @@ -817,7 +936,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.9.2: +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: @@ -834,7 +953,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0: babylon "^6.18.0" lodash "^4.17.4" -babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: +babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" dependencies: @@ -848,7 +967,7 @@ babel-traverse@^6.0.0, babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-tra invariant "^2.2.2" lodash "^4.17.4" -babel-types@^6.0.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: +babel-types@^6.0.0, babel-types@^6.18.0, babel-types@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" dependencies: @@ -967,7 +1086,7 @@ browser-resolve@^1.11.3: dependencies: resolve "1.1.7" -browserslist@^3.2.6: +browserslist@^3.0.0: version "3.2.8" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" dependencies: @@ -1015,8 +1134,8 @@ camelcase@^4.1.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" caniuse-lite@^1.0.30000844: - version "1.0.30000846" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000846.tgz#2092911eecad71a89dae1faa62bcc202fde7f959" + version "1.0.30000865" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000865.tgz#70026616e8afe6e1442f8bb4e1092987d81a2f25" caseless@~0.12.0: version "0.12.0" @@ -1203,7 +1322,7 @@ content-type-parser@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/content-type-parser/-/content-type-parser-1.0.1.tgz#c3e56988c53c65127fb46d4032a3a900246fdc94" -convert-source-map@^1.4.0, convert-source-map@^1.5.0, convert-source-map@^1.5.1: +convert-source-map@^1.1.0, convert-source-map@^1.4.0, convert-source-map@^1.5.0: version "1.5.1" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5" @@ -1319,7 +1438,7 @@ date-fns@^1.27.2: version "1.29.0" resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.29.0.tgz#12e609cdcb935127311d04d33334e2960a2a54e6" -debug@^2.1.3, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: +debug@^2.1.3, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" dependencies: @@ -1469,8 +1588,8 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" electron-to-chromium@^1.3.47: - version "1.3.48" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.48.tgz#d3b0d8593814044e092ece2108fc3ac9aea4b900" + version "1.3.52" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.52.tgz#d2d9f1270ba4a3b967b831c40ef71fb4d9ab5ce0" elegant-spinner@^1.0.1: version "1.0.1" @@ -1630,17 +1749,6 @@ expect@^22.4.0: jest-message-util "^22.4.0" jest-regex-util "^22.1.0" -expect@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/expect/-/expect-23.0.0.tgz#2c3ab0a44dae319e00a73e3561762768d03a2b27" - dependencies: - ansi-styles "^3.2.0" - jest-diff "^23.0.0" - jest-get-type "^22.1.0" - jest-matcher-utils "^23.0.0" - jest-message-util "^23.0.0" - jest-regex-util "^23.0.0" - expect@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/expect/-/expect-23.4.0.tgz#6da4ecc99c1471253e7288338983ad1ebadb60c3" @@ -1696,6 +1804,10 @@ fast-deep-equal@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff" +fast-json-stable-stringify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" + fast-levenshtein@~2.0.4: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" @@ -1931,6 +2043,10 @@ glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: once "^1.3.0" path-is-absolute "^1.0.0" +globals@^11.1.0: + version "11.7.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-11.7.0.tgz#a583faa43055b1aca771914bf68258e2fc125673" + globals@^9.18.0: version "9.18.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" @@ -2492,15 +2608,15 @@ istanbul-reports@^1.3.0: dependencies: handlebars "^4.0.3" -jest-changed-files@^22.2.0: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-22.4.3.tgz#8882181e022c38bd46a2e4d18d44d19d90a90fb2" +jest-changed-files@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-23.4.0.tgz#f1b304f98c235af5d9a31ec524262c5e4de3c6ff" dependencies: throat "^4.0.0" -jest-cli@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-23.0.0.tgz#29287498c9d844dcda5aaf011a4c82f9a888836e" +jest-cli@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-23.4.1.tgz#c1ffd33254caee376990aa2abe2963e0de4ca76b" dependencies: ansi-escapes "^3.0.0" chalk "^2.0.1" @@ -2513,22 +2629,24 @@ jest-cli@^23.0.0: istanbul-lib-coverage "^1.2.0" istanbul-lib-instrument "^1.10.1" istanbul-lib-source-maps "^1.2.4" - jest-changed-files "^22.2.0" - jest-config "^23.0.0" - jest-environment-jsdom "^23.0.0" + jest-changed-files "^23.4.0" + jest-config "^23.4.1" + jest-environment-jsdom "^23.4.0" jest-get-type "^22.1.0" - jest-haste-map "^23.0.0" - jest-message-util "^23.0.0" - jest-regex-util "^23.0.0" - jest-resolve-dependencies "^23.0.0" - jest-runner "^23.0.0" - jest-runtime "^23.0.0" - jest-snapshot "^23.0.0" - jest-util "^23.0.0" - jest-validate "^23.0.0" - jest-worker "^23.0.0" + jest-haste-map "^23.4.1" + jest-message-util "^23.4.0" + jest-regex-util "^23.3.0" + jest-resolve-dependencies "^23.4.1" + jest-runner "^23.4.1" + jest-runtime "^23.4.1" + jest-snapshot "^23.4.1" + jest-util "^23.4.0" + jest-validate "^23.4.0" + jest-watcher "^23.4.0" + jest-worker "^23.2.0" micromatch "^2.3.11" node-notifier "^5.2.1" + prompts "^0.1.9" realpath-native "^1.0.0" rimraf "^2.5.4" slash "^1.0.0" @@ -2553,24 +2671,6 @@ jest-config@^22.4.2: jest-validate "^22.4.2" pretty-format "^22.4.0" -jest-config@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.0.0.tgz#9444d858873ad567376f8cfe139fd8828e8d494b" - dependencies: - babel-core "^6.0.0" - babel-jest "^23.0.0" - chalk "^2.0.1" - glob "^7.1.1" - jest-environment-jsdom "^23.0.0" - jest-environment-node "^23.0.0" - jest-get-type "^22.1.0" - jest-jasmine2 "^23.0.0" - jest-regex-util "^23.0.0" - jest-resolve "^23.0.0" - jest-util "^23.0.0" - jest-validate "^23.0.0" - pretty-format "^23.0.0" - jest-config@^23.4.1: version "23.4.1" resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.4.1.tgz#3172fa21f0507d7f8a088ed1dbe4157057f201e9" @@ -2598,15 +2698,6 @@ jest-diff@^22.4.0: jest-get-type "^22.1.0" pretty-format "^22.4.0" -jest-diff@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.0.0.tgz#0a00b2157f518eec338121ccf8879c529269a88e" - dependencies: - chalk "^2.0.1" - diff "^3.2.0" - jest-get-type "^22.1.0" - pretty-format "^23.0.0" - jest-diff@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.2.0.tgz#9f2cf4b51e12c791550200abc16b47130af1062a" @@ -2616,9 +2707,9 @@ jest-diff@^23.2.0: jest-get-type "^22.1.0" pretty-format "^23.2.0" -jest-docblock@^22.4.0: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-22.4.3.tgz#50886f132b42b280c903c592373bb6e93bb68b19" +jest-docblock@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-23.2.0.tgz#f085e1f18548d99fdd69b20207e6fd55d91383a7" dependencies: detect-newline "^2.1.0" @@ -2637,14 +2728,6 @@ jest-environment-jsdom@^22.4.1: jest-util "^22.4.1" jsdom "^11.5.1" -jest-environment-jsdom@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-23.0.0.tgz#57b0f0dd263359a86d7952a4b712b3fabca1a625" - dependencies: - jest-mock "^23.0.0" - jest-util "^23.0.0" - jsdom "^11.5.1" - jest-environment-jsdom@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-23.4.0.tgz#056a7952b3fea513ac62a140a2c368c79d9e6023" @@ -2660,13 +2743,6 @@ jest-environment-node@^22.4.1: jest-mock "^22.2.0" jest-util "^22.4.1" -jest-environment-node@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-23.0.0.tgz#ef93a414a612484cf585c8b32ccc5ae30ce6095c" - dependencies: - jest-mock "^23.0.0" - jest-util "^23.0.0" - jest-environment-node@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-23.4.0.tgz#57e80ed0841dea303167cce8cd79521debafde10" @@ -2678,15 +2754,15 @@ jest-get-type@^22.1.0: version "22.1.0" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.1.0.tgz#4e90af298ed6181edc85d2da500dbd2753e0d5a9" -jest-haste-map@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-23.0.0.tgz#09be1c9a37c16b2e2f25398864eb2806d309ca96" +jest-haste-map@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-23.4.1.tgz#43a174ba7ac079ae1dd74eaf5a5fe78989474dd2" dependencies: fb-watchman "^2.0.0" graceful-fs "^4.1.11" - jest-docblock "^22.4.0" - jest-serializer "^23.0.0" - jest-worker "^23.0.0" + jest-docblock "^23.2.0" + jest-serializer "^23.0.1" + jest-worker "^23.2.0" micromatch "^2.3.11" sane "^2.0.0" @@ -2706,21 +2782,6 @@ jest-jasmine2@^22.4.2: jest-util "^22.4.1" source-map-support "^0.5.0" -jest-jasmine2@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-23.0.0.tgz#ea26f87b5c223e1a70985032f0727d8f855e59df" - dependencies: - chalk "^2.0.1" - co "^4.6.0" - expect "^23.0.0" - is-generator-fn "^1.0.0" - jest-diff "^23.0.0" - jest-matcher-utils "^23.0.0" - jest-message-util "^23.0.0" - jest-snapshot "^23.0.0" - jest-util "^23.0.0" - pretty-format "^23.0.0" - jest-jasmine2@^23.4.1: version "23.4.1" resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-23.4.1.tgz#fa192262430d418e827636e4a98423e5e7ff0fce" @@ -2737,11 +2798,11 @@ jest-jasmine2@^23.4.1: jest-util "^23.4.0" pretty-format "^23.2.0" -jest-leak-detector@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-23.0.0.tgz#ec93d755b21e8b2c4c4e59b8cccab1805a704ab3" +jest-leak-detector@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-23.2.0.tgz#c289d961dc638f14357d4ef96e0431ecc1aa377d" dependencies: - pretty-format "^23.0.0" + pretty-format "^23.2.0" jest-matcher-utils@^22.4.0: version "22.4.0" @@ -2751,14 +2812,6 @@ jest-matcher-utils@^22.4.0: jest-get-type "^22.1.0" pretty-format "^22.4.0" -jest-matcher-utils@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.0.0.tgz#ca2168fe5a7a416c0d7f2916e969e89dcce9d92a" - dependencies: - chalk "^2.0.1" - jest-get-type "^22.1.0" - pretty-format "^23.0.0" - jest-matcher-utils@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.2.0.tgz#4d4981f23213e939e3cedf23dc34c747b5ae1913" @@ -2777,16 +2830,6 @@ jest-message-util@^22.4.0: slash "^1.0.0" stack-utils "^1.0.1" -jest-message-util@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.0.0.tgz#073f3d76c701f7c718a4b9af1eb7f138792c4796" - dependencies: - "@babel/code-frame" "^7.0.0-beta.35" - chalk "^2.0.1" - micromatch "^2.3.11" - slash "^1.0.0" - stack-utils "^1.0.1" - jest-message-util@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.4.0.tgz#17610c50942349508d01a3d1e0bda2c079086a9f" @@ -2801,10 +2844,6 @@ jest-mock@^22.2.0: version "22.2.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-22.2.0.tgz#444b3f9488a7473adae09bc8a77294afded397a7" -jest-mock@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.0.0.tgz#d9d897a1b74dc05c66a737213931496215897dd8" - jest-mock@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.2.0.tgz#ad1c60f29e8719d47c26e1138098b6d18b261134" @@ -2813,20 +2852,16 @@ jest-regex-util@^22.1.0: version "22.1.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-22.1.0.tgz#5daf2fe270074b6da63e5d85f1c9acc866768f53" -jest-regex-util@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.0.0.tgz#dd5c1fde0c46f4371314cf10f7a751a23f4e8f76" - jest-regex-util@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.3.0.tgz#5f86729547c2785c4002ceaa8f849fe8ca471bc5" -jest-resolve-dependencies@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-23.0.0.tgz#c3e1cfee0e543dee10e6ec0628df69cd239244c9" +jest-resolve-dependencies@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-23.4.1.tgz#a1d85247e2963f8b3859f6b0ec61b741b359378e" dependencies: - jest-regex-util "^23.0.0" - jest-snapshot "^23.0.0" + jest-regex-util "^23.3.0" + jest-snapshot "^23.4.1" jest-resolve@^22.4.2: version "22.4.2" @@ -2835,14 +2870,6 @@ jest-resolve@^22.4.2: browser-resolve "^1.11.2" chalk "^2.0.1" -jest-resolve@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-23.0.0.tgz#f04362fd0531b4546399df76c55c3214a9f45e02" - dependencies: - browser-resolve "^1.11.2" - chalk "^2.0.1" - realpath-native "^1.0.0" - jest-resolve@^23.4.1: version "23.4.1" resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-23.4.1.tgz#7f3c17104732a2c0c940a01256025ed745814982" @@ -2851,43 +2878,43 @@ jest-resolve@^23.4.1: chalk "^2.0.1" realpath-native "^1.0.0" -jest-runner@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-23.0.0.tgz#b198a2dd78d57a2c0f3f8d7c7f97b62673922020" +jest-runner@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-23.4.1.tgz#d41fd1459b95d35d6df685f1468c09e617c8c260" dependencies: exit "^0.1.2" graceful-fs "^4.1.11" - jest-config "^23.0.0" - jest-docblock "^22.4.0" - jest-haste-map "^23.0.0" - jest-jasmine2 "^23.0.0" - jest-leak-detector "^23.0.0" - jest-message-util "^23.0.0" - jest-runtime "^23.0.0" - jest-util "^23.0.0" - jest-worker "^23.0.0" + jest-config "^23.4.1" + jest-docblock "^23.2.0" + jest-haste-map "^23.4.1" + jest-jasmine2 "^23.4.1" + jest-leak-detector "^23.2.0" + jest-message-util "^23.4.0" + jest-runtime "^23.4.1" + jest-util "^23.4.0" + jest-worker "^23.2.0" source-map-support "^0.5.6" throat "^4.0.0" -jest-runtime@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-23.0.0.tgz#8619227fe2e01603d542b9101dd3e64ef4593f66" +jest-runtime@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-23.4.1.tgz#c1822eba5eb19294debe6b25b2760d0a8c532fd1" dependencies: babel-core "^6.0.0" babel-plugin-istanbul "^4.1.6" chalk "^2.0.1" convert-source-map "^1.4.0" exit "^0.1.2" + fast-json-stable-stringify "^2.0.0" graceful-fs "^4.1.11" - jest-config "^23.0.0" - jest-haste-map "^23.0.0" - jest-message-util "^23.0.0" - jest-regex-util "^23.0.0" - jest-resolve "^23.0.0" - jest-snapshot "^23.0.0" - jest-util "^23.0.0" - jest-validate "^23.0.0" - json-stable-stringify "^1.0.1" + jest-config "^23.4.1" + jest-haste-map "^23.4.1" + jest-message-util "^23.4.0" + jest-regex-util "^23.3.0" + jest-resolve "^23.4.1" + jest-snapshot "^23.4.1" + jest-util "^23.4.0" + jest-validate "^23.4.0" micromatch "^2.3.11" realpath-native "^1.0.0" slash "^1.0.0" @@ -2895,9 +2922,9 @@ jest-runtime@^23.0.0: write-file-atomic "^2.1.0" yargs "^11.0.0" -jest-serializer@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-23.0.0.tgz#263411ac92e1e3dde243858642bb04e8a986e8ca" +jest-serializer@^23.0.1: + version "23.0.1" + resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-23.0.1.tgz#a3776aeb311e90fe83fab9e533e85102bd164165" jest-snapshot@^22.4.0: version "22.4.0" @@ -2910,17 +2937,6 @@ jest-snapshot@^22.4.0: natural-compare "^1.4.0" pretty-format "^22.4.0" -jest-snapshot@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.0.0.tgz#49cdb92a69b9999dbf92e0634d5ba1e8a8586803" - dependencies: - chalk "^2.0.1" - jest-diff "^23.0.0" - jest-matcher-utils "^23.0.0" - mkdirp "^0.5.1" - natural-compare "^1.4.0" - pretty-format "^23.0.0" - jest-snapshot@^23.4.1: version "23.4.1" resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.4.1.tgz#090de9acae927f6a3af3005bda40d912b83e9c96" @@ -2949,18 +2965,6 @@ jest-util@^22.4.1: mkdirp "^0.5.1" source-map "^0.6.0" -jest-util@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-23.0.0.tgz#86386800ffbe3fe17a06320e0cf9ca9b7868263b" - dependencies: - callsites "^2.0.0" - chalk "^2.0.1" - graceful-fs "^4.1.11" - is-ci "^1.0.10" - jest-message-util "^23.0.0" - mkdirp "^0.5.1" - source-map "^0.6.0" - jest-util@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-23.4.0.tgz#4d063cb927baf0a23831ff61bec2cbbf49793561" @@ -2984,15 +2988,6 @@ jest-validate@^22.4.0, jest-validate@^22.4.2: leven "^2.1.0" pretty-format "^22.4.0" -jest-validate@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.0.0.tgz#f88bc897b6cc376979aff0262d1025df1302d520" - dependencies: - chalk "^2.0.1" - jest-get-type "^22.1.0" - leven "^2.1.0" - pretty-format "^23.0.0" - jest-validate@^23.4.0: version "23.4.0" resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-23.4.0.tgz#d96eede01ef03ac909c009e9c8e455197d48c201" @@ -3002,18 +2997,30 @@ jest-validate@^23.4.0: leven "^2.1.0" pretty-format "^23.2.0" -jest-worker@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-23.0.0.tgz#e6b1378b81f8e6a108f3be33a1faa830c22ea450" +jest-watcher@^23.4.0: + version "23.4.0" + resolved "https://registry.yarnpkg.com/jest-watcher/-/jest-watcher-23.4.0.tgz#d2e28ce74f8dad6c6afc922b92cabef6ed05c91c" + dependencies: + ansi-escapes "^3.0.0" + chalk "^2.0.1" + string-length "^2.0.0" + +jest-worker@^23.2.0: + version "23.2.0" + resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-23.2.0.tgz#faf706a8da36fae60eb26957257fa7b5d8ea02b9" dependencies: merge-stream "^1.0.1" -jest@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/jest/-/jest-23.0.0.tgz#9282980309f5cde27aadc59ae583f1117c0e4430" +jest@^23.4.1: + version "23.4.1" + resolved "https://registry.yarnpkg.com/jest/-/jest-23.4.1.tgz#39550c72f3237f63ae1b434d8d122cdf6fa007b6" dependencies: import-local "^1.0.0" - jest-cli "^23.0.0" + jest-cli "^23.4.1" + +js-levenshtein@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.3.tgz#3ef627df48ec8cf24bacf05c0f184ff30ef413c5" js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" @@ -3063,6 +3070,10 @@ jsesc@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" +jsesc@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.1.tgz#e421a2a8e20d6b0819df28908f782526b96dd1fe" + jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" @@ -3089,7 +3100,7 @@ json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" -json5@^0.5.1: +json5@^0.5.0, json5@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" @@ -3132,6 +3143,10 @@ kind-of@^6.0.0, kind-of@^6.0.2: version "6.0.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.2.tgz#01146b36a6218e64e58f3a8d66de5d7fc6f6d051" +kleur@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/kleur/-/kleur-1.0.2.tgz#637f126d3cda40a423b1297da88cf753bd04ebdd" + lazy-cache@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" @@ -3874,13 +3889,6 @@ pretty-format@^22.4.0: ansi-regex "^3.0.0" ansi-styles "^3.2.0" -pretty-format@^23.0.0: - version "23.0.0" - resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.0.0.tgz#b66dc584a0907b1969783c4c20e4d1180b18ac75" - dependencies: - ansi-regex "^3.0.0" - ansi-styles "^3.2.0" - pretty-format@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.2.0.tgz#3b0aaa63c018a53583373c1cb3a5d96cc5e83017" @@ -3888,7 +3896,7 @@ pretty-format@^23.2.0: ansi-regex "^3.0.0" ansi-styles "^3.2.0" -private@^0.1.6, private@^0.1.7, private@^0.1.8: +private@^0.1.6, private@^0.1.7: version "0.1.8" resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" @@ -3906,6 +3914,13 @@ promise@^7.1.1: dependencies: asap "~2.0.3" +prompts@^0.1.9: + version "0.1.12" + resolved "https://registry.yarnpkg.com/prompts/-/prompts-0.1.12.tgz#39dc42de7d2f0ec3e2af76bf40713fcb8726090d" + dependencies: + kleur "^1.0.0" + sisteransi "^0.1.1" + prop-types@^15.6.0: version "15.6.1" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca" @@ -4036,20 +4051,24 @@ reflect-metadata@^0.1.12: version "0.1.12" resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.12.tgz#311bf0c6b63cd782f228a81abe146a2bfa9c56f2" -regenerate@^1.2.1: - version "1.3.3" - resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f" +regenerate-unicode-properties@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-7.0.0.tgz#107405afcc4a190ec5ed450ecaa00ed0cafa7a4c" + dependencies: + regenerate "^1.4.0" + +regenerate@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" regenerator-runtime@^0.11.0: version "0.11.0" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" -regenerator-transform@^0.10.0: - version "0.10.1" - resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd" +regenerator-transform@^0.13.3: + version "0.13.3" + resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.13.3.tgz#264bd9ff38a8ce24b06e0636496b2c856b57bcbb" dependencies: - babel-runtime "^6.18.0" - babel-types "^6.19.0" private "^0.1.6" regex-cache@^0.4.2: @@ -4065,21 +4084,24 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexpu-core@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" +regexpu-core@^4.1.3, regexpu-core@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.2.0.tgz#a3744fa03806cffe146dea4421a3e73bdcc47b1d" dependencies: - regenerate "^1.2.1" - regjsgen "^0.2.0" - regjsparser "^0.1.4" + regenerate "^1.4.0" + regenerate-unicode-properties "^7.0.0" + regjsgen "^0.4.0" + regjsparser "^0.3.0" + unicode-match-property-ecmascript "^1.0.4" + unicode-match-property-value-ecmascript "^1.0.2" -regjsgen@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" +regjsgen@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.4.0.tgz#c1eb4c89a209263f8717c782591523913ede2561" -regjsparser@^0.1.4: - version "0.1.5" - resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" +regjsparser@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.3.0.tgz#3c326da7fcfd69fa0d332575a41c8c0cdf588c96" dependencies: jsesc "~0.5.0" @@ -4374,6 +4396,10 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" +sisteransi@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-0.1.1.tgz#5431447d5f7d1675aac667ccd0b865a4994cb3ce" + slash@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" @@ -4460,7 +4486,7 @@ source-map@^0.4.4: dependencies: amdefine ">=0.0.4" -source-map@^0.5.3, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.6: +source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -4717,6 +4743,10 @@ to-fast-properties@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" +to-fast-properties@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" + to-object-path@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" @@ -4854,6 +4884,25 @@ unherit@^1.0.4: inherits "^2.0.1" xtend "^4.0.1" +unicode-canonical-property-names-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" + +unicode-match-property-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz#8ed2a32569961bce9227d09cd3ffbb8fed5f020c" + dependencies: + unicode-canonical-property-names-ecmascript "^1.0.4" + unicode-property-aliases-ecmascript "^1.0.4" + +unicode-match-property-value-ecmascript@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz#9f1dc76926d6ccf452310564fd834ace059663d4" + +unicode-property-aliases-ecmascript@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz#5a533f31b4317ea76f17d807fa0d116546111dd0" + unified@^4.1.1: version "4.2.1" resolved "https://registry.yarnpkg.com/unified/-/unified-4.2.1.tgz#76ff43aa8da430f6e7e4a55c84ebac2ad2cfcd2e" From 902bd9f94c2698ba70d0ebd192ba514c780034ec Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 10:10:54 +0200 Subject: [PATCH 05/21] build: upgrades typescript and tslint versions --- package.json | 4 ++-- yarn.lock | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 0baed44d32..a6abcd5519 100644 --- a/package.json +++ b/package.json @@ -98,8 +98,8 @@ "react-test-renderer": "16.4.1", "reflect-metadata": "^0.1.12", "rimraf": "^2.6.2", - "tslint": "^5.10.0", - "typescript": "^2.8.3" + "tslint": "^5.11.0", + "typescript": "^2.9.2" }, "lint-staged": { "*.js": [ diff --git a/yarn.lock b/yarn.lock index 2cdabcdd45..996c38f549 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4809,9 +4809,9 @@ tslib@^1.9.0: version "1.9.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.1.tgz#a5d1f0532a49221c87755cfcc89ca37197242ba7" -tslint@^5.10.0: - version "5.10.0" - resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.10.0.tgz#11e26bccb88afa02dd0d9956cae3d4540b5f54c3" +tslint@^5.11.0: + version "5.11.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed" dependencies: babel-code-frame "^6.22.0" builtin-modules "^1.1.1" @@ -4824,11 +4824,11 @@ tslint@^5.10.0: resolve "^1.3.2" semver "^5.3.0" tslib "^1.8.0" - tsutils "^2.12.1" + tsutils "^2.27.2" -tsutils@^2.12.1: - version "2.22.1" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.22.1.tgz#30450bd701be623b9e11a129df0c32322678461b" +tsutils@^2.27.2: + version "2.28.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.28.0.tgz#6bd71e160828f9d019b6f4e844742228f85169a1" dependencies: tslib "^1.8.1" @@ -4848,9 +4848,9 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -typescript@^2.8.3: - version "2.8.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" +typescript@^2.9.2: + version "2.9.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" ua-parser-js@^0.7.9: version "0.7.17" From 9a2d74f4e4871331f49f08fa6cf397e2fd411914 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 11:42:55 +0200 Subject: [PATCH 06/21] fix(html): correctly transforms html source when needed --- src/preprocessor.ts | 2 +- .../__snapshots__/html-transform.spec.ts.snap | 12 +++++--- tests/__tests__/html-transform.spec.ts | 29 +++++++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/preprocessor.ts b/src/preprocessor.ts index 851563e4d6..a5a04e8ad5 100644 --- a/src/preprocessor.ts +++ b/src/preprocessor.ts @@ -29,7 +29,7 @@ export function process( // This is to support angular 2. See https://github.com/kulshekhar/ts-jest/pull/145 if (isHtmlFile && jestConfig.globals.__TRANSFORM_HTML__) { - src = 'module.exports=`' + src + '`;'; + src = 'module.exports=' + JSON.stringify(src) + ';'; } const processFile = diff --git a/tests/__tests__/__snapshots__/html-transform.spec.ts.snap b/tests/__tests__/__snapshots__/html-transform.spec.ts.snap index bdea8378b9..1489c73e55 100644 --- a/tests/__tests__/__snapshots__/html-transform.spec.ts.snap +++ b/tests/__tests__/__snapshots__/html-transform.spec.ts.snap @@ -1,13 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Html transforms transforms html if config.globals.__TRANSFORM_HTML__ is set 1`] = ` -"module.exports=\`
+exports[`Html transforms transforms html if config.globals.__TRANSFORM_HTML__ is set: module 1`] = ` +"
This is element -
\`;" + This is a backtilt \` +
" `; -exports[`Html transforms transforms html if config.globals.__TRANSFORM_HTML__ is set 2`] = ` +exports[`Html transforms transforms html if config.globals.__TRANSFORM_HTML__ is set: source 1`] = `"module.exports=\\"
\\\\n This is element\\\\n This is a backtilt \`\\\\n
\\";"`; + +exports[`Html transforms transforms html if config.globals.__TRANSFORM_HTML__ is set: untransformed 1`] = ` "
This is element + This is a backtilt \`
" `; diff --git a/tests/__tests__/html-transform.spec.ts b/tests/__tests__/html-transform.spec.ts index 3a2ad22e0f..ec00cd8e09 100644 --- a/tests/__tests__/html-transform.spec.ts +++ b/tests/__tests__/html-transform.spec.ts @@ -1,19 +1,30 @@ import { process } from '../../src/preprocessor'; +const path = '/path/to/file.html'; +const config = { 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; + const source = `
This is element + This is a backtilt \`
`; -const path = '/path/to/file.html'; -const config = { - globals: { - __TRANSFORM_HTML__: true, - }, -}; describe('Html transforms', () => { it('transforms html if config.globals.__TRANSFORM_HTML__ is set', () => { - expect(process(source, path, config)).toMatchSnapshot(); - delete config.globals.__TRANSFORM_HTML__; - expect(process(source, path, config)).toMatchSnapshot(); + // get the untransformed version + const untransformed = process(source, path, config); + // ... then the one which should be transformed + config.globals.__TRANSFORM_HTML__ = true; + const transformed = process(source, path, config) as string; + // ... finally the result of a `require('module-with-transformed-version')` + const exported = wrap(transformed)(); + + expect(exported).toMatchSnapshot('module'); + expect(transformed).toMatchSnapshot('source'); + expect(untransformed).toMatchSnapshot('untransformed'); + // requiring the transformed version should return the same string as the untransformed version + expect(exported).toBe(untransformed); }); }); From e46caae881ed1a30f8ed2dede823c876f4b4403e Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 15:33:33 +0200 Subject: [PATCH 07/21] fix: big refactor + fixes (mainly cache key + coverage) --- index.d.ts | 11 ---- index.js | 15 ------ package.json | 12 ++--- preprocessor.js | 1 - scripts/tests.js | 10 ---- src/index.ts | 35 +++++++++++++ src/postprocess.ts | 35 +++++++------ src/{preprocessor.ts => preprocess.ts} | 43 +++------------- src/transpile-if-ts.ts | 23 --------- src/transpiler.ts | 5 +- src/{jest-types.ts => types.ts} | 38 ++++++-------- src/utils/constants.ts | 12 +++++ src/utils/get-babel-rc.ts | 50 +++++++++++++++++++ src/utils/get-cache-key.ts | 31 ++++++++++++ src/{utils.ts => utils/index.ts} | 14 +++--- src/{ => utils}/logger.ts | 0 tests/__tests__/get-cache-key.spec.ts | 11 ++-- tests/__tests__/transpiler.spec.ts | 21 ++++++-- tests/coverage-simple/.gitignore | 1 + tests/coverage-simple/Hello.ts | 28 +++++++++++ tests/coverage-simple/NullCoverage.js | 6 +++ tests/coverage-simple/__tests__/Hello.test.ts | 9 ++++ tests/coverage-simple/package.json | 22 ++++++++ tests/coverage-simple/tsconfig.json | 10 ++++ tests/coverage-simple/yarn.lock | 4 ++ tsconfig.build.json | 11 ++++ tsconfig.json | 7 +-- 27 files changed, 299 insertions(+), 166 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.js delete mode 100644 preprocessor.js create mode 100644 src/index.ts rename src/{preprocessor.ts => preprocess.ts} (65%) delete mode 100644 src/transpile-if-ts.ts rename src/{jest-types.ts => types.ts} (65%) create mode 100644 src/utils/constants.ts create mode 100644 src/utils/get-babel-rc.ts create mode 100644 src/utils/get-cache-key.ts rename src/{utils.ts => utils/index.ts} (94%) rename src/{ => utils}/logger.ts (100%) create mode 100644 tests/coverage-simple/.gitignore create mode 100644 tests/coverage-simple/Hello.ts create mode 100644 tests/coverage-simple/NullCoverage.js create mode 100644 tests/coverage-simple/__tests__/Hello.test.ts create mode 100644 tests/coverage-simple/package.json create mode 100644 tests/coverage-simple/tsconfig.json create mode 100644 tests/coverage-simple/yarn.lock create mode 100644 tsconfig.build.json diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 206d91423f..0000000000 --- a/index.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 13ad594168..0000000000 --- a/index.js +++ /dev/null @@ -1,15 +0,0 @@ -// 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 = { - getCacheKey: lazyRequire('getCacheKey'), - process: lazyRequire('process'), -}; diff --git a/package.json b/package.json index a6abcd5519..501a3327ef 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,18 @@ { "name": "ts-jest", "version": "23.0.1", - "main": "index.js", + "main": "dist/index.js", "types": "./dist/index.d.ts", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { - "build": "cpx index.d.ts dist/ && tsc -p .", - "build:watch": "cpx index.d.ts dist/ && tsc -p . -w", + "build": "tsc -p tsconfig.build.json", + "build:watch": "tsc -p tsconfig.build.json -w", "test:nolint": "npm run clean-build && node scripts/tests.js", - "clean": "rimraf dist/**/* && rimraf tests/simple/coverage && rimraf tests/simple-async/coverage && rimraf tests/**/*/debug.txt && rimraf tests/**/node_modules", + "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", "test": "node scripts/tests.js", - "tslint": "tslint src/*.ts", + "tslint": "tslint src/**/*.ts", "doc": "doctoc .", "prepublish": "npm run clean-build", "precommit": "lint-staged", @@ -38,7 +38,7 @@ "homepage": "https://github.com/kulshekhar/ts-jest#readme", "jest": { "transform": { - "^.+\\.tsx?$": "/dist/preprocessor.js" + "^.+\\.tsx?$": "/dist/index.js" }, "testRegex": "tests/__tests__/.*\\.spec\\.ts$", "testPathIgnorePatterns": [ diff --git a/preprocessor.js b/preprocessor.js deleted file mode 100644 index d56eb74241..0000000000 --- a/preprocessor.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./dist/preprocessor'); \ No newline at end of file diff --git a/scripts/tests.js b/scripts/tests.js index 3baec1dd28..36934fae5d 100644 --- a/scripts/tests.js +++ b/scripts/tests.js @@ -25,16 +25,6 @@ function createIntegrationMock() { const rootDir = path.resolve('.'); const testCaseModuleFolder = path.join(testCaseNodeModules, 'ts-jest'); - // Copy javascript files - fs.copySync( - path.resolve(rootDir, 'index.js'), - path.resolve(testCaseModuleFolder, 'index.js') - ); - fs.copySync( - path.resolve(rootDir, 'preprocessor.js'), - path.resolve(testCaseModuleFolder, 'preprocessor.js') - ); - // Copy package.json fs.copySync( path.resolve(rootDir, 'package.json'), diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000000..c49fd4fb34 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,35 @@ +// structure of this file heavilly inspired on: +// https://github.com/facebook/jest/blob/master/packages/babel-jest/src/index.js + +import jestPreset from 'babel-preset-jest'; +import getCacheKeyForArgs from './utils/get-cache-key'; +import { TsJestContext, JestCacheKeyArguments } from './types'; +import preprocess from './preprocess'; + +const createTransformer = (options?: any): jest.Transformer => { + const cache = Object.create(null); + + options = Object.assign({}, options, { + compact: false, + plugins: (options && options.plugins) || [], + presets: ((options && options.presets) || []).concat([jestPreset]), + sourceMaps: 'both', + }); + delete options.cacheDirectory; + delete options.filename; + + const context: TsJestContext = { cache, options }; + + const getCacheKey = (...args: any[]) => + getCacheKeyForArgs(args as JestCacheKeyArguments, context); + + return { + canInstrument: true, + getCacheKey, + process: preprocess, + createTransformer: undefined as any, + }; +}; + +export default createTransformer(); +export { createTransformer }; diff --git a/src/postprocess.ts b/src/postprocess.ts index b86e72d6cb..f91876d3ab 100644 --- a/src/postprocess.ts +++ b/src/postprocess.ts @@ -16,26 +16,24 @@ function importBabelDeps() { istanbulPlugin = require('babel-plugin-istanbul').default; jestPreset = require('babel-preset-jest'); } -import { CompilerOptions } from 'typescript/lib/typescript'; +import { CompilerOptions } from 'typescript'; import { BabelTransformOptions, - CodeSourceMapPair, - JestConfig, PostProcessHook, - TransformOptions, + JestCacheKeyOptions, TsJestConfig, -} from './jest-types'; -import { logOnce } from './logger'; +} from './types'; +import { logOnce } from './utils/logger'; // Function that takes the transpiled typescript and runs it through babel/whatever. export function postProcessCode( compilerOptions: CompilerOptions, - jestConfig: JestConfig, + jestConfig: jest.ProjectConfig, tsJestConfig: TsJestConfig, - transformOptions: TransformOptions, - transpileOutput: CodeSourceMapPair, + transformOptions: jest.TransformOptions, + transpileOutput: jest.TransformedSource, filePath: string, -): CodeSourceMapPair { +): jest.TransformedSource { const postHook = getPostProcessHook( compilerOptions, jestConfig, @@ -58,11 +56,11 @@ function createBabelTransformer( delete options.filename; return ( - codeSourcemapPair: CodeSourceMapPair, + codeSourcemapPair: jest.TransformedSource, filename: string, - config: JestConfig, - transformOptions: TransformOptions, - ): CodeSourceMapPair => { + config: jest.ProjectConfig, + transformOptions: JestCacheKeyOptions, + ): jest.TransformedSource => { const theseOptions = Object.assign( { filename, inputSourceMap: codeSourcemapPair.map }, options, @@ -81,17 +79,18 @@ function createBabelTransformer( ], ]); } - // Babel has incorrect typings, where the map is an object instead of a string. So we have to typecast it here - return (babel.transform( + + // we typecast here because babel returns a more complete object than the one expected by jest + return babel.transform( codeSourcemapPair.code, theseOptions, - ) as any) as CodeSourceMapPair; + ) as jest.TransformedSource; }; } export const getPostProcessHook = ( tsCompilerOptions: CompilerOptions, - jestConfig: JestConfig, + jestConfig: jest.ProjectConfig, tsJestConfig: TsJestConfig, ): PostProcessHook => { if (tsJestConfig.skipBabel) { diff --git a/src/preprocessor.ts b/src/preprocess.ts similarity index 65% rename from src/preprocessor.ts rename to src/preprocess.ts index a5a04e8ad5..748a2aca82 100644 --- a/src/preprocessor.ts +++ b/src/preprocess.ts @@ -1,22 +1,14 @@ -import * as crypto from 'crypto'; -import { - BabelTransformOptions, - CodeSourceMapPair, - JestConfig, - Path, - TransformOptions, -} from './jest-types'; -import { flushLogs, logOnce } from './logger'; +import { flushLogs, logOnce } from './utils/logger'; import { postProcessCode } from './postprocess'; import { getTSConfig, getTSJestConfig, runTsDiagnostics } from './utils'; import { transpileTypescript } from './transpiler'; -export function process( +export default function preprocess( src: string, - filePath: Path, - jestConfig: JestConfig, - transformOptions: TransformOptions = { instrument: false }, -): CodeSourceMapPair | string { + filePath: jest.Path, + jestConfig: jest.ProjectConfig, + transformOptions: jest.TransformOptions, +): jest.TransformedSource | string { // transformOptions.instrument is a proxy for collectCoverage // https://github.com/kulshekhar/ts-jest/issues/201#issuecomment-300572902 const compilerOptions = getTSConfig(jestConfig.globals, jestConfig.rootDir); @@ -28,7 +20,7 @@ export function process( const isHtmlFile = /\.html$/.test(filePath); // This is to support angular 2. See https://github.com/kulshekhar/ts-jest/pull/145 - if (isHtmlFile && jestConfig.globals.__TRANSFORM_HTML__) { + if (isHtmlFile && (jestConfig.globals as any).__TRANSFORM_HTML__) { src = 'module.exports=' + JSON.stringify(src) + ';'; } @@ -76,24 +68,3 @@ export function process( return { code: outputText.code, map: outputText.map }; } - -/** - * This is the function Jest uses to check if it has the file already in cache - */ -export function getCacheKey( - fileData: string, - filePath: Path, - jestConfigStr: string, - transformOptions: TransformOptions = { instrument: false }, -): string { - const jestConfig: JestConfig = JSON.parse(jestConfigStr); - - const tsConfig = getTSConfig(jestConfig.globals, jestConfig.rootDir); - - return crypto - .createHash('md5') - .update(JSON.stringify(tsConfig), 'utf8') - .update(JSON.stringify(transformOptions), 'utf8') - .update(fileData + filePath + jestConfigStr, 'utf8') - .digest('hex'); -} diff --git a/src/transpile-if-ts.ts b/src/transpile-if-ts.ts deleted file mode 100644 index 95a2640f0e..0000000000 --- a/src/transpile-if-ts.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as tsc from 'typescript'; -import { getTSConfig, mockGlobalTSConfigSchema } from './utils'; -import { ConfigGlobals } from './jest-types'; - -export function transpileIfTypescript( - path: string, - contents: string, - config?: ConfigGlobals, - rootDir: string = '', -): string { - if (path && (path.endsWith('.tsx') || path.endsWith('.ts'))) { - const transpiled = tsc.transpileModule(contents, { - compilerOptions: getTSConfig( - config || mockGlobalTSConfigSchema(global), - rootDir, - ), - fileName: path, - }); - - return transpiled.outputText; - } - return contents; -} diff --git a/src/transpiler.ts b/src/transpiler.ts index 06ce887b2b..8c6721d857 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -1,13 +1,12 @@ import * as ts from 'typescript'; -import { logOnce } from './logger'; -import { CodeSourceMapPair } from './jest-types'; +import { logOnce } from './utils/logger'; // Takes the typescript code and by whatever method configured, makes it into javascript code. export function transpileTypescript( filePath: string, fileSrc: string, compilerOptions: ts.CompilerOptions, -): CodeSourceMapPair { +): jest.TransformedSource { logOnce('Compiling via normal transpileModule call'); const transpileOutput = transpileViaTranspileModule( filePath, diff --git a/src/jest-types.ts b/src/types.ts similarity index 65% rename from src/jest-types.ts rename to src/types.ts index f3ff30693d..e6456852b1 100644 --- a/src/jest-types.ts +++ b/src/types.ts @@ -1,17 +1,22 @@ import { TransformOptions as BabelTransformOpts } from 'babel-core'; -export interface TransformOptions { +export interface JestCacheKeyOptions { + rootDir: string; instrument: boolean; } -export type Path = string; - -export type Glob = string; - -export interface ConfigGlobals { - [key: string]: any; +export interface TsJestContext { + cache: any; + options: any; } +export type JestCacheKeyArguments = [ + string, + string, + string, + JestCacheKeyOptions +]; + export interface HasteConfig { defaultPlatform?: string | null; hasteImplModulePath?: string; @@ -24,17 +29,11 @@ export interface BabelTransformOptions extends BabelTransformOpts { } export type PostProcessHook = ( - codeSourcemapPair: CodeSourceMapPair, + codeSourcemapPair: jest.TransformedSource, filePath: string, - config: JestConfig, - transformOptions: TransformOptions, -) => CodeSourceMapPair; - -export type JestConfig = jest.InitialOptions & { - globals?: jest.ConfigGlobals & { - __TRANSFORM_HTML__?: boolean; - }; -}; + config: jest.ProjectConfig, + transformOptions: jest.TransformOptions, +) => jest.TransformedSource; export interface TsJestConfig { babelConfig?: BabelTransformOpts; @@ -53,8 +52,3 @@ export interface JestConfigNormalize { hasDeprecationWarnings: boolean; options: jest.DefaultOptions; } - -export interface CodeSourceMapPair { - code: string; - map: string; -} diff --git a/src/utils/constants.ts b/src/utils/constants.ts new file mode 100644 index 0000000000..b8556ac8ac --- /dev/null +++ b/src/utils/constants.ts @@ -0,0 +1,12 @@ +import { readFileSync } from 'fs'; +import { resolve } from 'path'; + +export const BABELRC_FILENAME = '.babelrc'; +export const BABELRC_JS_FILENAME = '.babelrc.js'; +export const BABEL_CONFIG_KEY = 'babel'; +export const TSCONFIG_FILENAME = 'tsconfig.json'; +export const TSCONFIG_GLOBALS_KEY = 'ts-jest'; +export const PACKAGE_JSON = 'package.json'; +export const MY_PACKAGE_CONTENT = readFileSync( + resolve(__dirname, '..', '..', PACKAGE_JSON), +); diff --git a/src/utils/get-babel-rc.ts b/src/utils/get-babel-rc.ts new file mode 100644 index 0000000000..b4734513a9 --- /dev/null +++ b/src/utils/get-babel-rc.ts @@ -0,0 +1,50 @@ +import { readFileSync, existsSync } from 'fs'; +import { dirname, join, resolve } from 'path'; +import { + BABELRC_FILENAME, + BABELRC_JS_FILENAME, + PACKAGE_JSON, + BABEL_CONFIG_KEY, +} from './constants'; +import { TsJestContext } from '../types'; + +// ideally we'd get that from babel-jest if it was exported, +// this is a pure translation from js +export default function getBabelRC(filename, { cache }: TsJestContext) { + const paths = []; + let directory = filename; + // tslint:disable-next-line:no-conditional-assignment + while (directory !== (directory = dirname(directory))) { + if (cache[directory]) { + break; + } + + paths.push(directory); + const configFilePath = join(directory, BABELRC_FILENAME); + if (existsSync(configFilePath)) { + cache[directory] = readFileSync(configFilePath, 'utf8'); + break; + } + const configJsFilePath = join(directory, BABELRC_JS_FILENAME); + if (existsSync(configJsFilePath)) { + cache[directory] = JSON.stringify(require(configJsFilePath)); + break; + } + const resolvedJsonFilePath = join(directory, PACKAGE_JSON); + const packageJsonFilePath = + resolvedJsonFilePath === PACKAGE_JSON + ? resolve(directory, PACKAGE_JSON) + : resolvedJsonFilePath; + if (existsSync(packageJsonFilePath)) { + const packageJsonFileContents = require(packageJsonFilePath); + if (packageJsonFileContents[BABEL_CONFIG_KEY]) { + cache[directory] = JSON.stringify( + packageJsonFileContents[BABEL_CONFIG_KEY], + ); + break; + } + } + } + paths.forEach(directoryPath => (cache[directoryPath] = cache[directory])); + return cache[directory] || ''; +} diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts new file mode 100644 index 0000000000..d471bfe28d --- /dev/null +++ b/src/utils/get-cache-key.ts @@ -0,0 +1,31 @@ +import { createHash } from 'crypto'; +import { JestCacheKeyArguments, TsJestContext } from '../types'; +import { relative, resolve } from 'path'; +import { MY_PACKAGE_CONTENT } from './constants'; +import getBabelRC from './get-babel-rc'; +import { getTSConfig } from '.'; + +export default function getCacheKey( + args: JestCacheKeyArguments, + ctx: TsJestContext, +): string { + const [fileData, filePath, jestConfigString, { instrument, rootDir }] = args; + const glob = JSON.parse(jestConfigString).globals || {}; + return createHash('md5') + .update(MY_PACKAGE_CONTENT) + .update('\0', 'utf8') + .update(JSON.stringify(ctx.options)) + .update('\0', 'utf8') + .update(fileData) + .update('\0', 'utf8') + .update(relative(rootDir, filePath)) + .update('\0', 'utf8') + .update(jestConfigString) + .update('\0', 'utf8') + .update(JSON.stringify(getTSConfig(glob, rootDir))) + .update('\0', 'utf8') + .update(getBabelRC(filePath, ctx)) + .update('\0', 'utf8') + .update(instrument ? 'instrument' : '') + .digest('hex'); +} diff --git a/src/utils.ts b/src/utils/index.ts similarity index 94% rename from src/utils.ts rename to src/utils/index.ts index 8b9b03c198..a2c68b3365 100644 --- a/src/utils.ts +++ b/src/utils/index.ts @@ -3,12 +3,12 @@ import * as fs from 'fs'; import * as fsExtra from 'fs-extra'; import * as path from 'path'; import * as tsc from 'typescript'; -import { ConfigGlobals, JestConfig, TsJestConfig } from './jest-types'; +import { TsJestConfig } from '../types'; import { logOnce } from './logger'; import * as _ from 'lodash'; -export function getTSJestConfig(globals: ConfigGlobals): TsJestConfig { - return globals && globals['ts-jest'] ? globals['ts-jest'] : {}; +export function getTSJestConfig(globals: jest.ConfigGlobals): TsJestConfig { + return (globals && globals['ts-jest']) || {}; } function formatTsDiagnostics(errors: tsc.Diagnostic[]): string { @@ -88,7 +88,7 @@ function getPathToClosestTSConfig( } function getTSConfigPathFromConfig( - globals: ConfigGlobals, + globals: jest.ConfigGlobals, rootDir?: string, ): string { const defaultTSConfigFile = getPathToClosestTSConfig(rootDir); @@ -106,8 +106,8 @@ function getTSConfigPathFromConfig( } export function mockGlobalTSConfigSchema( - globals: ConfigGlobals, -): ConfigGlobals { + globals: jest.ConfigGlobals, +): jest.ConfigGlobals { const configPath = getTSConfigPathFromConfig(globals); return { 'ts-jest': { tsConfigFile: configPath } }; } @@ -161,7 +161,7 @@ function getTSConfig_local(globals, rootDir: string = '') { } export function cacheFile( - jestConfig: JestConfig, + jestConfig: jest.ProjectConfig, filePath: string, src: string, ): void { diff --git a/src/logger.ts b/src/utils/logger.ts similarity index 100% rename from src/logger.ts rename to src/utils/logger.ts diff --git a/tests/__tests__/get-cache-key.spec.ts b/tests/__tests__/get-cache-key.spec.ts index a85885b9e6..43e3e2e7a4 100644 --- a/tests/__tests__/get-cache-key.spec.ts +++ b/tests/__tests__/get-cache-key.spec.ts @@ -1,6 +1,9 @@ -import { getCacheKey } from '../../src/preprocessor'; -import { TransformOptions } from '../../src/jest-types'; +import getCacheKeyForArgs from '../../dist/utils/get-cache-key'; +import { TsJestContext } from '../../dist/types'; +const tsJestContext: TsJestContext = { cache: {}, options: {} }; +const getCacheKey = (...args: any[]) => + getCacheKeyForArgs(args as any, tsJestContext); describe('getCacheKey', () => { const src = 'console.log(123);'; const filepath = '/tmp/filepath'; @@ -18,7 +21,7 @@ describe('getCacheKey', () => { }, "testRegex": "(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$" }`; - const options: TransformOptions = { instrument: false }; + const options: jest.TransformOptions = { instrument: false }; const originalHash = getCacheKey(src, filepath, configStr, options); it('should change hash when src changes', () => { @@ -40,7 +43,7 @@ describe('getCacheKey', () => { }); it('should change hash when transform options change', () => { - const newOptions: TransformOptions = { instrument: true }; + const newOptions: jest.TransformOptions = { instrument: true }; const newHash = getCacheKey(src, filepath, configStr, newOptions); expect(newHash).not.toBe(originalHash); }); diff --git a/tests/__tests__/transpiler.spec.ts b/tests/__tests__/transpiler.spec.ts index abaab22f45..4e10add7dc 100644 --- a/tests/__tests__/transpiler.spec.ts +++ b/tests/__tests__/transpiler.spec.ts @@ -2,22 +2,33 @@ import { transpileTypescript } from '../../src/transpiler'; import * as ts from 'typescript'; describe('transpileTypescript', () => { - - const compilerOptions: ts.CompilerOptions = {newLine: ts.NewLineKind.LineFeed}; + const compilerOptions: ts.CompilerOptions = { + newLine: ts.NewLineKind.LineFeed, + }; it('should transpile valid TS syntax', () => { - const result = transpileTypescript('valid.ts', 'var a = true;', compilerOptions); + const result = transpileTypescript( + 'valid.ts', + 'var a = true;', + compilerOptions, + ); expect(result.code).toBe('var a = true;\n'); }); it('should transpile valid TS syntax with type errors', () => { - const result = transpileTypescript('valid.ts', 'var a: string = true;', compilerOptions); + const result = transpileTypescript( + 'valid.ts', + 'var a: string = true;', + compilerOptions, + ); expect(result.code).toBe('var a = true;\n'); }); it('should throw an error when transpiling invalid TS syntax', () => { expect(() => { transpileTypescript('invalid.ts', 'var a = ;', compilerOptions); - }).toThrow('TypeScript compiler encountered syntax errors while transpiling. Errors: Expression expected.'); + }).toThrow( + 'TypeScript compiler encountered syntax errors while transpiling. Errors: Expression expected.', + ); }); }); diff --git a/tests/coverage-simple/.gitignore b/tests/coverage-simple/.gitignore new file mode 100644 index 0000000000..9e233d795a --- /dev/null +++ b/tests/coverage-simple/.gitignore @@ -0,0 +1 @@ +coverage-custom diff --git a/tests/coverage-simple/Hello.ts b/tests/coverage-simple/Hello.ts new file mode 100644 index 0000000000..3eaae5c40d --- /dev/null +++ b/tests/coverage-simple/Hello.ts @@ -0,0 +1,28 @@ +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 new file mode 100644 index 0000000000..c59dbbdef3 --- /dev/null +++ b/tests/coverage-simple/NullCoverage.js @@ -0,0 +1,6 @@ +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 new file mode 100644 index 0000000000..3df75018f9 --- /dev/null +++ b/tests/coverage-simple/__tests__/Hello.test.ts @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000000..c577a32b44 --- /dev/null +++ b/tests/coverage-simple/package.json @@ -0,0 +1,22 @@ +{ + "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 new file mode 100644 index 0000000000..55f8667f97 --- /dev/null +++ b/tests/coverage-simple/tsconfig.json @@ -0,0 +1,10 @@ +{ + "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 new file mode 100644 index 0000000000..fb57ccd13a --- /dev/null +++ b/tests/coverage-simple/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000000..4eecabd0b4 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "sourceMap": false, + "removeComments": true, + "outDir": "dist", + "rootDir": "src", + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/tsconfig.json b/tsconfig.json index d5b6e37db0..d1a8c133ba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "sourceMap": false, + "inlineSourceMap": true, "declaration": true, "target": "es5", "module": "commonjs", @@ -11,17 +12,13 @@ "noImplicitReturns": true, "removeComments": true, "strictNullChecks": false, - "inlineSourceMap": true, "jsx": "react", "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": false, - "outDir": "dist", - "rootDir": "src", "skipLibCheck": true, "lib": ["es2015"], "types": ["jest"] }, - "include": ["src/**/*.ts", "src/**/*.tsx"], - "exclude": ["node_modules"] + "exclude": ["**/node_modules/**/*"] } From 09500c2f3fa60617c04370802fed5ceffa791778 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 19 Jul 2018 17:08:37 +0200 Subject: [PATCH 08/21] fix: fixes coverage and tests --- package.json | 2 +- src/index.ts | 5 ++-- src/utils/get-cache-key.ts | 7 ++++- src/utils/logger.ts | 2 +- .../ts-coverage-async.spec.ts.snap | 12 ++++++++ .../__snapshots__/ts-coverage.spec.ts.snap | 12 ++++++++ tests/__tests__/html-transform.spec.ts | 10 +++---- tests/__tests__/postprocess.spec.ts | 23 +++++++++------ tests/__tests__/transpile-if-ts.spec.ts | 23 --------------- tests/__tests__/ts-coverage-async.spec.ts | 5 +--- tests/__tests__/ts-coverage.spec.ts | 5 +--- tests/button/package.json | 2 +- tests/coverage-simple/.gitignore | 1 - tests/coverage-simple/Hello.ts | 28 ------------------- tests/coverage-simple/NullCoverage.js | 6 ---- tests/coverage-simple/__tests__/Hello.test.ts | 9 ------ tests/coverage-simple/package.json | 22 --------------- tests/coverage-simple/tsconfig.json | 10 ------- tests/coverage-simple/yarn.lock | 4 --- .../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 | 2 +- tests/metadata-emit/package.json | 2 +- tests/no-synthetic-default/package.json | 2 +- tests/simple-async/package.json | 2 +- tests/simple-long-path/package.json | 2 +- tests/skip-babelrc/package.json | 2 +- tests/synthetic-default/package.json | 2 +- tests/ts-diagnostics/package.json | 2 +- .../ts-jest-module-interface.test.ts | 8 +++++- tests/use-babelrc/package.json | 2 +- tests/use-strict/package.json | 2 +- tests/watch-test/package.json | 2 +- tslint.json | 6 ++++ 36 files changed, 85 insertions(+), 147 deletions(-) create mode 100644 tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap create mode 100644 tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap delete mode 100644 tests/__tests__/transpile-if-ts.spec.ts delete mode 100644 tests/coverage-simple/.gitignore delete mode 100644 tests/coverage-simple/Hello.ts delete mode 100644 tests/coverage-simple/NullCoverage.js delete mode 100644 tests/coverage-simple/__tests__/Hello.test.ts delete mode 100644 tests/coverage-simple/package.json delete mode 100644 tests/coverage-simple/tsconfig.json delete mode 100644 tests/coverage-simple/yarn.lock 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/**/*" + ] } } From 691720f0b36b1db121bc421376d52be7a8e29e73 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 23 Jul 2018 14:02:51 +0200 Subject: [PATCH 09/21] chore: refactor to cleanup and use only "new" jest api --- package.json | 4 + scripts/tests.js | 3 + src/index.ts | 32 +-- src/postprocess.ts | 42 ++-- src/preprocess.ts | 16 +- src/types.ts | 7 - src/utils/cache-file.ts | 38 ++++ src/utils/format-diagnostics.ts | 16 ++ src/utils/get-babel-rc.ts | 55 ++--- src/utils/get-cache-key.ts | 40 ++-- src/utils/get-ts-config.ts | 129 +++++++++++ src/utils/get-ts-jest-config.ts | 8 + src/utils/index.ts | 193 ---------------- src/utils/run-ts-diagnostics.ts | 18 ++ tests/__helpers__/jest-config.ts | 210 ++++++++++++++++++ tests/__helpers__/utils.ts | 1 + .../tsconfig-comments.spec.ts.snap | 29 +++ .../tsconfig-default.spec.ts.snap | 19 ++ .../tsconfig-string.spec.ts.snap | 50 +++++ tests/__tests__/debug.spec.ts | 4 +- tests/__tests__/get-cache-key.spec.ts | 46 ++-- tests/__tests__/html-transform.spec.ts | 12 +- tests/__tests__/postprocess.spec.ts | 32 ++- tests/__tests__/transpiler.spec.ts | 2 +- tests/__tests__/tsconfig-comments.spec.ts | 39 ++-- tests/__tests__/tsconfig-default.spec.ts | 102 +++------ tests/__tests__/tsconfig-string.spec.ts | 99 ++------- .../ts-jest-module-interface.test.ts | 2 +- tests/tsconfig-test/allows-comments2.json | 2 +- tests/utils/test-utils.ts | 4 +- yarn.lock | 18 ++ 31 files changed, 729 insertions(+), 543 deletions(-) create mode 100644 src/utils/cache-file.ts create mode 100644 src/utils/format-diagnostics.ts create mode 100644 src/utils/get-ts-config.ts create mode 100644 src/utils/get-ts-jest-config.ts delete mode 100644 src/utils/index.ts create mode 100644 src/utils/run-ts-diagnostics.ts create mode 100644 tests/__helpers__/jest-config.ts create mode 100644 tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap create mode 100644 tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap create mode 100644 tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap diff --git a/package.json b/package.json index 5a44dae15b..34fc935265 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "clean-build": "npm run clean && npm run build", "pretest": "npm run tslint && npm run clean-build", "test": "node scripts/tests.js", + "test:unit": "jest --testRegex '' --testMatch '/src/**/*.spec.ts'", "tslint": "tslint src/**/*.ts", "doc": "doctoc .", "prepublish": "npm run clean-build", @@ -62,6 +63,7 @@ ] }, "dependencies": { + "closest-file-data": "^0.1.4", "cpx": "^1.5.0", "fs-extra": "6.0.1", "jest-config": "^23.4.1", @@ -79,6 +81,7 @@ "@babel/preset-env": "^7.0.0-beta.54", "@types/babel-core": "^6.25.5", "@types/es6-shim": "0.31.37", + "@types/flat": "^0.0.28", "@types/fs-extra": "5.0.4", "@types/jest": "^23.3.0", "@types/lodash": "^4.14.109", @@ -90,6 +93,7 @@ "cross-spawn": "latest", "cross-spawn-with-kill": "latest", "doctoc": "latest", + "flat": "^4.1.0", "husky": "^0.14.3", "jest": "^23.4.1", "lint-staged": "^7.1.2", diff --git a/scripts/tests.js b/scripts/tests.js index 36934fae5d..9ccb16e8ee 100644 --- a/scripts/tests.js +++ b/scripts/tests.js @@ -41,6 +41,9 @@ function createIntegrationMock() { createIntegrationMock(); +// HACK: allow us to change the `startDir()` during tests +process.env.__RUNNING_TS_JEST_TESTS = Date.now(); + const argv = process.argv.slice(2); argv.push('--no-cache'); argv.push('--testPathPattern', '^(?!(.*watch.spec.ts$)).*'); diff --git a/src/index.ts b/src/index.ts index 3cc76e8b77..e51d91e016 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,27 +1,17 @@ -// structure of this file heavilly inspired on: -// https://github.com/facebook/jest/blob/master/packages/babel-jest/src/index.js - -import jestPreset from 'babel-preset-jest'; -import getCacheKeyForArgs from './utils/get-cache-key'; -import { TsJestContext, JestCacheKeyArguments } from './types'; +import getCacheKey from './utils/get-cache-key'; import preprocess from './preprocess'; +//FIXME: options is always empty const createTransformer = (options?: any): jest.Transformer => { - const cache = Object.create(null); - - options = Object.assign({}, options, { - compact: false, - plugins: (options && options.plugins) || [], - presets: ((options && options.presets) || []).concat([jestPreset]), - sourceMaps: 'both', - }); - delete options.cacheDirectory; - delete options.filename; - - const context: TsJestContext = { cache, options }; - - const getCacheKey = (...args: any[]) => - getCacheKeyForArgs(args as JestCacheKeyArguments, context); + // const cache = Object.create(null); + // options = Object.assign({}, options, { + // compact: false, + // plugins: (options && options.plugins) || [], + // presets: ((options && options.presets) || []).concat([jestPreset]), + // sourceMaps: 'both', + // }); + // delete options.cacheDirectory; + // delete options.filename; return { canInstrument: true, diff --git a/src/postprocess.ts b/src/postprocess.ts index f91876d3ab..5c86152bde 100644 --- a/src/postprocess.ts +++ b/src/postprocess.ts @@ -9,36 +9,28 @@ let babel: typeof __types__babel; let istanbulPlugin: typeof __types__istanbulPlugin; let jestPreset: typeof __types__jestPreset; function importBabelDeps() { - if (babel) { - return; - } - babel = require('@babel/core'); - istanbulPlugin = require('babel-plugin-istanbul').default; - jestPreset = require('babel-preset-jest'); + if (babel) return; // tslint:ignore-line + // ensure we use the require from jest + babel = require.main.require('@babel/core'); + istanbulPlugin = require.main.require('babel-plugin-istanbul').default; + jestPreset = require.main.require('babel-preset-jest'); } -import { CompilerOptions } from 'typescript'; import { BabelTransformOptions, PostProcessHook, JestCacheKeyOptions, - TsJestConfig, } from './types'; import { logOnce } from './utils/logger'; +import getTSJestConfig from './utils/get-ts-jest-config'; // Function that takes the transpiled typescript and runs it through babel/whatever. export function postProcessCode( - compilerOptions: CompilerOptions, jestConfig: jest.ProjectConfig, - tsJestConfig: TsJestConfig, transformOptions: jest.TransformOptions, transpileOutput: jest.TransformedSource, filePath: string, ): jest.TransformedSource { - const postHook = getPostProcessHook( - compilerOptions, - jestConfig, - tsJestConfig, - ); + const postHook = getPostProcessHook(jestConfig); return postHook(transpileOutput, filePath, jestConfig, transformOptions); } @@ -89,29 +81,29 @@ function createBabelTransformer( } export const getPostProcessHook = ( - tsCompilerOptions: CompilerOptions, jestConfig: jest.ProjectConfig, - tsJestConfig: TsJestConfig, ): PostProcessHook => { + const tsJestConfig = getTSJestConfig(jestConfig); if (tsJestConfig.skipBabel) { logOnce('Not using any postprocess hook.'); // Identity function return input => input; } - const plugins = Array.from( - (tsJestConfig.babelConfig && tsJestConfig.babelConfig.plugins) || [], - ); - + const tsJestBabelConfig = tsJestConfig.babelConfig || {}; const babelOptions: BabelTransformOptions = { - ...tsJestConfig.babelConfig, + ...tsJestBabelConfig, babelrc: tsJestConfig.useBabelrc || false, - plugins, - presets: tsJestConfig.babelConfig ? tsJestConfig.babelConfig.presets : [], - sourceMaps: tsJestConfig.disableSourceMapSupport !== true, + plugins: toArray(tsJestBabelConfig.plugins), + presets: toArray(tsJestBabelConfig.presets), + sourceMaps: !tsJestConfig.disableSourceMapSupport, }; logOnce('Using babel with options:', babelOptions); return createBabelTransformer(babelOptions); }; + +function toArray(iter?: Iterable | null): Array { + return iter ? Array.from(iter) : []; +} diff --git a/src/preprocess.ts b/src/preprocess.ts index 748a2aca82..f350e0a33b 100644 --- a/src/preprocess.ts +++ b/src/preprocess.ts @@ -1,17 +1,19 @@ import { flushLogs, logOnce } from './utils/logger'; import { postProcessCode } from './postprocess'; -import { getTSConfig, getTSJestConfig, runTsDiagnostics } from './utils'; import { transpileTypescript } from './transpiler'; +import runTsDiagnostics from './utils/run-ts-diagnostics'; +import getTSConfig from './utils/get-ts-config'; +import getTSJestConfig from './utils/get-ts-jest-config'; export default function preprocess( src: string, filePath: jest.Path, jestConfig: jest.ProjectConfig, - transformOptions: jest.TransformOptions, + transformOptions?: jest.TransformOptions, ): jest.TransformedSource | string { // transformOptions.instrument is a proxy for collectCoverage // https://github.com/kulshekhar/ts-jest/issues/201#issuecomment-300572902 - const compilerOptions = getTSConfig(jestConfig.globals, jestConfig.rootDir); + const compilerOptions = getTSConfig(jestConfig); logOnce('final compilerOptions:', compilerOptions); @@ -31,7 +33,7 @@ export default function preprocess( return src; } - const tsJestConfig = getTSJestConfig(jestConfig.globals); + const tsJestConfig = getTSJestConfig(jestConfig); logOnce('tsJestConfig: ', tsJestConfig); // We can potentially do this faster by using the language service. @@ -44,21 +46,19 @@ export default function preprocess( if (tsJestConfig.ignoreCoverageForAllDecorators === true) { transpileOutput.code = transpileOutput.code.replace( - /__decorate/g, + /\b__decorate\b/g, '/* istanbul ignore next */__decorate', ); } if (tsJestConfig.ignoreCoverageForDecorators === true) { transpileOutput.code = transpileOutput.code.replace( - /(__decorate\(\[\r?\n[^\n\r]*)\/\*\s*istanbul\s*ignore\s*decorator(.*)\*\//g, + /(\b__decorate\(\[\r?\n[^\n\r]*)\/\*\s*istanbul\s+ignore\s+decorator(.*)\*\//g, '/* istanbul ignore next$2*/$1', ); } const outputText = postProcessCode( - compilerOptions, jestConfig, - tsJestConfig, transformOptions, transpileOutput, filePath, diff --git a/src/types.ts b/src/types.ts index e6456852b1..5e65556867 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,13 +10,6 @@ export interface TsJestContext { options: any; } -export type JestCacheKeyArguments = [ - string, - string, - string, - JestCacheKeyOptions -]; - export interface HasteConfig { defaultPlatform?: string | null; hasteImplModulePath?: string; diff --git a/src/utils/cache-file.ts b/src/utils/cache-file.ts new file mode 100644 index 0000000000..ae2de1eb49 --- /dev/null +++ b/src/utils/cache-file.ts @@ -0,0 +1,38 @@ +import { join } from 'path'; +import { createHash } from 'crypto'; +import { outputFileSync } from 'fs-extra'; +import { memoize } from 'lodash'; + +// to use the same compiled regexp object all the time +// See https://jsperf.com/string-match-str-re/1 +const memoizedRegexp = memoize(RegExp); +const cachedTest = ( + reString: string | undefined | null, + subject: string, +): boolean => { + if (reString == null) { + return false; + } + return memoizedRegexp(reString).test(subject); +}; + +const cachedMd5 = memoize((path: string) => + createHash('md5') + .update(path) + .digest('hex'), +); + +// FIXME: I think there is testRegexp and testMatch in Jest configugation +// There is a default setting for that, but maybe it's defaulted from scratch +export function cacheFile( + jestConfig: jest.ProjectConfig, + filePath: string, + src: string, +): void { + // store transpiled code contains source map into cache, except test cases + if (!cachedTest(jestConfig.testRegex, filePath)) { + const hash = cachedMd5(filePath); + const outputFilePath = join(jestConfig.cacheDirectory, 'ts-jest', hash); + outputFileSync(outputFilePath, src); + } +} diff --git a/src/utils/format-diagnostics.ts b/src/utils/format-diagnostics.ts new file mode 100644 index 0000000000..e6911fb6f7 --- /dev/null +++ b/src/utils/format-diagnostics.ts @@ -0,0 +1,16 @@ +import { + sys, + Diagnostic, + FormatDiagnosticsHost, + formatDiagnostics, +} from 'typescript'; + +export default function formatTsDiagnostics(errors: Diagnostic[]): string { + const defaultFormatHost: FormatDiagnosticsHost = { + getCurrentDirectory: () => sys.getCurrentDirectory(), + getCanonicalFileName: fileName => fileName, + getNewLine: () => sys.newLine, + }; + + return formatDiagnostics(errors, defaultFormatHost); +} diff --git a/src/utils/get-babel-rc.ts b/src/utils/get-babel-rc.ts index b4734513a9..c49e799531 100644 --- a/src/utils/get-babel-rc.ts +++ b/src/utils/get-babel-rc.ts @@ -1,50 +1,23 @@ -import { readFileSync, existsSync } from 'fs'; -import { dirname, join, resolve } from 'path'; +import closestFileData from 'closest-file-data'; +import { readFileSync } from 'fs'; import { BABELRC_FILENAME, BABELRC_JS_FILENAME, PACKAGE_JSON, BABEL_CONFIG_KEY, } from './constants'; -import { TsJestContext } from '../types'; +import { BabelTransformOptions } from '../types'; -// ideally we'd get that from babel-jest if it was exported, -// this is a pure translation from js -export default function getBabelRC(filename, { cache }: TsJestContext) { - const paths = []; - let directory = filename; - // tslint:disable-next-line:no-conditional-assignment - while (directory !== (directory = dirname(directory))) { - if (cache[directory]) { - break; - } +const babelReaders = [ + { + basename: BABELRC_FILENAME, + read: f => JSON.parse(readFileSync(f, 'utf8')), + }, + { basename: BABELRC_JS_FILENAME, read: f => require(f) }, + { basename: PACKAGE_JSON, read: f => require(f)[BABEL_CONFIG_KEY] }, +]; - paths.push(directory); - const configFilePath = join(directory, BABELRC_FILENAME); - if (existsSync(configFilePath)) { - cache[directory] = readFileSync(configFilePath, 'utf8'); - break; - } - const configJsFilePath = join(directory, BABELRC_JS_FILENAME); - if (existsSync(configJsFilePath)) { - cache[directory] = JSON.stringify(require(configJsFilePath)); - break; - } - const resolvedJsonFilePath = join(directory, PACKAGE_JSON); - const packageJsonFilePath = - resolvedJsonFilePath === PACKAGE_JSON - ? resolve(directory, PACKAGE_JSON) - : resolvedJsonFilePath; - if (existsSync(packageJsonFilePath)) { - const packageJsonFileContents = require(packageJsonFilePath); - if (packageJsonFileContents[BABEL_CONFIG_KEY]) { - cache[directory] = JSON.stringify( - packageJsonFileContents[BABEL_CONFIG_KEY], - ); - break; - } - } - } - paths.forEach(directoryPath => (cache[directoryPath] = cache[directory])); - return cache[directory] || ''; +export default function getBabelRC(filename): babel.BabylonOptions | void { + const res = closestFileData(filename, babelReaders); + return res && res.data; } diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts index 9302b791ba..2ec8304e78 100644 --- a/src/utils/get-cache-key.ts +++ b/src/utils/get-cache-key.ts @@ -1,36 +1,34 @@ import { createHash } from 'crypto'; -import { JestCacheKeyArguments, TsJestContext } from '../types'; -import { relative, resolve } from 'path'; +import { JestCacheKeyOptions } from '../types'; +import { relative } from 'path'; import { MY_PACKAGE_CONTENT } from './constants'; import getBabelRC from './get-babel-rc'; -import { getTSConfig } from '.'; +import getTSConfig from './get-ts-config'; +// FIXME: remove dependency on config, it's empty export default function getCacheKey( - args: JestCacheKeyArguments, - ctx: TsJestContext, + fileData: string, + filePath: string, + jestConfigString: string, + { instrument, rootDir }: JestCacheKeyOptions, ): string { - const [ - fileData, - filePath, - jestConfigString, - { instrument = false, rootDir = process.cwd() } = {}, - ] = args; - const glob = JSON.parse(jestConfigString).globals || {}; - return createHash('md5') + const jestConfig: jest.ProjectConfig = JSON.parse(jestConfigString) || {}; + delete jestConfig.cacheDirectory; + delete jestConfig.name; + const hash = createHash('md5') .update(MY_PACKAGE_CONTENT) .update('\0', 'utf8') - .update(JSON.stringify(ctx.options)) - .update('\0', 'utf8') .update(fileData) .update('\0', 'utf8') .update(relative(rootDir, filePath)) .update('\0', 'utf8') .update(jestConfigString) .update('\0', 'utf8') - .update(JSON.stringify(getTSConfig(glob, rootDir))) - .update('\0', 'utf8') - .update(getBabelRC(filePath, ctx)) - .update('\0', 'utf8') - .update(instrument ? 'instrument' : '') - .digest('hex'); + .update(JSON.stringify(getTSConfig(jestConfig))) + .update('\0', 'utf8'); + const babelRc = getBabelRC(filePath); + if (babelRc) { + hash.update(JSON.stringify(babelRc)).update('\0', 'utf8'); + } + return hash.update(instrument ? 'instrument' : '').digest('hex'); } diff --git a/src/utils/get-ts-config.ts b/src/utils/get-ts-config.ts new file mode 100644 index 0000000000..903a104b41 --- /dev/null +++ b/src/utils/get-ts-config.ts @@ -0,0 +1,129 @@ +import { TSCONFIG_FILENAME } from './constants'; +import { + CompilerOptions, + readConfigFile, + sys, + parseJsonConfigFileContent, + ModuleKind, + JsxEmit, +} from 'typescript'; +import { resolve, sep } from 'path'; +import formatTsDiagnostics from './format-diagnostics'; +import closestFileData, { IClosestDataResult } from 'closest-file-data'; +import { memoize } from 'lodash'; +import { logOnce } from './logger'; +import getTSJestConfig from './get-ts-jest-config'; + +const getTSConfig = memoize(getTSConfig_local, jestConfig => { + // check cache before resolving configuration + // NB: We use JSON.stringify() to create a consistent, unique signature. Although it lacks a uniform + // shape, this is simpler and faster than using the crypto package to generate a hash signature. + return JSON.stringify(jestConfig); +}); +export default getTSConfig; + +// Non-memoized version of TSConfig +function getTSConfig_local(jestConfig: jest.ProjectConfig): CompilerOptions { + const configMeta = findTSConfigPath(jestConfig); + if (!configMeta) { + throw new ReferenceError( + `[ts-jest] Unable to find TS configuration file given current configuration`, + ); + } + const { path: configPath } = configMeta; + logOnce(`Reading tsconfig file from path ${configPath}`); + + const config = readCompilerOptions(configPath, jestConfig.rootDir); + logOnce('Original typescript config before modifications: ', { ...config }); + + // tsc should not emit declaration map when used for tests + // disable some options that might break jest + config.declaration = false; + config.declarationMap = false; + config.emitDeclarationOnly = false; + + // ts-jest will map lines numbers properly if inlineSourceMap and + // inlineSources are set to true. The sourceMap configuration + // is used to send the sourcemap back to Jest + delete config.sourceMap; + config.inlineSourceMap = true; + config.inlineSources = true; + + // the coverage report is broken if `.outDir` is set + // see https://github.com/kulshekhar/ts-jest/issues/201 + // `.outDir` is removed even for test files as it affects with breakpoints + // see https://github.com/kulshekhar/ts-jest/issues/309 + delete config.outDir; + delete config.outFile; + + if (!configMeta.isUserDefined) { + // hardcode module to 'commonjs' in case the config is being loaded + // from the default tsconfig file. This is to ensure that coverage + // works well. If there's a need to override, it can be done using + // a custom tsconfig for testing + config.module = ModuleKind.CommonJS; + } + + config.module = config.module || ModuleKind.CommonJS; + config.jsx = config.jsx || JsxEmit.React; + + return config; +} + +function readCompilerOptions( + configPath: string, + rootDir: string, +): CompilerOptions { + configPath = resolve(rootDir, configPath); + const { config, error } = readConfigFile(configPath, sys.readFile); + if (error) { + throw error; + } + + const { errors, options } = parseJsonConfigFileContent( + config, + sys, + resolve(rootDir), + ); + + if (errors.length > 0) { + const formattedErrors = formatTsDiagnostics(errors); + throw new Error( + `Some errors occurred while attempting to read from ${configPath}: ${formattedErrors}`, + ); + } + + return options; +} + +// function getStartDir(jestConfig: jest.ProjectConfig): string { +// // This is needed because of the way our tests are structured. +// // If this is being executed as a library (under node_modules) +// // we want to start with the project directory that's three +// // levels above. +// // If this is being executed from the test suite, we want to start +// // in the directory of the test + +// // TODO: shouldn't we use the path of jest config here instead of '.' ? +// // return process.env.__RUNNING_TS_JEST_TESTS ? process.cwd() : '.'; +// return process.env.__RUNNING_TS_JEST_TESTS ? process.cwd() : (jestConfig.rootDir || process.cwd()); +// } + +// we don't need any data, just its full path +const tsConfigReader = { basename: TSCONFIG_FILENAME, read: () => null }; + +function findTSConfigPath( + jestConfig: jest.ProjectConfig, +): { isUserDefined?: boolean; path: string } | void { + let tsConfigFile = getTSJestConfig(jestConfig).tsConfigFile; + if (tsConfigFile) { + tsConfigFile = tsConfigFile.replace( + '', + `${jestConfig.rootDir}${sep}`, + ); + tsConfigFile = resolve(jestConfig.rootDir, tsConfigFile); + return { path: tsConfigFile, isUserDefined: true }; + } + + return closestFileData(jestConfig.rootDir, tsConfigReader); +} diff --git a/src/utils/get-ts-jest-config.ts b/src/utils/get-ts-jest-config.ts new file mode 100644 index 0000000000..9cf5736c95 --- /dev/null +++ b/src/utils/get-ts-jest-config.ts @@ -0,0 +1,8 @@ +import { TSCONFIG_GLOBALS_KEY } from './constants'; +import { TsJestConfig } from '../types'; + +export default function getTSJestConfig( + jestConfig: jest.ProjectConfig | jest.InitialOptions, +): TsJestConfig { + return (jestConfig.globals && jestConfig.globals[TSCONFIG_GLOBALS_KEY]) || {}; +} diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index a2c68b3365..0000000000 --- a/src/utils/index.ts +++ /dev/null @@ -1,193 +0,0 @@ -import * as crypto from 'crypto'; -import * as fs from 'fs'; -import * as fsExtra from 'fs-extra'; -import * as path from 'path'; -import * as tsc from 'typescript'; -import { TsJestConfig } from '../types'; -import { logOnce } from './logger'; -import * as _ from 'lodash'; - -export function getTSJestConfig(globals: jest.ConfigGlobals): TsJestConfig { - return (globals && globals['ts-jest']) || {}; -} - -function formatTsDiagnostics(errors: tsc.Diagnostic[]): string { - const defaultFormatHost: tsc.FormatDiagnosticsHost = { - getCurrentDirectory: () => tsc.sys.getCurrentDirectory(), - getCanonicalFileName: fileName => fileName, - getNewLine: () => tsc.sys.newLine, - }; - - return tsc.formatDiagnostics(errors, defaultFormatHost); -} - -function readCompilerOptions( - configPath: string, - rootDir: string, -): tsc.CompilerOptions { - configPath = path.resolve(rootDir, configPath); - const { config, error } = tsc.readConfigFile(configPath, tsc.sys.readFile); - if (error) { - throw error; - } - - const { errors, options } = tsc.parseJsonConfigFileContent( - config, - tsc.sys, - path.resolve(rootDir), - ); - - if (errors.length > 0) { - const formattedErrors = formatTsDiagnostics(errors); - throw new Error( - `Some errors occurred while attempting to read from ${configPath}: ${formattedErrors}`, - ); - } - - return options; -} - -function getStartDir(): string { - // This is needed because of the way our tests are structured. - // If this is being executed as a library (under node_modules) - // we want to start with the project directory that's three - // levels above. - // If this is being executed from the test suite, we want to start - // in the directory of the test - - const grandparent = path.resolve(__dirname, '..', '..'); - if (grandparent.endsWith(`${path.sep}node_modules`)) { - return process.cwd(); - } - - return '.'; -} - -function getPathToClosestTSConfig( - startDir?: string, - previousDir?: string, -): string { - // Starting with the startDir directory and moving on to the - // parent directory recursively (going no further than the root directory) - // find and return the path to the first encountered tsconfig.json file - - if (!startDir) { - return getPathToClosestTSConfig(getStartDir()); - } - - const tsConfigPath = path.join(startDir, 'tsconfig.json'); - - const startDirPath = path.resolve(startDir); - const previousDirPath = path.resolve(previousDir || '/'); - - if (startDirPath === previousDirPath || fs.existsSync(tsConfigPath)) { - return tsConfigPath; - } - - return getPathToClosestTSConfig(path.join(startDir, '..'), startDir); -} - -function getTSConfigPathFromConfig( - globals: jest.ConfigGlobals, - rootDir?: string, -): string { - const defaultTSConfigFile = getPathToClosestTSConfig(rootDir); - if (!globals) { - return defaultTSConfigFile; - } - - const tsJestConfig = getTSJestConfig(globals); - - if (tsJestConfig.tsConfigFile) { - return tsJestConfig.tsConfigFile; - } - - return defaultTSConfigFile; -} - -export function mockGlobalTSConfigSchema( - globals: jest.ConfigGlobals, -): jest.ConfigGlobals { - const configPath = getTSConfigPathFromConfig(globals); - return { 'ts-jest': { tsConfigFile: configPath } }; -} - -export const getTSConfig = _.memoize(getTSConfig_local, (globals, rootDir) => { - // check cache before resolving configuration - // NB: We use JSON.stringify() to create a consistent, unique signature. Although it lacks a uniform - // shape, this is simpler and faster than using the crypto package to generate a hash signature. - return `${rootDir}:${JSON.stringify(globals)}`; -}); - -// Non-memoized version of TSConfig -function getTSConfig_local(globals, rootDir: string = '') { - const configPath = getTSConfigPathFromConfig(globals, rootDir); - logOnce(`Reading tsconfig file from path ${configPath}`); - - const config = readCompilerOptions(configPath, rootDir); - logOnce('Original typescript config before modifications: ', { ...config }); - - // tsc should not emit declaration map when used for tests - // disable some options that might break jest - config.declaration = false; - config.declarationMap = false; - config.emitDeclarationOnly = false; - - // ts-jest will map lines numbers properly if inlineSourceMap and - // inlineSources are set to true. The sourceMap configuration - // is used to send the sourcemap back to Jest - delete config.sourceMap; - config.inlineSourceMap = true; - config.inlineSources = true; - - // the coverage report is broken if `.outDir` is set - // see https://github.com/kulshekhar/ts-jest/issues/201 - // `.outDir` is removed even for test files as it affects with breakpoints - // see https://github.com/kulshekhar/ts-jest/issues/309 - delete config.outDir; - - if (configPath === path.join(getStartDir(), 'tsconfig.json')) { - // hardcode module to 'commonjs' in case the config is being loaded - // from the default tsconfig file. This is to ensure that coverage - // works well. If there's a need to override, it can be done using - // a custom tsconfig for testing - config.module = tsc.ModuleKind.CommonJS; - } - - config.module = config.module || tsc.ModuleKind.CommonJS; - config.jsx = config.jsx || tsc.JsxEmit.React; - - return config; -} - -export function cacheFile( - jestConfig: jest.ProjectConfig, - filePath: string, - src: string, -): void { - // store transpiled code contains source map into cache, except test cases - if (!jestConfig.testRegex || !filePath.match(jestConfig.testRegex)) { - const outputFilePath = path.join( - jestConfig.cacheDirectory, - '/ts-jest/', - crypto - .createHash('md5') - .update(filePath) - .digest('hex'), - ); - - fsExtra.outputFileSync(outputFilePath, src); - } -} - -export function runTsDiagnostics( - filePath: string, - compilerOptions: tsc.CompilerOptions, -): void { - const program = tsc.createProgram([filePath], compilerOptions); - const allDiagnostics = tsc.getPreEmitDiagnostics(program); - - if (allDiagnostics.length) { - throw new Error(formatTsDiagnostics(allDiagnostics)); - } -} diff --git a/src/utils/run-ts-diagnostics.ts b/src/utils/run-ts-diagnostics.ts new file mode 100644 index 0000000000..856179b6d9 --- /dev/null +++ b/src/utils/run-ts-diagnostics.ts @@ -0,0 +1,18 @@ +import formatTsDiagnostics from './format-diagnostics'; +import { + getPreEmitDiagnostics, + createProgram, + CompilerOptions, +} from 'typescript'; + +export default function runTsDiagnostics( + filePath: string, + compilerOptions: CompilerOptions, +): void { + const program = createProgram([filePath], compilerOptions); + const allDiagnostics = getPreEmitDiagnostics(program); + + if (allDiagnostics.length) { + throw new Error(formatTsDiagnostics(allDiagnostics)); + } +} diff --git a/tests/__helpers__/jest-config.ts b/tests/__helpers__/jest-config.ts new file mode 100644 index 0000000000..5b9911b1a6 --- /dev/null +++ b/tests/__helpers__/jest-config.ts @@ -0,0 +1,210 @@ +import { TsJestConfig } from '../../dist/types'; + +const { resolve } = require.requireActual('path'); + +function createJestConfig( + testModulePath: string, + tsJestOptions: TsJestConfig | null = null, + jestOptions: jest.InitialOptions = {}, +): jest.ProjectConfig { + const rootDir = resolve(__dirname, '..', testModulePath); + let options = { ...jestOptions }; + if (tsJestOptions) + options.globals = { ...options.globals, 'ts-jest': tsJestOptions }; + return { rootDir, ...options } as any; +} +require('fs').read; +const jestConfig = Object.assign(createJestConfig, { + babelConfig: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('babel-config', t, j), + babelConfigInvalid: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('babel-config-invalid', t, j), + babelConfigMergeIgnoreBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => createJestConfig('babel-config-merge-ignore-babelrc', t, j), + babelConfigMergeWithBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => createJestConfig('babel-config-merge-with-babelrc', t, j), + button: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('button', t, j), + dynamicImports: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('dynamic-imports', t, j), + hoistErrors: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('hoist-errors', t, j), + hoistTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('hoist-test', t, j), + importsTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('imports-test', t, j), + jestProjects: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('jest-projects', t, j), + jestProjectsWithWorkspace: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => createJestConfig('jest-projects-with-workspace', t, j), + jestconfigTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('jestconfig-test', t, j), + metadataEmit: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('metadata-emit', t, j), + noJsonModuleFileExt: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('no-json-module-file-ext', t, j), + noSourcemaps: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('no-sourcemaps', t, j), + noSyntheticDefault: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('no-synthetic-default', t, j), + simple: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('simple', t, j), + simpleAsync: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('simple-async', t, j), + simpleLongPath: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('simple-long-path', t, j), + skipBabelrc: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('skip-babelrc', t, j), + syntheticDefault: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('synthetic-default', t, j), + tsDiagnostics: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('ts-diagnostics', t, j), + tsJestModuleInterface: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('ts-jest-module-interface', t, j), + tsconfigTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('tsconfig-test', t, j), + useBabelrc: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('use-babelrc', t, j), + useConfigFromNodeModules: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => createJestConfig('use-config-from-node-modules', t, j), + useStrict: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('use-strict', t, j), + utils: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('utils', t, j), + watchTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => + createJestConfig('watch-test', t, j), +}); + +interface TestJestConfigHelpers { + ( + testModulePath: string, + tsJestOptions?: TsJestConfig | null, + jestOptions?: jest.InitialOptions, + ): jest.ProjectConfig; + babelConfig: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + babelConfigInvalid: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + babelConfigMergeIgnoreBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + babelConfigMergeWithBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + button: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + dynamicImports: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + hoistErrors: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + hoistTest: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + importsTest: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + jestProjects: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + jestProjectsWithWorkspace: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + jestconfigTest: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + metadataEmit: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + noJsonModuleFileExt: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + noSourcemaps: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + noSyntheticDefault: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + simple: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + simpleAsync: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + simpleLongPath: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + skipBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + syntheticDefault: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + tsDiagnostics: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + tsJestModuleInterface: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + tsconfigTest: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + useBabelrc: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + useConfigFromNodeModules: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + useStrict: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + utils: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; + watchTest: ( + t?: TsJestConfig | null, + j?: jest.InitialOptions, + ) => jest.ProjectConfig; +} + +export default jestConfig as TestJestConfigHelpers; diff --git a/tests/__helpers__/utils.ts b/tests/__helpers__/utils.ts index a241722ad3..e9395f9b3d 100644 --- a/tests/__helpers__/utils.ts +++ b/tests/__helpers__/utils.ts @@ -1,6 +1,7 @@ // from: https://github.com/facebook/jest/blob/master/integration_tests/utils.js import { sync as spawnSync } from 'cross-spawn'; import { Result } from './runJest'; +import { TsJestConfig } from '../../dist/types'; export function run(cmd, cwd) { const args = cmd.split(/\s/).slice(1); diff --git a/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap new file mode 100644 index 0000000000..d9154208c7 --- /dev/null +++ b/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`parse tsconfig with comments new behaviour (tsConfigFile & tsConfig) should correctly read allow-comments.json 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "pretty": false, +} +`; + +exports[`parse tsconfig with comments new behaviour (tsConfigFile & tsConfig) should correctly read allow-comments2.json 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "pretty": false, +} +`; diff --git a/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap new file mode 100644 index 0000000000..8adbd8b34c --- /dev/null +++ b/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`get default ts config new behavior (tsConfigFile & tsConfig) should not change the module if it is loaded from a non-default config file 1`] = `5`; + +exports[`get default ts config should correctly read tsconfig.json 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "moduleResolution": 2, + "noEmitOnError": false, + "target": 2, +} +`; diff --git a/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap new file mode 100644 index 0000000000..49b7d71850 --- /dev/null +++ b/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap @@ -0,0 +1,50 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`get ts config from string new behaviour (tsConfigFile & tsConfig) should correctly override any config in the "extends" directive 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "moduleResolution": 2, + "noEmitOnError": true, + "noImplicitAny": true, + "target": 1, +} +`; + +exports[`get ts config from string new behaviour (tsConfigFile & tsConfig) should correctly read my-tsconfig.json 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "moduleResolution": 2, + "noEmitOnError": true, + "target": 2, +} +`; + +exports[`get ts config from string new behaviour (tsConfigFile & tsConfig) should correctly resolve the "extends" directive 1`] = ` +Object { + "configFilePath": undefined, + "declaration": false, + "declarationMap": false, + "emitDeclarationOnly": false, + "inlineSourceMap": true, + "inlineSources": true, + "jsx": 2, + "module": 1, + "moduleResolution": 2, + "noEmitOnError": true, + "target": 2, +} +`; diff --git a/tests/__tests__/debug.spec.ts b/tests/__tests__/debug.spec.ts index a3f810828e..82be3ccb4c 100644 --- a/tests/__tests__/debug.spec.ts +++ b/tests/__tests__/debug.spec.ts @@ -16,7 +16,7 @@ describe('Debug output', () => { runJest('../simple', ['--no-cache', '-u'], { TS_JEST_DEBUG: 'true', }); - const logFile = await fs.readFile(debugFilePath, 'utf-8'); + const logFile = await fs.readFile(debugFilePath, 'utf8'); expect(logFile).not.toBeNull(); }); @@ -24,6 +24,6 @@ describe('Debug output', () => { it('Should not create a file if the debug flag is not set', async () => { runJest('../simple', ['--no-cache', '-u']); expect.assertions(1); // To make sure we actually do assert the promise on the line below - await expect(fs.readFile(debugFilePath, 'utf-8')).rejects.toThrow(); + await expect(fs.readFile(debugFilePath, 'utf8')).rejects.toThrow(); }); }); diff --git a/tests/__tests__/get-cache-key.spec.ts b/tests/__tests__/get-cache-key.spec.ts index 43e3e2e7a4..38a07ebd99 100644 --- a/tests/__tests__/get-cache-key.spec.ts +++ b/tests/__tests__/get-cache-key.spec.ts @@ -1,50 +1,34 @@ -import getCacheKeyForArgs from '../../dist/utils/get-cache-key'; -import { TsJestContext } from '../../dist/types'; +import getCacheKey from '../../dist/utils/get-cache-key'; +import cfg from '../__helpers__/jest-config'; -const tsJestContext: TsJestContext = { cache: {}, options: {} }; -const getCacheKey = (...args: any[]) => - getCacheKeyForArgs(args as any, tsJestContext); describe('getCacheKey', () => { const src = 'console.log(123);'; - const filepath = '/tmp/filepath'; - const configStr = `{ - "globals": { - "__TS_CONFIG": { - "compilerOptions": { - "target": "ES5", - "module": "commonjs" - } - } - }, - "transform": { - "^.+\\\\.tsx?$": "../../preprocessor.js" - }, - "testRegex": "(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$" - }`; - const options: jest.TransformOptions = { instrument: false }; + const jestConfig = cfg.simple(null, { + transform: { '^.+\\\\.tsx?$': '../../preprocessor.js' }, + testRegex: '(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$', + }); + const filepath = `${jestConfig.rootDir}/some-file.ts`; + const configStr = JSON.stringify(jestConfig); + const options = { instrument: false, rootDir: jestConfig.rootDir }; const originalHash = getCacheKey(src, filepath, configStr, options); it('should change hash when src changes', () => { const newSrc = 'console.log(1234);'; - const newHash = getCacheKey(newSrc, filepath, configStr); + const newHash = getCacheKey(newSrc, filepath, configStr, options); expect(newHash).not.toBe(originalHash); }); it('should change hash when filepath changes', () => { - const newPath = '/tmp/newfilepath'; - const newHash = getCacheKey(src, newPath, configStr); - expect(newHash).not.toBe(originalHash); - }); - - it('should change hash when tsconfig changes', () => { - const newConfigStr = configStr.replace(`"ES5"`, `"ES2015"`); - const newHash = getCacheKey(src, filepath, newConfigStr); + const newPath = `${jestConfig.rootDir}/some-other-file.ts`; + const newHash = getCacheKey(src, newPath, configStr, options); expect(newHash).not.toBe(originalHash); }); it('should change hash when transform options change', () => { - const newOptions: jest.TransformOptions = { instrument: true }; + const newOptions = { ...options, instrument: true }; const newHash = getCacheKey(src, filepath, configStr, newOptions); expect(newHash).not.toBe(originalHash); }); + + // TODO: test when package dependencies change }); diff --git a/tests/__tests__/html-transform.spec.ts b/tests/__tests__/html-transform.spec.ts index 744d44dadf..718b5f797a 100644 --- a/tests/__tests__/html-transform.spec.ts +++ b/tests/__tests__/html-transform.spec.ts @@ -1,7 +1,9 @@ -import * as tsJest from '../..'; +import * as tsJest from '../../dist'; +import jestConfig from '../__helpers__/jest-config'; + +const config = jestConfig.simple({}); +const filePath = `${config.rootDir}/some-file.html`; -const path = '/path/to/file.html'; -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 +16,10 @@ const source = `
describe('Html transforms', () => { it('transforms html if config.globals.__TRANSFORM_HTML__ is set', () => { // get the untransformed version - const untransformed = tsJest.process(source, path, config); + const untransformed = tsJest.process(source, filePath, { ...config }); // ... then the one which should be transformed (config.globals as any).__TRANSFORM_HTML__ = true; - const transformed = tsJest.process(source, path, config) as string; + const transformed = tsJest.process(source, filePath, 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 bd368cf65b..d5d8866cdb 100644 --- a/tests/__tests__/postprocess.spec.ts +++ b/tests/__tests__/postprocess.spec.ts @@ -6,27 +6,25 @@ jest.mock('@babel/core', () => { }; }); -import { getPostProcessHook } from '../../src/postprocess'; +import { getPostProcessHook } from '../../dist/postprocess'; +import jestConfig from '../__helpers__/jest-config'; describe('postprocess', () => { - 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, - }); + function runHook(jestConfig = {} as any) { + return getPostProcessHook({ rootDir: '/tmp/project', ...jestConfig })( + { code: 'input_code', map: 'input_source_map' }, + 'fake_file', + {} as any, + { + instrument: null, + }, + ); } it('skips postprocess when skipBabel=true', () => { const transformMock = require.requireMock('@babel/core').transform; - runHook({}, {}, { skipBabel: true }); + runHook({ globals: { 'ts-jest': { skipBabel: true } } }); expect(transformMock).not.toBeCalled(); }); @@ -34,7 +32,7 @@ describe('postprocess', () => { const transformMock = require.requireMock('@babel/core').transform; runHook(); - getPostProcessHook({}, {} as any, {})( + getPostProcessHook(jestConfig.simple())( { code: 'input_code', map: 'input_source_map' }, 'fake_file', {} as any, @@ -57,8 +55,8 @@ describe('postprocess', () => { skipBabel: false, }; - runHook({}, {}, tsJestConfig); - runHook({}, {}, tsJestConfig); + runHook({ globals: { 'ts-jest': tsJestConfig } }); + runHook({ globals: { 'ts-jest': tsJestConfig } }); expect(transformMock).lastCalledWith( expect.any(String), diff --git a/tests/__tests__/transpiler.spec.ts b/tests/__tests__/transpiler.spec.ts index 4e10add7dc..dfc6a0e48e 100644 --- a/tests/__tests__/transpiler.spec.ts +++ b/tests/__tests__/transpiler.spec.ts @@ -1,4 +1,4 @@ -import { transpileTypescript } from '../../src/transpiler'; +import { transpileTypescript } from '../../dist/transpiler'; import * as ts from 'typescript'; describe('transpileTypescript', () => { diff --git a/tests/__tests__/tsconfig-comments.spec.ts b/tests/__tests__/tsconfig-comments.spec.ts index 7c2e6dbf24..c434539d2d 100644 --- a/tests/__tests__/tsconfig-comments.spec.ts +++ b/tests/__tests__/tsconfig-comments.spec.ts @@ -1,8 +1,9 @@ import { MockedPath } from '../__mocks__/path'; jest.mock('path'); import * as fs from 'fs'; -import { getTSConfig } from '../../src/utils'; +import getTSConfig from '../../dist/utils/get-ts-config'; import * as path from 'path'; +import cfg from '../__helpers__/jest-config'; describe('parse tsconfig with comments', () => { const configFile1 = './tests/tsconfig-test/allows-comments.json'; @@ -24,34 +25,28 @@ describe('parse tsconfig with comments', () => { expect(() => { JSON.parse(fs.readFileSync(configFile1, 'utf8')); - }).toThrowError(); + }).toThrow(); expect(() => { JSON.parse(fs.readFileSync(configFile2, 'utf8')); - }).toThrowError(); + }).toThrow(); }); describe('new behaviour (tsConfigFile & tsConfig)', () => { - it('one config file should extend the other', () => { - const config = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'allows-comments.json', - }, - }); - - // allows-comments.json does not contain a "pretty" field, - // while allows-comments2.json does. Default value would be "false". - expect(config.pretty).toEqual(true); - }); - + // allows-comments.json does not contain a "pretty" field, + // while allows-comments2.json does. + // allow-comments.json extends allow-comments2.json it('should correctly read allow-comments.json', () => { - expect(() => { - getTSConfig({ - 'ts-jest': { - tsConfigFile: 'allows-comments.json', - }, - }); - }).not.toThrow(); + const config = getTSConfig( + cfg.tsconfigTest({ tsConfigFile: 'allows-comments.json' }), + ); + expect(config).toMatchSnapshot(); + }); + it('should correctly read allow-comments2.json', () => { + const config = getTSConfig( + cfg.tsconfigTest({ tsConfigFile: 'allows-comments2.json' }), + ); + expect(config).toMatchSnapshot(); }); }); }); diff --git a/tests/__tests__/tsconfig-default.spec.ts b/tests/__tests__/tsconfig-default.spec.ts index e3bc06b4e7..a2edea4d09 100644 --- a/tests/__tests__/tsconfig-default.spec.ts +++ b/tests/__tests__/tsconfig-default.spec.ts @@ -2,8 +2,10 @@ import { MockedPath } from '../__mocks__/path'; jest.mock('path'); import * as ts from 'typescript'; -import { getTSConfig } from '../../src/utils'; +import getTSConfig from '../../dist/utils/get-ts-config'; import * as path from 'path'; +import jestConfig from '../__helpers__/jest-config'; +import getTSJestConfig from '../../dist/utils/get-ts-jest-config'; describe('get default ts config', () => { beforeEach(() => { @@ -14,77 +16,45 @@ describe('get default ts config', () => { }); it('should correctly read tsconfig.json', () => { - const result = getTSConfig(null); - - expect(result).toEqual({ - declaration: false, - declarationMap: false, - emitDeclarationOnly: false, - inlineSourceMap: true, - inlineSources: true, - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: false, - jsx: ts.JsxEmit.React, - }); - }); - - it('should not read my-tsconfig.json', () => { - const result = getTSConfig(null); + const result = getTSConfig(jestConfig.tsconfigTest(null)); - expect(result).not.toEqual({ - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: true, - jsx: ts.JsxEmit.React, - }); - }); - - it('should not read inline tsconfig options', () => { - const result = getTSConfig(null); - - expect(result).not.toEqual({ - module: ts.ModuleKind.CommonJS, - jsx: ts.JsxEmit.React, - }); + expect(result).toMatchSnapshot(); }); describe('new behavior (tsConfigFile & tsConfig)', () => { it('should be same results for null/undefined/etc.', () => { - const result = getTSConfig(null); - const resultUndefinedParam = getTSConfig(undefined); - const resultNullParam = getTSConfig(null); - const resultEmptyParam = getTSConfig({}); - const resultUndefinedContentFile = getTSConfig({ - 'ts-jest': { tsConfigFile: undefined }, - }); - const resultNullContentFile = getTSConfig({ - 'ts-jest': { tsConfigFile: null }, - }); - - expect(result).toEqual(resultUndefinedParam); - expect(result).toEqual(resultNullParam); + const result = getTSConfig(jestConfig.tsconfigTest(null)); + const resultEmptyParam = getTSConfig(jestConfig.tsconfigTest({})); + const resultUndefinedContentFile = getTSConfig( + jestConfig.tsconfigTest({ tsConfigFile: undefined }), + ); + const resultNullContentFile = getTSConfig( + jestConfig.tsconfigTest({ tsConfigFile: null }), + ); + expect(result).toEqual(resultEmptyParam); expect(result).toEqual(resultUndefinedContentFile); expect(result).toEqual(resultNullContentFile); }); it('should be different results for different rootDir with same jest config.', () => { - const rootConfig = getTSConfig({}); - const subConfig = getTSConfig({}, 'tsconfig-module'); + const rootConfig = getTSConfig(jestConfig.tsconfigTest()); + const subConfig = getTSConfig( + jestConfig('tsconfig-test/tsconfig-module'), + ); expect(rootConfig).not.toEqual(subConfig); }); it('should not change the module if it is loaded from a non-default config file', () => { - const config = getTSConfig({ - 'ts-jest': { + const config = getTSConfig( + jestConfig.tsconfigTest({ tsConfigFile: 'tsconfig-module/custom-config.json', - }, - }); + }), + ); + // snapshot would be enough here, but that adds a security in case we do not see it in a PR expect(config.module).toBe(ts.ModuleKind.ES2015); + expect(config.module).toMatchSnapshot(); }); it('should set the module to CommonJS if it is not, when loading from the default tsconfig file', () => { @@ -94,11 +64,7 @@ describe('get default ts config', () => { './tests/tsconfig-test/tsconfig-module', ); - const config = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'tsconfig.json', - }, - }); + const config = getTSConfig(jestConfig('tsconfig-test/tsconfig-module')); expect(config.module).toBe(ts.ModuleKind.CommonJS); }); @@ -109,26 +75,28 @@ describe('get default ts config', () => { './tests/tsconfig-test/tsconfig-module', ); - const { getTSJestConfig } = require('../../src/utils'); - const config1 = getTSJestConfig({ - 'ts-jest': { - skipBabel: true, + globals: { + 'ts-jest': { + skipBabel: true, + }, }, }); expect(config1.skipBabel).toBe(true); const config2 = getTSJestConfig({ - 'ts-jest': { - skipBabel: false, + globals: { + 'ts-jest': { + skipBabel: false, + }, }, }); expect(config2.skipBabel).toBe(false); - expect(getTSJestConfig({ 'ts-jest': {} })).toEqual({}); + expect(getTSJestConfig({ globals: { 'ts-jest': {} } })).toEqual({}); expect(getTSJestConfig({})).toEqual({}); - expect(getTSJestConfig()).toEqual({}); + // expect(getTSJestConfig(null)).toEqual({}); }); }); diff --git a/tests/__tests__/tsconfig-string.spec.ts b/tests/__tests__/tsconfig-string.spec.ts index 210b6a2376..77574f48c7 100644 --- a/tests/__tests__/tsconfig-string.spec.ts +++ b/tests/__tests__/tsconfig-string.spec.ts @@ -1,8 +1,9 @@ jest.mock('path'); -import { getTSConfig } from '../../dist/utils'; +import getTSConfig from '../../dist/utils/get-ts-config'; import * as ts from 'typescript'; import * as path from 'path'; +import cfg from '../__helpers__/jest-config'; describe('get ts config from string', () => { beforeEach(() => { @@ -12,93 +13,35 @@ describe('get ts config from string', () => { describe('new behaviour (tsConfigFile & tsConfig)', () => { it('should correctly read my-tsconfig.json', () => { - const result = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'my-tsconfig.json', - }, - }); + const result = getTSConfig( + cfg.tsconfigTest({ tsConfigFile: 'my-tsconfig.json' }), + ); - expect(result).toMatchObject({ - inlineSourceMap: true, - inlineSources: true, - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: true, - jsx: ts.JsxEmit.React, - }); - }); - - it('should not read tsconfig.json', () => { - const result = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'my-tsconfig.json', - }, - }); - - expect(result).not.toEqual({ - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: false, - jsx: ts.JsxEmit.React, - }); - }); - - it('should not read inline tsconfig options', () => { - const result = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'my-tsconfig.json', - }, - }); - - expect(result).not.toEqual({ - target: ts.ScriptTarget.ES5, - jsx: ts.JsxEmit.React, - }); + // snapshot would be enough here, but that adds a security in case we do not see it in a PR + expect(result.target).toBe(ts.ScriptTarget.ES2015); // es6 resolves to ES2015 enum value + expect(result).toMatchSnapshot(); }); it('should correctly resolve the "extends" directive', () => { - const result = getTSConfig({ - 'ts-jest': { - tsConfigFile: 'extends-tsconfig.json', - }, - }); + const result = getTSConfig( + cfg.tsconfigTest({ tsConfigFile: 'extends-tsconfig.json' }), + ); - expect(result).toEqual({ - declaration: false, - declarationMap: false, - emitDeclarationOnly: false, - inlineSourceMap: true, - inlineSources: true, - target: ts.ScriptTarget.ES2015, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: true, - jsx: ts.JsxEmit.React, - }); + // snapshot would be enough here, but that adds a security in case we do not see it in a PR + expect(result.target).toBe(ts.ScriptTarget.ES2015); // es6 resolves to ES2015 enum value + expect(result).toMatchSnapshot(); }); it('should correctly override any config in the "extends" directive', () => { - const result = getTSConfig({ - 'ts-jest': { + const result = getTSConfig( + cfg.tsconfigTest({ tsConfigFile: 'extends-with-overrides-tsconfig.json', - }, - }); + }), + ); - expect(result).toEqual({ - declaration: false, - declarationMap: false, - emitDeclarationOnly: false, - inlineSourceMap: true, - inlineSources: true, - target: ts.ScriptTarget.ES5, - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.NodeJs, - noEmitOnError: true, - jsx: ts.JsxEmit.React, - noImplicitAny: true, - }); + // snapshot would be enough here, but that adds a security in case we do not see it in a PR + expect(result.target).toBe(ts.ScriptTarget.ES5); + expect(result).toMatchSnapshot(); }); }); }); 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 fb1e52a2b8..5aee192c1c 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 '../../..'; +import * as tsJest from '../../../dist'; describe('ts-jest module interface', () => { it('is an object', () => { diff --git a/tests/tsconfig-test/allows-comments2.json b/tests/tsconfig-test/allows-comments2.json index e5b406f1ca..1d84a98b46 100644 --- a/tests/tsconfig-test/allows-comments2.json +++ b/tests/tsconfig-test/allows-comments2.json @@ -1,6 +1,6 @@ { "compilerOptions": { //some comments - "pretty": true + "pretty": false } } diff --git a/tests/utils/test-utils.ts b/tests/utils/test-utils.ts index c361a898c4..eacaa345ce 100644 --- a/tests/utils/test-utils.ts +++ b/tests/utils/test-utils.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import { normalize } from 'jest-config'; import * as setFromArgv from 'jest-config/build/set_from_argv'; import * as path from 'path'; -import { JestConfigNormalize } from '../../src/jest-types'; +import { JestConfigNormalize } from '../../dist/types'; import { Arguments } from 'yargs'; function readRawConfig(argv: Arguments, root: string): JestConfigNormalize { @@ -60,7 +60,7 @@ function loadJestConfigFromFile( filePath: string, argv: Arguments, ): JestConfigNormalize { - const config = JSON.parse(fs.readFileSync(filePath, 'utf-8')); + const config = JSON.parse(fs.readFileSync(filePath, 'utf8')); config.rootDir = config.rootDir ? path.resolve(path.dirname(filePath), config.rootDir) : process.cwd(); diff --git a/yarn.lock b/yarn.lock index 996c38f549..21439109a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -564,6 +564,10 @@ version "0.31.37" resolved "https://registry.yarnpkg.com/@types/es6-shim/-/es6-shim-0.31.37.tgz#d01fa9b61a6692e57387dde5483b0255659ba70f" +"@types/flat@^0.0.28": + version "0.0.28" + resolved "https://registry.yarnpkg.com/@types/flat/-/flat-0.0.28.tgz#5c788149d85a6cf8ff5f5f000acdd912cdea4274" + "@types/fs-extra@5.0.4": version "5.0.4" resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-5.0.4.tgz#b971134d162cc0497d221adde3dbb67502225599" @@ -1263,6 +1267,10 @@ cliui@^4.0.0: strip-ansi "^4.0.0" wrap-ansi "^2.0.0" +closest-file-data@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/closest-file-data/-/closest-file-data-0.1.4.tgz#975f87c132f299d24a0375b9f63ca3fb88f72b3a" + co@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" @@ -1894,6 +1902,12 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" +flat@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2" + dependencies: + is-buffer "~2.0.3" + for-in@^1.0.1, for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -2315,6 +2329,10 @@ is-buffer@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" +is-buffer@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" + is-builtin-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" From af5c97dfdd0b4a3d9666772d73f4d87130b9e4eb Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 23 Jul 2018 14:30:39 +0200 Subject: [PATCH 10/21] test: removes any tsconfig.json in the way of the tests --- package.json | 7 +++++- scripts/tests.js | 2 +- src/utils/get-ts-config.ts | 2 +- tests/__tests__/tsconfig-comments.spec.ts | 1 + tests/__tests__/tsconfig-default.spec.ts | 10 ++++++++- tests/__tests__/tsconfig-string.spec.ts | 1 + tests/tsconfig.json | 26 ----------------------- tsconfig.json => tsconfig.base.json | 0 tsconfig.build.json | 2 +- 9 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 tests/tsconfig.json rename tsconfig.json => tsconfig.base.json (100%) diff --git a/package.json b/package.json index 34fc935265..0813d962d5 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,12 @@ "js", "jsx", "json" - ] + ], + "globals": { + "ts-jest": { + "tsConfigFile": "tsconfig.base.json" + } + } }, "dependencies": { "closest-file-data": "^0.1.4", diff --git a/scripts/tests.js b/scripts/tests.js index 9ccb16e8ee..2bd482195c 100644 --- a/scripts/tests.js +++ b/scripts/tests.js @@ -16,7 +16,7 @@ function getDirectories(rootDir) { function createIntegrationMock() { const testsRoot = 'tests'; const testCaseFolders = getDirectories(testsRoot).filter(function(testDir) { - return !(testDir.startsWith('__') && testDir.endsWith('__')); + return !/^(?:utils|__.+__)$/.test(testDir); }); testCaseFolders.forEach(directory => { diff --git a/src/utils/get-ts-config.ts b/src/utils/get-ts-config.ts index 903a104b41..50fedf5005 100644 --- a/src/utils/get-ts-config.ts +++ b/src/utils/get-ts-config.ts @@ -110,7 +110,7 @@ function readCompilerOptions( // } // we don't need any data, just its full path -const tsConfigReader = { basename: TSCONFIG_FILENAME, read: () => null }; +const tsConfigReader = { basename: TSCONFIG_FILENAME, read: () => 0 }; function findTSConfigPath( jestConfig: jest.ProjectConfig, diff --git a/tests/__tests__/tsconfig-comments.spec.ts b/tests/__tests__/tsconfig-comments.spec.ts index c434539d2d..7479c721f6 100644 --- a/tests/__tests__/tsconfig-comments.spec.ts +++ b/tests/__tests__/tsconfig-comments.spec.ts @@ -12,6 +12,7 @@ describe('parse tsconfig with comments', () => { beforeEach(() => { // Set up some mocked out file info before each test ((path as any) as MockedPath).__setBaseDir('./tests/tsconfig-test'); + getTSConfig.cache.clear(); }); it('the two config files should exist', () => { diff --git a/tests/__tests__/tsconfig-default.spec.ts b/tests/__tests__/tsconfig-default.spec.ts index a2edea4d09..dbfc24c89f 100644 --- a/tests/__tests__/tsconfig-default.spec.ts +++ b/tests/__tests__/tsconfig-default.spec.ts @@ -15,6 +15,15 @@ describe('get default ts config', () => { getTSConfig.cache.clear(); }); + it('should bail when no default tsconfig.json found', () => { + // there is no tsconfig file in that test module + ((path as any) as MockedPath).__setBaseDir('./tests/jestconfig-test'); + + expect(() => getTSConfig(jestConfig.jestconfigTest(null))).toThrowError( + /unable to find ts configuration file/i, + ); + }); + it('should correctly read tsconfig.json', () => { const result = getTSConfig(jestConfig.tsconfigTest(null)); @@ -97,6 +106,5 @@ describe('get default ts config', () => { expect(getTSJestConfig({ globals: { 'ts-jest': {} } })).toEqual({}); expect(getTSJestConfig({})).toEqual({}); - // expect(getTSJestConfig(null)).toEqual({}); }); }); diff --git a/tests/__tests__/tsconfig-string.spec.ts b/tests/__tests__/tsconfig-string.spec.ts index 77574f48c7..5b4285783a 100644 --- a/tests/__tests__/tsconfig-string.spec.ts +++ b/tests/__tests__/tsconfig-string.spec.ts @@ -9,6 +9,7 @@ describe('get ts config from string', () => { beforeEach(() => { // Set up some mocked out file info before each test (path as any).__setBaseDir('./tests/tsconfig-test'); + getTSConfig.cache.clear(); }); describe('new behaviour (tsConfigFile & tsConfig)', () => { diff --git a/tests/tsconfig.json b/tests/tsconfig.json deleted file mode 100644 index f4161e554b..0000000000 --- a/tests/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "sourceMap": false, - "declaration": true, - "target": "ES5", - "module": "commonjs", - "moduleResolution": "node", - "noEmitOnError": true, - "noFallthroughCasesInSwitch": true, - "noImplicitAny": false, - "noImplicitReturns": true, - "removeComments": true, - "strictNullChecks": false, - "jsx": "react", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": false - }, - "include": [ - "**/*.ts", - "**/*.tsx" - ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.base.json similarity index 100% rename from tsconfig.json rename to tsconfig.base.json diff --git a/tsconfig.build.json b/tsconfig.build.json index 4eecabd0b4..6686956918 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "sourceMap": false, "removeComments": true, From 3e0b7da0cb6b213533c375aadd1d496bff0fa4b9 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 23 Jul 2018 14:37:39 +0200 Subject: [PATCH 11/21] chore: removes unnecessary notes --- src/index.ts | 12 +----------- src/utils/get-cache-key.ts | 1 - 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index e51d91e016..c9f1b96030 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,18 +1,8 @@ import getCacheKey from './utils/get-cache-key'; import preprocess from './preprocess'; -//FIXME: options is always empty const createTransformer = (options?: any): jest.Transformer => { - // const cache = Object.create(null); - // options = Object.assign({}, options, { - // compact: false, - // plugins: (options && options.plugins) || [], - // presets: ((options && options.presets) || []).concat([jestPreset]), - // sourceMaps: 'both', - // }); - // delete options.cacheDirectory; - // delete options.filename; - + // options are always empty, must be the older jest API giving options here return { canInstrument: true, getCacheKey, diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts index 2ec8304e78..b6a969d51a 100644 --- a/src/utils/get-cache-key.ts +++ b/src/utils/get-cache-key.ts @@ -5,7 +5,6 @@ import { MY_PACKAGE_CONTENT } from './constants'; import getBabelRC from './get-babel-rc'; import getTSConfig from './get-ts-config'; -// FIXME: remove dependency on config, it's empty export default function getCacheKey( fileData: string, filePath: string, From 60ab36eb4eb17055d5ef266e55b55d07a1da691b Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Mon, 23 Jul 2018 14:51:24 +0200 Subject: [PATCH 12/21] fix(lint): fixes tslint script & lint issues --- package.json | 2 +- src/postprocess.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0813d962d5..a76fa67e3a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "pretest": "npm run tslint && npm run clean-build", "test": "node scripts/tests.js", "test:unit": "jest --testRegex '' --testMatch '/src/**/*.spec.ts'", - "tslint": "tslint src/**/*.ts", + "tslint": "tslint 'src/**/*.ts'", "doc": "doctoc .", "prepublish": "npm run clean-build", "precommit": "lint-staged", diff --git a/src/postprocess.ts b/src/postprocess.ts index 5c86152bde..cabe70fabd 100644 --- a/src/postprocess.ts +++ b/src/postprocess.ts @@ -9,7 +9,7 @@ let babel: typeof __types__babel; let istanbulPlugin: typeof __types__istanbulPlugin; let jestPreset: typeof __types__jestPreset; function importBabelDeps() { - if (babel) return; // tslint:ignore-line + if (babel) return; // tslint:disable-line // ensure we use the require from jest babel = require.main.require('@babel/core'); istanbulPlugin = require.main.require('babel-plugin-istanbul').default; @@ -104,6 +104,6 @@ export const getPostProcessHook = ( return createBabelTransformer(babelOptions); }; -function toArray(iter?: Iterable | null): Array { +function toArray(iter?: Iterable | null): T[] { return iter ? Array.from(iter) : []; } From 76e27c1c37fea160d84785c2fcd117b757ca0547 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Tue, 24 Jul 2018 11:42:34 +0200 Subject: [PATCH 13/21] fix(source-maps): fix source maps options/calls --- src/postprocess.ts | 93 ++++++++++++------- src/preprocess.ts | 1 + src/transpiler.ts | 7 +- src/utils/get-ts-config.ts | 4 +- .../ts-coverage-async.spec.ts.snap | 4 +- .../__snapshots__/ts-coverage.spec.ts.snap | 4 +- .../tsconfig-comments.spec.ts.snap | 6 +- .../tsconfig-default.spec.ts.snap | 3 +- .../tsconfig-string.spec.ts.snap | 9 +- tests/__tests__/jest-hoist.spec.ts | 4 - tests/__tests__/postprocess.spec.ts | 4 +- tests/hoist-test/__tests__/jest-hoist.test.ts | 4 +- 12 files changed, 85 insertions(+), 58 deletions(-) diff --git a/src/postprocess.ts b/src/postprocess.ts index cabe70fabd..4ead6c3195 100644 --- a/src/postprocess.ts +++ b/src/postprocess.ts @@ -5,16 +5,6 @@ import * as __types__babel from 'babel-core'; import __types__istanbulPlugin from 'babel-plugin-istanbul'; import * as __types__jestPreset from 'babel-preset-jest'; -let babel: typeof __types__babel; -let istanbulPlugin: typeof __types__istanbulPlugin; -let jestPreset: typeof __types__jestPreset; -function importBabelDeps() { - if (babel) return; // tslint:disable-line - // ensure we use the require from jest - babel = require.main.require('@babel/core'); - istanbulPlugin = require.main.require('babel-plugin-istanbul').default; - jestPreset = require.main.require('babel-preset-jest'); -} import { BabelTransformOptions, PostProcessHook, @@ -23,6 +13,18 @@ import { import { logOnce } from './utils/logger'; import getTSJestConfig from './utils/get-ts-jest-config'; +let babel: typeof __types__babel; +let istanbulPlugin: typeof __types__istanbulPlugin; +let jestPreset: typeof __types__jestPreset; + +function importBabelDeps() { + if (babel) return; // tslint:disable-line + // we must use babel until we handle hoisting of jest.mock() internally + babel = require('@babel/core'); + istanbulPlugin = require('babel-plugin-istanbul').default; + jestPreset = require('babel-preset-jest'); +} + // Function that takes the transpiled typescript and runs it through babel/whatever. export function postProcessCode( jestConfig: jest.ProjectConfig, @@ -39,37 +41,43 @@ function createBabelTransformer( options: BabelTransformOptions, ): PostProcessHook { importBabelDeps(); - options = { - ...options, - plugins: options.plugins || [], - presets: (options.presets || []).concat([jestPreset]), - }; - delete options.cacheDirectory; - delete options.filename; + const presets = options.presets.slice(); + const plugins = options.plugins.slice(); + + // adds babel-preset-jest if not present + if (!hasBabelAddon(presets, jestPreset)) { + presets.push(jestPreset); + } + + // we need to know if there is istanbul plugin in the list so that we do not add it + // in the case the user already has it configured + const hasIstanbul = hasBabelAddon(plugins, istanbulPlugin); + + // create a new object we'll use as options with the sliced presets and plugins + const optionsBase = { ...options, presets, plugins }; - return ( + delete optionsBase.cacheDirectory; + + const babelTransformer = ( codeSourcemapPair: jest.TransformedSource, filename: string, config: jest.ProjectConfig, transformOptions: JestCacheKeyOptions, ): jest.TransformedSource => { - const theseOptions = Object.assign( - { filename, inputSourceMap: codeSourcemapPair.map }, - options, - ); + const inputSourceMap = + typeof codeSourcemapPair.map === 'string' + ? JSON.parse(codeSourcemapPair.map) + : codeSourcemapPair.map; + const theseOptions = { ...optionsBase, filename, inputSourceMap }; if (transformOptions && transformOptions.instrument) { theseOptions.auxiliaryCommentBefore = ' istanbul ignore next '; // Copied from jest-runtime transform.js - theseOptions.plugins = theseOptions.plugins.concat([ - [ - istanbulPlugin, - { - // files outside `cwd` will not be instrumented - cwd: config.rootDir, - exclude: [], - }, - ], - ]); + if (!hasIstanbul) { + theseOptions.plugins = [ + ...theseOptions.plugins, + istanbulPluginConfig(config), + ]; + } } // we typecast here because babel returns a more complete object than the one expected by jest @@ -78,6 +86,8 @@ function createBabelTransformer( theseOptions, ) as jest.TransformedSource; }; + + return babelTransformer; } export const getPostProcessHook = ( @@ -96,7 +106,7 @@ export const getPostProcessHook = ( babelrc: tsJestConfig.useBabelrc || false, plugins: toArray(tsJestBabelConfig.plugins), presets: toArray(tsJestBabelConfig.presets), - sourceMaps: !tsJestConfig.disableSourceMapSupport, + sourceMaps: tsJestConfig.disableSourceMapSupport ? false : 'both', }; logOnce('Using babel with options:', babelOptions); @@ -107,3 +117,20 @@ export const getPostProcessHook = ( function toArray(iter?: Iterable | null): T[] { return iter ? Array.from(iter) : []; } + +function istanbulPluginConfig(jestConfig: jest.ProjectConfig) { + return [ + istanbulPlugin, + { + // files outside `cwd` will not be instrumented + cwd: jestConfig.rootDir, + exclude: [], + }, + ]; +} + +function hasBabelAddon(inputList: any[], ...addonMatches: any[]): boolean { + return inputList.some(item => { + return addonMatches.indexOf(Array.isArray(item) ? item[0] : item) !== -1; + }); +} diff --git a/src/preprocess.ts b/src/preprocess.ts index f350e0a33b..9e954bd46c 100644 --- a/src/preprocess.ts +++ b/src/preprocess.ts @@ -44,6 +44,7 @@ export default function preprocess( const transpileOutput = transpileTypescript(filePath, src, compilerOptions); + // FIXME: this should be done in the typescript source, else it's invalidating source maps if (tsJestConfig.ignoreCoverageForAllDecorators === true) { transpileOutput.code = transpileOutput.code.replace( /\b__decorate\b/g, diff --git a/src/transpiler.ts b/src/transpiler.ts index 8c6721d857..9e17459111 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -8,15 +8,12 @@ export function transpileTypescript( compilerOptions: ts.CompilerOptions, ): jest.TransformedSource { logOnce('Compiling via normal transpileModule call'); - const transpileOutput = transpileViaTranspileModule( + const { outputText: code, sourceMapText: map } = transpileViaTranspileModule( filePath, fileSrc, compilerOptions, ); - return { - code: transpileOutput.outputText, - map: transpileOutput.sourceMapText, - }; + return { code, map }; } /** diff --git a/src/utils/get-ts-config.ts b/src/utils/get-ts-config.ts index 50fedf5005..9a20bb1583 100644 --- a/src/utils/get-ts-config.ts +++ b/src/utils/get-ts-config.ts @@ -45,8 +45,8 @@ function getTSConfig_local(jestConfig: jest.ProjectConfig): CompilerOptions { // ts-jest will map lines numbers properly if inlineSourceMap and // inlineSources are set to true. The sourceMap configuration // is used to send the sourcemap back to Jest - delete config.sourceMap; - config.inlineSourceMap = true; + config.inlineSourceMap = false; + config.sourceMap = true; config.inlineSources = true; // the coverage report is broken if `.outDir` is set diff --git a/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap b/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap index 0eb8e0a7cc..8439cd570a 100644 --- a/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap +++ b/tests/__tests__/__snapshots__/ts-coverage-async.spec.ts.snap @@ -3,10 +3,10 @@ exports[`Typescript async coverage Should generate the correct async coverage numbers 1`] = ` " =============================== Coverage summary =============================== -Statements : 68.75% ( 11/16 ) +Statements : 71.43% ( 10/14 ) Branches : 33.33% ( 2/6 ) Functions : 66.67% ( 4/6 ) -Lines : 73.33% ( 11/15 ) +Lines : 66.67% ( 8/12 ) ================================================================================ " `; diff --git a/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap b/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap index aa24548bb4..141c4d8d0a 100644 --- a/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap +++ b/tests/__tests__/__snapshots__/ts-coverage.spec.ts.snap @@ -3,10 +3,10 @@ exports[`Typescript coverage Should generate the correct coverage numbers. 1`] = ` " =============================== Coverage summary =============================== -Statements : 68.75% ( 11/16 ) +Statements : 71.43% ( 10/14 ) Branches : 33.33% ( 2/6 ) Functions : 66.67% ( 4/6 ) -Lines : 73.33% ( 11/15 ) +Lines : 66.67% ( 8/12 ) ================================================================================ " `; diff --git a/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap index d9154208c7..e641618a0c 100644 --- a/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap +++ b/tests/__tests__/__snapshots__/tsconfig-comments.spec.ts.snap @@ -6,11 +6,12 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "pretty": false, + "sourceMap": true, } `; @@ -20,10 +21,11 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "pretty": false, + "sourceMap": true, } `; diff --git a/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap index 8adbd8b34c..59dc4907dd 100644 --- a/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap +++ b/tests/__tests__/__snapshots__/tsconfig-default.spec.ts.snap @@ -8,12 +8,13 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "moduleResolution": 2, "noEmitOnError": false, + "sourceMap": true, "target": 2, } `; diff --git a/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap b/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap index 49b7d71850..73cffd5d6f 100644 --- a/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap +++ b/tests/__tests__/__snapshots__/tsconfig-string.spec.ts.snap @@ -6,13 +6,14 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "moduleResolution": 2, "noEmitOnError": true, "noImplicitAny": true, + "sourceMap": true, "target": 1, } `; @@ -23,12 +24,13 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "moduleResolution": 2, "noEmitOnError": true, + "sourceMap": true, "target": 2, } `; @@ -39,12 +41,13 @@ Object { "declaration": false, "declarationMap": false, "emitDeclarationOnly": false, - "inlineSourceMap": true, + "inlineSourceMap": false, "inlineSources": true, "jsx": 2, "module": 1, "moduleResolution": 2, "noEmitOnError": true, + "sourceMap": true, "target": 2, } `; diff --git a/tests/__tests__/jest-hoist.spec.ts b/tests/__tests__/jest-hoist.spec.ts index 81fb70d2bb..e117c915fd 100644 --- a/tests/__tests__/jest-hoist.spec.ts +++ b/tests/__tests__/jest-hoist.spec.ts @@ -15,10 +15,6 @@ describe('Jest.mock() calls', () => { const stderr = result.stderr; expect(stderr).toContain('Hello.ts:22:11'); - // TODO FIX COMMENT - sourcemap is accurate now - // The actual error occurs at line 14. However, because the mock calls - // are hoisted, this changes - in this case, to 22 - // The column numbers are accurate. expect(stderr).toContain('Hello.test.ts:14:19'); expect(result.status).toBe(1); diff --git a/tests/__tests__/postprocess.spec.ts b/tests/__tests__/postprocess.spec.ts index d5d8866cdb..74792d0ac2 100644 --- a/tests/__tests__/postprocess.spec.ts +++ b/tests/__tests__/postprocess.spec.ts @@ -12,7 +12,7 @@ import jestConfig from '../__helpers__/jest-config'; describe('postprocess', () => { function runHook(jestConfig = {} as any) { return getPostProcessHook({ rootDir: '/tmp/project', ...jestConfig })( - { code: 'input_code', map: 'input_source_map' }, + { code: 'input_code', map: '"input_source_map"' }, 'fake_file', {} as any, { @@ -33,7 +33,7 @@ describe('postprocess', () => { runHook(); getPostProcessHook(jestConfig.simple())( - { code: 'input_code', map: 'input_source_map' }, + { code: 'input_code', map: '"input_source_map"' }, 'fake_file', {} as any, { instrument: null }, diff --git a/tests/hoist-test/__tests__/jest-hoist.test.ts b/tests/hoist-test/__tests__/jest-hoist.test.ts index ae01fd7949..83f92e02c7 100644 --- a/tests/hoist-test/__tests__/jest-hoist.test.ts +++ b/tests/hoist-test/__tests__/jest-hoist.test.ts @@ -19,11 +19,11 @@ describe('Local mocks', () => { expect((SomeClass as any).mockReturnValue).toBeDefined(); }); - it('Jest should be able to mock a local class', () => { + it('Jest should be able to mock a local function', () => { expect((SomeFunction as any).mockReturnValueOnce).toBeDefined(); }); - it('Jest should be able to mock a local class', () => { + it('Jest should be able to mock a local const', () => { expect( (SomeFunctionDeclaredAsConst as any).mockImplementation, ).toBeDefined(); From 68f8cb30450fde30bea10645ea3d3c0e2d02e220 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Tue, 24 Jul 2018 15:29:33 +0200 Subject: [PATCH 14/21] test: adds a test for `resolveJsonModule` in TS 2.9 --- tests/__tests__/import-json.spec.ts | 9 +++++++++ tests/import-json/.gitignore | 1 + tests/import-json/__tests__/pkg.test.ts | 9 +++++++++ tests/import-json/package.json | 15 +++++++++++++++ tests/import-json/pkg.ts | 3 +++ tests/import-json/tsconfig.json | 5 +++++ 6 files changed, 42 insertions(+) create mode 100644 tests/__tests__/import-json.spec.ts create mode 100644 tests/import-json/.gitignore create mode 100644 tests/import-json/__tests__/pkg.test.ts create mode 100644 tests/import-json/package.json create mode 100644 tests/import-json/pkg.ts create mode 100644 tests/import-json/tsconfig.json diff --git a/tests/__tests__/import-json.spec.ts b/tests/__tests__/import-json.spec.ts new file mode 100644 index 0000000000..9666e5c4a4 --- /dev/null +++ b/tests/__tests__/import-json.spec.ts @@ -0,0 +1,9 @@ +import runJest from '../__helpers__/runJest'; + +describe('Import JSON with `resolveJsonModule`', () => { + it('should work as expected', () => { + const result = runJest('../import-json', ['--no-cache']); + + expect(result.status).toBe(0); + }); +}); diff --git a/tests/import-json/.gitignore b/tests/import-json/.gitignore new file mode 100644 index 0000000000..4ebc8aea50 --- /dev/null +++ b/tests/import-json/.gitignore @@ -0,0 +1 @@ +coverage diff --git a/tests/import-json/__tests__/pkg.test.ts b/tests/import-json/__tests__/pkg.test.ts new file mode 100644 index 0000000000..b08106caa4 --- /dev/null +++ b/tests/import-json/__tests__/pkg.test.ts @@ -0,0 +1,9 @@ +declare var jest, describe, it, expect; + +import pkg from '../pkg'; + +describe('pkg', () => { + it('should statically import package.json', () => { + expect(pkg).toEqual(require('../package.json')); + }); +}); diff --git a/tests/import-json/package.json b/tests/import-json/package.json new file mode 100644 index 0000000000..1cd551ae47 --- /dev/null +++ b/tests/import-json/package.json @@ -0,0 +1,15 @@ +{ + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ] + } +} diff --git a/tests/import-json/pkg.ts b/tests/import-json/pkg.ts new file mode 100644 index 0000000000..8eed6e7938 --- /dev/null +++ b/tests/import-json/pkg.ts @@ -0,0 +1,3 @@ +import * as pkg from './package'; + +export default pkg; diff --git a/tests/import-json/tsconfig.json b/tests/import-json/tsconfig.json new file mode 100644 index 0000000000..1f3a011864 --- /dev/null +++ b/tests/import-json/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "resolveJsonModule": true + } +} From a4d000b38ab3b270dbc701adc2f0bedf1192504d Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 26 Jul 2018 11:36:22 +0200 Subject: [PATCH 15/21] test: adds a failing test for #636 --- tests/__tests__/rel-config-paths.spec.ts | 24 +++++++++++++++++++ .../config/jest.config.invalid.js | 14 +++++++++++ tests/rel-config-paths/config/jest.config.js | 14 +++++++++++ .../config/tsconfig.base.json | 6 +++++ .../config/tsconfig.test.json | 6 +++++ .../rel-config-paths/custom-test-dir/test.ts | 9 +++++++ tests/rel-config-paths/package.json | 1 + tests/rel-config-paths/src/index.ts | 3 +++ 8 files changed, 77 insertions(+) create mode 100644 tests/__tests__/rel-config-paths.spec.ts create mode 100644 tests/rel-config-paths/config/jest.config.invalid.js create mode 100644 tests/rel-config-paths/config/jest.config.js create mode 100644 tests/rel-config-paths/config/tsconfig.base.json create mode 100644 tests/rel-config-paths/config/tsconfig.test.json create mode 100644 tests/rel-config-paths/custom-test-dir/test.ts create mode 100644 tests/rel-config-paths/package.json create mode 100644 tests/rel-config-paths/src/index.ts diff --git a/tests/__tests__/rel-config-paths.spec.ts b/tests/__tests__/rel-config-paths.spec.ts new file mode 100644 index 0000000000..eba5218699 --- /dev/null +++ b/tests/__tests__/rel-config-paths.spec.ts @@ -0,0 +1,24 @@ +import runJest from '../__helpers__/runJest'; + +describe('Use jest config from config dir', () => { + it('Should run all tests resolving tsconfig extends', () => { + const result = runJest('../rel-config-paths', [ + '--no-cache', + '--config=./config/jest.config.js', + ]); + + expect(result.status).toBe(0); + }); + + it('Should fail resolving tsconfig with wrong relative path', () => { + const result = runJest('../rel-config-paths', [ + '--no-cache', + '--config=./config/jest.config.invalid.js', + ]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain( + 'Unable to find tsconfig file given "./tsconfig.test.json"', + ); + }); +}); diff --git a/tests/rel-config-paths/config/jest.config.invalid.js b/tests/rel-config-paths/config/jest.config.invalid.js new file mode 100644 index 0000000000..4f0b49dfe3 --- /dev/null +++ b/tests/rel-config-paths/config/jest.config.invalid.js @@ -0,0 +1,14 @@ +module.exports = { + errorOnDeprecated: true, + globals: { + 'ts-jest': { + tsConfigFile: './tsconfig.test.json', + }, + }, + moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], + rootDir: '../', + testMatch: ['/custom-test-dir/**/*.ts'], + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, +}; diff --git a/tests/rel-config-paths/config/jest.config.js b/tests/rel-config-paths/config/jest.config.js new file mode 100644 index 0000000000..790e32b891 --- /dev/null +++ b/tests/rel-config-paths/config/jest.config.js @@ -0,0 +1,14 @@ +module.exports = { + errorOnDeprecated: true, + globals: { + 'ts-jest': { + tsConfigFile: '/config/tsconfig.test.json', + }, + }, + moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], + rootDir: '../', + testMatch: ['/custom-test-dir/**/*.ts'], + transform: { + '^.+\\.tsx?$': 'ts-jest', + }, +}; diff --git a/tests/rel-config-paths/config/tsconfig.base.json b/tests/rel-config-paths/config/tsconfig.base.json new file mode 100644 index 0000000000..3a7fb4da10 --- /dev/null +++ b/tests/rel-config-paths/config/tsconfig.base.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "baseUrl": "../", + "outDir": "../dist" + } +} diff --git a/tests/rel-config-paths/config/tsconfig.test.json b/tests/rel-config-paths/config/tsconfig.test.json new file mode 100644 index 0000000000..8000a52a3a --- /dev/null +++ b/tests/rel-config-paths/config/tsconfig.test.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "include": [ + "../custom-test-dir" + ] +} diff --git a/tests/rel-config-paths/custom-test-dir/test.ts b/tests/rel-config-paths/custom-test-dir/test.ts new file mode 100644 index 0000000000..e1db5bd814 --- /dev/null +++ b/tests/rel-config-paths/custom-test-dir/test.ts @@ -0,0 +1,9 @@ +declare var jest, describe, it, expect; + +import { hi } from '../src'; + +describe('hi', () => { + it('should say hi', () => { + expect(hi()).toBe('HI!'); + }); +}); diff --git a/tests/rel-config-paths/package.json b/tests/rel-config-paths/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/rel-config-paths/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/rel-config-paths/src/index.ts b/tests/rel-config-paths/src/index.ts new file mode 100644 index 0000000000..56966913e9 --- /dev/null +++ b/tests/rel-config-paths/src/index.ts @@ -0,0 +1,3 @@ +export function hi() { + return 'HI!'; +} From 5ab100c4712047ba13e00878552e69e53032ae63 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 26 Jul 2018 11:41:25 +0200 Subject: [PATCH 16/21] fix: resolves correctly config file path (fix #636) --- src/utils/get-ts-config.ts | 37 +++++++++++++------ tests/__helpers__/jest-config.ts | 2 +- .../tsconfig.json | 5 ++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/utils/get-ts-config.ts b/src/utils/get-ts-config.ts index 9a20bb1583..c556a4112e 100644 --- a/src/utils/get-ts-config.ts +++ b/src/utils/get-ts-config.ts @@ -7,9 +7,10 @@ import { ModuleKind, JsxEmit, } from 'typescript'; -import { resolve, sep } from 'path'; +import { resolve, sep, dirname } from 'path'; +import { existsSync } from 'fs'; import formatTsDiagnostics from './format-diagnostics'; -import closestFileData, { IClosestDataResult } from 'closest-file-data'; +import closestFileData from 'closest-file-data'; import { memoize } from 'lodash'; import { logOnce } from './logger'; import getTSJestConfig from './get-ts-jest-config'; @@ -18,7 +19,7 @@ const getTSConfig = memoize(getTSConfig_local, jestConfig => { // check cache before resolving configuration // NB: We use JSON.stringify() to create a consistent, unique signature. Although it lacks a uniform // shape, this is simpler and faster than using the crypto package to generate a hash signature. - return JSON.stringify(jestConfig); + return JSON.stringify({ ...jestConfig, name: null, cacheDirectory: null }); }); export default getTSConfig; @@ -33,7 +34,7 @@ function getTSConfig_local(jestConfig: jest.ProjectConfig): CompilerOptions { const { path: configPath } = configMeta; logOnce(`Reading tsconfig file from path ${configPath}`); - const config = readCompilerOptions(configPath, jestConfig.rootDir); + const config = readCompilerOptions(configPath); logOnce('Original typescript config before modifications: ', { ...config }); // tsc should not emit declaration map when used for tests @@ -70,11 +71,8 @@ function getTSConfig_local(jestConfig: jest.ProjectConfig): CompilerOptions { return config; } -function readCompilerOptions( - configPath: string, - rootDir: string, -): CompilerOptions { - configPath = resolve(rootDir, configPath); +function readCompilerOptions(configPath: string): CompilerOptions { + // at this point the configPath is resolved const { config, error } = readConfigFile(configPath, sys.readFile); if (error) { throw error; @@ -83,7 +81,8 @@ function readCompilerOptions( const { errors, options } = parseJsonConfigFileContent( config, sys, - resolve(rootDir), + // paths in a tsconfig are relative to that file's path + dirname(configPath), ); if (errors.length > 0) { @@ -117,13 +116,29 @@ function findTSConfigPath( ): { isUserDefined?: boolean; path: string } | void { let tsConfigFile = getTSJestConfig(jestConfig).tsConfigFile; if (tsConfigFile) { + const givenConfigFile = tsConfigFile; tsConfigFile = tsConfigFile.replace( '', `${jestConfig.rootDir}${sep}`, ); - tsConfigFile = resolve(jestConfig.rootDir, tsConfigFile); + // ensure the path is resolved + if (!tsConfigFile.startsWith('/')) { + tsConfigFile = resolve(jestConfig.rootDir, tsConfigFile); + } else { + tsConfigFile = resolve(tsConfigFile); + } + if (!existsSync(tsConfigFile)) { + throw new Error( + [ + `Unable to find tsconfig file given "${givenConfigFile}". If you gave a relative path,`, + `it'll be relative to the resolved "rootDir".\nTo avoid issues, use followed`, + `by a relative path to it in "tsConfigFile" config key.`, + ].join(' '), + ); + } return { path: tsConfigFile, isUserDefined: true }; } + // try to find the config file starting from the root dir as defined in (or resolved by) jest config return closestFileData(jestConfig.rootDir, tsConfigReader); } diff --git a/tests/__helpers__/jest-config.ts b/tests/__helpers__/jest-config.ts index 5b9911b1a6..61b8c7bcff 100644 --- a/tests/__helpers__/jest-config.ts +++ b/tests/__helpers__/jest-config.ts @@ -11,7 +11,7 @@ function createJestConfig( let options = { ...jestOptions }; if (tsJestOptions) options.globals = { ...options.globals, 'ts-jest': tsJestOptions }; - return { rootDir, ...options } as any; + return { rootDir, cwd: rootDir, ...options } as any; } require('fs').read; const jestConfig = Object.assign(createJestConfig, { diff --git a/tests/use-config-from-node-modules/tsconfig.json b/tests/use-config-from-node-modules/tsconfig.json index 55f8667f97..5feb961b7d 100644 --- a/tests/use-config-from-node-modules/tsconfig.json +++ b/tests/use-config-from-node-modules/tsconfig.json @@ -6,5 +6,8 @@ "noEmitOnError": false, "jsx": "react", "allowJs": true - } + }, + "include": [ + "../../**/*" + ] } From fbe4f1f37e6e2f51855bff1ffba552c6739dc7f1 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Thu, 26 Jul 2018 11:42:10 +0200 Subject: [PATCH 17/21] perf: do not hash cache key, jest does it underneath --- package.json | 3 ++- src/utils/constants.ts | 1 + src/utils/get-babel-rc.ts | 1 - src/utils/get-cache-key.ts | 27 ++++++++++----------------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index a76fa67e3a..88540da339 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,8 @@ }, "peerDependencies": { "babel-core": "^7.0.0-0", - "jest": "^23.0.0 || ^24.0.0", + "babel-jest": "^23.0.0", + "jest": "^23.0.0", "typescript": "2.x" }, "devDependencies": { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index b8556ac8ac..675384cd92 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -9,4 +9,5 @@ export const TSCONFIG_GLOBALS_KEY = 'ts-jest'; export const PACKAGE_JSON = 'package.json'; export const MY_PACKAGE_CONTENT = readFileSync( resolve(__dirname, '..', '..', PACKAGE_JSON), + 'utf8', ); diff --git a/src/utils/get-babel-rc.ts b/src/utils/get-babel-rc.ts index c49e799531..0e7b665102 100644 --- a/src/utils/get-babel-rc.ts +++ b/src/utils/get-babel-rc.ts @@ -6,7 +6,6 @@ import { PACKAGE_JSON, BABEL_CONFIG_KEY, } from './constants'; -import { BabelTransformOptions } from '../types'; const babelReaders = [ { diff --git a/src/utils/get-cache-key.ts b/src/utils/get-cache-key.ts index b6a969d51a..f213e31923 100644 --- a/src/utils/get-cache-key.ts +++ b/src/utils/get-cache-key.ts @@ -1,4 +1,3 @@ -import { createHash } from 'crypto'; import { JestCacheKeyOptions } from '../types'; import { relative } from 'path'; import { MY_PACKAGE_CONTENT } from './constants'; @@ -14,20 +13,14 @@ export default function getCacheKey( const jestConfig: jest.ProjectConfig = JSON.parse(jestConfigString) || {}; delete jestConfig.cacheDirectory; delete jestConfig.name; - const hash = createHash('md5') - .update(MY_PACKAGE_CONTENT) - .update('\0', 'utf8') - .update(fileData) - .update('\0', 'utf8') - .update(relative(rootDir, filePath)) - .update('\0', 'utf8') - .update(jestConfigString) - .update('\0', 'utf8') - .update(JSON.stringify(getTSConfig(jestConfig))) - .update('\0', 'utf8'); - const babelRc = getBabelRC(filePath); - if (babelRc) { - hash.update(JSON.stringify(babelRc)).update('\0', 'utf8'); - } - return hash.update(instrument ? 'instrument' : '').digest('hex'); + // jest creates hash under the hoods + return JSON.stringify([ + MY_PACKAGE_CONTENT, + fileData, + relative(rootDir, filePath), + jestConfig, + getTSConfig(jestConfig), + getBabelRC(filePath), + instrument, + ]); } From 4fc3933cf4de03e5b8172be6561a227d7f7554de Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Fri, 27 Jul 2018 11:46:14 +0200 Subject: [PATCH 18/21] chore: changes after GeeWee review - re-added a removed test related to cache key - cleaned-up deps --- package.json | 6 ++---- tests/__tests__/get-cache-key.spec.ts | 16 ++++++++++++++++ yarn.lock | 14 -------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 88540da339..747f92f66a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "clean-build": "npm run clean && npm run build", "pretest": "npm run tslint && npm run clean-build", "test": "node scripts/tests.js", - "test:unit": "jest --testRegex '' --testMatch '/src/**/*.spec.ts'", "tslint": "tslint 'src/**/*.ts'", "doc": "doctoc .", "prepublish": "npm run clean-build", @@ -79,6 +78,7 @@ "peerDependencies": { "babel-core": "^7.0.0-0", "babel-jest": "^23.0.0", + "@babel/preset-env": "^7.0.0", "jest": "^23.0.0", "typescript": "2.x" }, @@ -87,19 +87,17 @@ "@babel/preset-env": "^7.0.0-beta.54", "@types/babel-core": "^6.25.5", "@types/es6-shim": "0.31.37", - "@types/flat": "^0.0.28", "@types/fs-extra": "5.0.4", "@types/jest": "^23.3.0", "@types/lodash": "^4.14.109", "@types/node": "10.5.2", "@types/react": "16.4.6", "@types/yargs": "^11.0.0", - "babel-plugin-istanbul": "^4.1.6", + "babel-jest": "^23.4.0", "babel-preset-jest": "^23.2.0", "cross-spawn": "latest", "cross-spawn-with-kill": "latest", "doctoc": "latest", - "flat": "^4.1.0", "husky": "^0.14.3", "jest": "^23.4.1", "lint-staged": "^7.1.2", diff --git a/tests/__tests__/get-cache-key.spec.ts b/tests/__tests__/get-cache-key.spec.ts index 38a07ebd99..9fff410267 100644 --- a/tests/__tests__/get-cache-key.spec.ts +++ b/tests/__tests__/get-cache-key.spec.ts @@ -1,5 +1,15 @@ import getCacheKey from '../../dist/utils/get-cache-key'; import cfg from '../__helpers__/jest-config'; +import _getTSConfig from '../../dist/utils/get-ts-config'; + +jest.mock('../../dist/utils/get-ts-config', () => { + return { + default: jest.fn(() => ({ foo: 'bar' })), + }; +}); + +// type casting +const getTSConfig: jest.Mock = _getTSConfig as any; describe('getCacheKey', () => { const src = 'console.log(123);'; @@ -24,6 +34,12 @@ describe('getCacheKey', () => { expect(newHash).not.toBe(originalHash); }); + it('should change hash when tsconfig changes', () => { + getTSConfig.mockImplementationOnce(() => ({ not_foo: 'not bar' })); + const newHash = getCacheKey(src, filepath, configStr, options); + expect(newHash).not.toBe(originalHash); + }); + it('should change hash when transform options change', () => { const newOptions = { ...options, instrument: true }; const newHash = getCacheKey(src, filepath, configStr, newOptions); diff --git a/yarn.lock b/yarn.lock index 21439109a3..b36a6fdfcb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -564,10 +564,6 @@ version "0.31.37" resolved "https://registry.yarnpkg.com/@types/es6-shim/-/es6-shim-0.31.37.tgz#d01fa9b61a6692e57387dde5483b0255659ba70f" -"@types/flat@^0.0.28": - version "0.0.28" - resolved "https://registry.yarnpkg.com/@types/flat/-/flat-0.0.28.tgz#5c788149d85a6cf8ff5f5f000acdd912cdea4274" - "@types/fs-extra@5.0.4": version "5.0.4" resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-5.0.4.tgz#b971134d162cc0497d221adde3dbb67502225599" @@ -1902,12 +1898,6 @@ find-up@^3.0.0: dependencies: locate-path "^3.0.0" -flat@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/flat/-/flat-4.1.0.tgz#090bec8b05e39cba309747f1d588f04dbaf98db2" - dependencies: - is-buffer "~2.0.3" - for-in@^1.0.1, for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -2329,10 +2319,6 @@ is-buffer@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" -is-buffer@~2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725" - is-builtin-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" From ddc8c321a8290ed23d52b7f8bc89b15ff3b0c15d Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Fri, 27 Jul 2018 14:22:52 +0200 Subject: [PATCH 19/21] chore: moves test-utils.ts in __helpers__ dir --- tests/{utils => __helpers__}/test-utils.ts | 0 tests/__tests__/jestconfig-json.spec.ts | 2 +- tests/__tests__/jestconfig-package.spec.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/{utils => __helpers__}/test-utils.ts (100%) diff --git a/tests/utils/test-utils.ts b/tests/__helpers__/test-utils.ts similarity index 100% rename from tests/utils/test-utils.ts rename to tests/__helpers__/test-utils.ts diff --git a/tests/__tests__/jestconfig-json.spec.ts b/tests/__tests__/jestconfig-json.spec.ts index 3bb5e4ce2e..d01904edc7 100644 --- a/tests/__tests__/jestconfig-json.spec.ts +++ b/tests/__tests__/jestconfig-json.spec.ts @@ -1,5 +1,5 @@ import * as pkgDir from 'pkg-dir'; -import { getJestConfig } from '../utils/test-utils'; +import { getJestConfig } from '../__helpers__/test-utils'; describe('get json jest config', () => { let yargsMock; diff --git a/tests/__tests__/jestconfig-package.spec.ts b/tests/__tests__/jestconfig-package.spec.ts index 154f8f898c..97d61e3a09 100644 --- a/tests/__tests__/jestconfig-package.spec.ts +++ b/tests/__tests__/jestconfig-package.spec.ts @@ -1,5 +1,5 @@ import * as pkgDir from 'pkg-dir'; -import { getJestConfig } from '../utils/test-utils'; +import { getJestConfig } from '../__helpers__/test-utils'; describe('get package json config', () => { let yargsMock; From fb5cd12a664b159ac841dfa3646f766a75f84134 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Fri, 27 Jul 2018 15:58:25 +0200 Subject: [PATCH 20/21] chore: simplify jest config test helper + moves test utils - removes complex jest-config test helpers and simplify the tool - removes unused (anymore) rootDir() related code - improves readability of html-transform test - moves `test-utils.ts` into `__helpers__` dir --- scripts/tests.js | 17 +- src/preprocess.ts | 6 +- src/utils/get-ts-config.ts | 13 -- tests/__helpers__/jest-config.ts | 210 ---------------------- tests/__helpers__/mock-jest-config.ts | 26 +++ tests/__tests__/get-cache-key.spec.ts | 7 +- tests/__tests__/html-transform.spec.ts | 51 ++++-- tests/__tests__/postprocess.spec.ts | 4 +- tests/__tests__/tsconfig-comments.spec.ts | 16 +- tests/__tests__/tsconfig-default.spec.ts | 34 ++-- tests/__tests__/tsconfig-string.spec.ts | 10 +- 11 files changed, 116 insertions(+), 278 deletions(-) delete mode 100644 tests/__helpers__/jest-config.ts create mode 100644 tests/__helpers__/mock-jest-config.ts diff --git a/scripts/tests.js b/scripts/tests.js index 2bd482195c..a06cdf7bb3 100644 --- a/scripts/tests.js +++ b/scripts/tests.js @@ -13,11 +13,19 @@ function getDirectories(rootDir) { }); } +function isJestFolder(basename) { + return basename.startsWith('__') && basename.endsWith('__'); +} + +// TODO: later we could add a `.test-case-keep` empty file in each folder? +// ...or move all into a `test-cases` dedicated directory +function isTestCaseFolder(basename) { + return !isJestFolder(basename); +} + function createIntegrationMock() { const testsRoot = 'tests'; - const testCaseFolders = getDirectories(testsRoot).filter(function(testDir) { - return !/^(?:utils|__.+__)$/.test(testDir); - }); + const testCaseFolders = getDirectories(testsRoot).filter(isTestCaseFolder); testCaseFolders.forEach(directory => { const testCaseNodeModules = path.join(testsRoot, directory, 'node_modules'); @@ -41,9 +49,6 @@ function createIntegrationMock() { createIntegrationMock(); -// HACK: allow us to change the `startDir()` during tests -process.env.__RUNNING_TS_JEST_TESTS = Date.now(); - const argv = process.argv.slice(2); argv.push('--no-cache'); argv.push('--testPathPattern', '^(?!(.*watch.spec.ts$)).*'); diff --git a/src/preprocess.ts b/src/preprocess.ts index 9e954bd46c..064e901001 100644 --- a/src/preprocess.ts +++ b/src/preprocess.ts @@ -22,7 +22,11 @@ export default function preprocess( const isHtmlFile = /\.html$/.test(filePath); // This is to support angular 2. See https://github.com/kulshekhar/ts-jest/pull/145 - if (isHtmlFile && (jestConfig.globals as any).__TRANSFORM_HTML__) { + if ( + isHtmlFile && + jestConfig.globals && + (jestConfig.globals as any).__TRANSFORM_HTML__ + ) { src = 'module.exports=' + JSON.stringify(src) + ';'; } diff --git a/src/utils/get-ts-config.ts b/src/utils/get-ts-config.ts index c556a4112e..6c018303ed 100644 --- a/src/utils/get-ts-config.ts +++ b/src/utils/get-ts-config.ts @@ -95,19 +95,6 @@ function readCompilerOptions(configPath: string): CompilerOptions { return options; } -// function getStartDir(jestConfig: jest.ProjectConfig): string { -// // This is needed because of the way our tests are structured. -// // If this is being executed as a library (under node_modules) -// // we want to start with the project directory that's three -// // levels above. -// // If this is being executed from the test suite, we want to start -// // in the directory of the test - -// // TODO: shouldn't we use the path of jest config here instead of '.' ? -// // return process.env.__RUNNING_TS_JEST_TESTS ? process.cwd() : '.'; -// return process.env.__RUNNING_TS_JEST_TESTS ? process.cwd() : (jestConfig.rootDir || process.cwd()); -// } - // we don't need any data, just its full path const tsConfigReader = { basename: TSCONFIG_FILENAME, read: () => 0 }; diff --git a/tests/__helpers__/jest-config.ts b/tests/__helpers__/jest-config.ts deleted file mode 100644 index 61b8c7bcff..0000000000 --- a/tests/__helpers__/jest-config.ts +++ /dev/null @@ -1,210 +0,0 @@ -import { TsJestConfig } from '../../dist/types'; - -const { resolve } = require.requireActual('path'); - -function createJestConfig( - testModulePath: string, - tsJestOptions: TsJestConfig | null = null, - jestOptions: jest.InitialOptions = {}, -): jest.ProjectConfig { - const rootDir = resolve(__dirname, '..', testModulePath); - let options = { ...jestOptions }; - if (tsJestOptions) - options.globals = { ...options.globals, 'ts-jest': tsJestOptions }; - return { rootDir, cwd: rootDir, ...options } as any; -} -require('fs').read; -const jestConfig = Object.assign(createJestConfig, { - babelConfig: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('babel-config', t, j), - babelConfigInvalid: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('babel-config-invalid', t, j), - babelConfigMergeIgnoreBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => createJestConfig('babel-config-merge-ignore-babelrc', t, j), - babelConfigMergeWithBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => createJestConfig('babel-config-merge-with-babelrc', t, j), - button: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('button', t, j), - dynamicImports: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('dynamic-imports', t, j), - hoistErrors: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('hoist-errors', t, j), - hoistTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('hoist-test', t, j), - importsTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('imports-test', t, j), - jestProjects: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('jest-projects', t, j), - jestProjectsWithWorkspace: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => createJestConfig('jest-projects-with-workspace', t, j), - jestconfigTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('jestconfig-test', t, j), - metadataEmit: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('metadata-emit', t, j), - noJsonModuleFileExt: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('no-json-module-file-ext', t, j), - noSourcemaps: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('no-sourcemaps', t, j), - noSyntheticDefault: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('no-synthetic-default', t, j), - simple: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('simple', t, j), - simpleAsync: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('simple-async', t, j), - simpleLongPath: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('simple-long-path', t, j), - skipBabelrc: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('skip-babelrc', t, j), - syntheticDefault: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('synthetic-default', t, j), - tsDiagnostics: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('ts-diagnostics', t, j), - tsJestModuleInterface: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('ts-jest-module-interface', t, j), - tsconfigTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('tsconfig-test', t, j), - useBabelrc: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('use-babelrc', t, j), - useConfigFromNodeModules: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => createJestConfig('use-config-from-node-modules', t, j), - useStrict: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('use-strict', t, j), - utils: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('utils', t, j), - watchTest: (t?: TsJestConfig | null, j?: jest.InitialOptions) => - createJestConfig('watch-test', t, j), -}); - -interface TestJestConfigHelpers { - ( - testModulePath: string, - tsJestOptions?: TsJestConfig | null, - jestOptions?: jest.InitialOptions, - ): jest.ProjectConfig; - babelConfig: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - babelConfigInvalid: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - babelConfigMergeIgnoreBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - babelConfigMergeWithBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - button: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - dynamicImports: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - hoistErrors: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - hoistTest: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - importsTest: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - jestProjects: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - jestProjectsWithWorkspace: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - jestconfigTest: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - metadataEmit: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - noJsonModuleFileExt: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - noSourcemaps: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - noSyntheticDefault: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - simple: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - simpleAsync: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - simpleLongPath: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - skipBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - syntheticDefault: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - tsDiagnostics: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - tsJestModuleInterface: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - tsconfigTest: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - useBabelrc: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - useConfigFromNodeModules: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - useStrict: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - utils: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; - watchTest: ( - t?: TsJestConfig | null, - j?: jest.InitialOptions, - ) => jest.ProjectConfig; -} - -export default jestConfig as TestJestConfigHelpers; diff --git a/tests/__helpers__/mock-jest-config.ts b/tests/__helpers__/mock-jest-config.ts new file mode 100644 index 0000000000..8981a549ad --- /dev/null +++ b/tests/__helpers__/mock-jest-config.ts @@ -0,0 +1,26 @@ +import { TsJestConfig } from '../../dist/types'; + +const { resolve } = require.requireActual('path'); + +/** + * Mock a jest config object for the test case in given folder + * + * Basically it defines `rootDir` and `cwd` properties to the full path of that + * test case, as Jest would do. + * + * Accepts an optional config object, which will be defined on `globals.ts-jest` + */ +export default function mockJestConfig( + testCaseFolder: string, + tsJest: TsJestConfig | null = null, +): jest.ProjectConfig { + // resolves the path since jest would give a resolved path + const rootDir = resolve(__dirname, '..', testCaseFolder); + // create base jest config object + let options: any = { rootDir, cwd: rootDir }; + // adds TS Jest options if any given + if (tsJest != null) { + options.globals = { 'ts-jest': tsJest }; + } + return options; +} diff --git a/tests/__tests__/get-cache-key.spec.ts b/tests/__tests__/get-cache-key.spec.ts index 9fff410267..d71ccab5b6 100644 --- a/tests/__tests__/get-cache-key.spec.ts +++ b/tests/__tests__/get-cache-key.spec.ts @@ -1,5 +1,5 @@ import getCacheKey from '../../dist/utils/get-cache-key'; -import cfg from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; import _getTSConfig from '../../dist/utils/get-ts-config'; jest.mock('../../dist/utils/get-ts-config', () => { @@ -13,10 +13,11 @@ const getTSConfig: jest.Mock = _getTSConfig as any; describe('getCacheKey', () => { const src = 'console.log(123);'; - const jestConfig = cfg.simple(null, { + const jestConfig = { + ...mockJestConfig('simple'), transform: { '^.+\\\\.tsx?$': '../../preprocessor.js' }, testRegex: '(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.(jsx?|tsx?)$', - }); + }; const filepath = `${jestConfig.rootDir}/some-file.ts`; const configStr = JSON.stringify(jestConfig); const options = { instrument: false, rootDir: jestConfig.rootDir }; diff --git a/tests/__tests__/html-transform.spec.ts b/tests/__tests__/html-transform.spec.ts index 718b5f797a..b25d88fa1c 100644 --- a/tests/__tests__/html-transform.spec.ts +++ b/tests/__tests__/html-transform.spec.ts @@ -1,32 +1,47 @@ import * as tsJest from '../../dist'; -import jestConfig from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; -const config = jestConfig.simple({}); -const filePath = `${config.rootDir}/some-file.html`; +const TEST_CASE = 'simple'; +const FILENAME = 'some-file.html'; -// 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; - -const source = `
+const fileContent = `
This is element This is a backtilt \`
`; describe('Html transforms', () => { it('transforms html if config.globals.__TRANSFORM_HTML__ is set', () => { + let jestConfig; + // get the untransformed version - const untransformed = tsJest.process(source, filePath, { ...config }); - // ... then the one which should be transformed - (config.globals as any).__TRANSFORM_HTML__ = true; - const transformed = tsJest.process(source, filePath, config) as string; - // ... finally the result of a `require('module-with-transformed-version')` - const exported = wrap(transformed)(); + jestConfig = mockJestConfig(TEST_CASE); + const untransformed = tsJest.process( + fileContent, + `${jestConfig.rootDir}/${FILENAME}`, + jestConfig, + ); + expect(untransformed).toBe(fileContent); + expect(untransformed).toMatchSnapshot('untransformed'); - expect(exported).toMatchSnapshot('module'); + // ... then the one which should be transformed + jestConfig = { + ...mockJestConfig(TEST_CASE), + globals: { __TRANSFORM_HTML__: true }, + }; + const transformed = tsJest.process( + fileContent, + `${jestConfig.rootDir}/${FILENAME}`, + jestConfig, + ) as string; + expect(transformed).not.toBe(fileContent); expect(transformed).toMatchSnapshot('source'); - expect(untransformed).toMatchSnapshot('untransformed'); - // requiring the transformed version should return the same string as the untransformed version - expect(exported).toBe(untransformed); + + // ... finally the result of a `require('module-with-transformed-version')` + const value = eval( + `(function(){const module={}; ${transformed}; return module.exports;})()`, + ); + expect(value).toMatchSnapshot('module'); + // the value should be the same string as the source version + expect(value).toBe(fileContent); }); }); diff --git a/tests/__tests__/postprocess.spec.ts b/tests/__tests__/postprocess.spec.ts index 74792d0ac2..8e03b265a0 100644 --- a/tests/__tests__/postprocess.spec.ts +++ b/tests/__tests__/postprocess.spec.ts @@ -7,7 +7,7 @@ jest.mock('@babel/core', () => { }); import { getPostProcessHook } from '../../dist/postprocess'; -import jestConfig from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; describe('postprocess', () => { function runHook(jestConfig = {} as any) { @@ -32,7 +32,7 @@ describe('postprocess', () => { const transformMock = require.requireMock('@babel/core').transform; runHook(); - getPostProcessHook(jestConfig.simple())( + getPostProcessHook(mockJestConfig('simple'))( { code: 'input_code', map: '"input_source_map"' }, 'fake_file', {} as any, diff --git a/tests/__tests__/tsconfig-comments.spec.ts b/tests/__tests__/tsconfig-comments.spec.ts index 7479c721f6..28aa8a7f1b 100644 --- a/tests/__tests__/tsconfig-comments.spec.ts +++ b/tests/__tests__/tsconfig-comments.spec.ts @@ -3,7 +3,9 @@ jest.mock('path'); import * as fs from 'fs'; import getTSConfig from '../../dist/utils/get-ts-config'; import * as path from 'path'; -import cfg from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; + +const TEST_CASE = 'tsconfig-test'; describe('parse tsconfig with comments', () => { const configFile1 = './tests/tsconfig-test/allows-comments.json'; @@ -38,16 +40,16 @@ describe('parse tsconfig with comments', () => { // while allows-comments2.json does. // allow-comments.json extends allow-comments2.json it('should correctly read allow-comments.json', () => { - const config = getTSConfig( - cfg.tsconfigTest({ tsConfigFile: 'allows-comments.json' }), + const tsConfig = getTSConfig( + mockJestConfig(TEST_CASE, { tsConfigFile: 'allows-comments.json' }), ); - expect(config).toMatchSnapshot(); + expect(tsConfig).toMatchSnapshot(); }); it('should correctly read allow-comments2.json', () => { - const config = getTSConfig( - cfg.tsconfigTest({ tsConfigFile: 'allows-comments2.json' }), + const tsConfig = getTSConfig( + mockJestConfig(TEST_CASE, { tsConfigFile: 'allows-comments2.json' }), ); - expect(config).toMatchSnapshot(); + expect(tsConfig).toMatchSnapshot(); }); }); }); diff --git a/tests/__tests__/tsconfig-default.spec.ts b/tests/__tests__/tsconfig-default.spec.ts index dbfc24c89f..d9b3cae369 100644 --- a/tests/__tests__/tsconfig-default.spec.ts +++ b/tests/__tests__/tsconfig-default.spec.ts @@ -4,9 +4,11 @@ jest.mock('path'); import * as ts from 'typescript'; import getTSConfig from '../../dist/utils/get-ts-config'; import * as path from 'path'; -import jestConfig from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; import getTSJestConfig from '../../dist/utils/get-ts-jest-config'; +const TEST_CASE = 'tsconfig-test'; + describe('get default ts config', () => { beforeEach(() => { // Set up some mocked out file info before each test @@ -19,44 +21,46 @@ describe('get default ts config', () => { // there is no tsconfig file in that test module ((path as any) as MockedPath).__setBaseDir('./tests/jestconfig-test'); - expect(() => getTSConfig(jestConfig.jestconfigTest(null))).toThrowError( + expect(() => getTSConfig(mockJestConfig('jestconfig-test'))).toThrowError( /unable to find ts configuration file/i, ); }); it('should correctly read tsconfig.json', () => { - const result = getTSConfig(jestConfig.tsconfigTest(null)); + const result = getTSConfig(mockJestConfig(TEST_CASE)); expect(result).toMatchSnapshot(); }); describe('new behavior (tsConfigFile & tsConfig)', () => { it('should be same results for null/undefined/etc.', () => { - const result = getTSConfig(jestConfig.tsconfigTest(null)); - const resultEmptyParam = getTSConfig(jestConfig.tsconfigTest({})); + const resultWithoutTsJestSection = getTSConfig( + mockJestConfig(TEST_CASE, null), + ); + const resultEmptyParam = getTSConfig(mockJestConfig(TEST_CASE, {})); const resultUndefinedContentFile = getTSConfig( - jestConfig.tsconfigTest({ tsConfigFile: undefined }), + mockJestConfig(TEST_CASE, { tsConfigFile: undefined }), ); const resultNullContentFile = getTSConfig( - jestConfig.tsconfigTest({ tsConfigFile: null }), + mockJestConfig(TEST_CASE, { tsConfigFile: null }), ); - expect(result).toEqual(resultEmptyParam); - expect(result).toEqual(resultUndefinedContentFile); - expect(result).toEqual(resultNullContentFile); + expect(resultEmptyParam).toEqual(resultWithoutTsJestSection); + expect(resultUndefinedContentFile).toEqual(resultWithoutTsJestSection); + expect(resultNullContentFile).toEqual(resultWithoutTsJestSection); }); it('should be different results for different rootDir with same jest config.', () => { - const rootConfig = getTSConfig(jestConfig.tsconfigTest()); + const rootConfig = getTSConfig(mockJestConfig(TEST_CASE)); const subConfig = getTSConfig( - jestConfig('tsconfig-test/tsconfig-module'), + mockJestConfig(`${TEST_CASE}/tsconfig-module`), ); expect(rootConfig).not.toEqual(subConfig); }); it('should not change the module if it is loaded from a non-default config file', () => { const config = getTSConfig( - jestConfig.tsconfigTest({ + mockJestConfig(TEST_CASE, { tsConfigFile: 'tsconfig-module/custom-config.json', }), ); @@ -73,7 +77,9 @@ describe('get default ts config', () => { './tests/tsconfig-test/tsconfig-module', ); - const config = getTSConfig(jestConfig('tsconfig-test/tsconfig-module')); + const config = getTSConfig( + mockJestConfig(`${TEST_CASE}/tsconfig-module`), + ); expect(config.module).toBe(ts.ModuleKind.CommonJS); }); diff --git a/tests/__tests__/tsconfig-string.spec.ts b/tests/__tests__/tsconfig-string.spec.ts index 5b4285783a..2267ac95e9 100644 --- a/tests/__tests__/tsconfig-string.spec.ts +++ b/tests/__tests__/tsconfig-string.spec.ts @@ -3,7 +3,9 @@ jest.mock('path'); import getTSConfig from '../../dist/utils/get-ts-config'; import * as ts from 'typescript'; import * as path from 'path'; -import cfg from '../__helpers__/jest-config'; +import mockJestConfig from '../__helpers__/mock-jest-config'; + +const TEST_CASE = 'tsconfig-test'; describe('get ts config from string', () => { beforeEach(() => { @@ -15,7 +17,7 @@ describe('get ts config from string', () => { describe('new behaviour (tsConfigFile & tsConfig)', () => { it('should correctly read my-tsconfig.json', () => { const result = getTSConfig( - cfg.tsconfigTest({ tsConfigFile: 'my-tsconfig.json' }), + mockJestConfig(TEST_CASE, { tsConfigFile: 'my-tsconfig.json' }), ); // snapshot would be enough here, but that adds a security in case we do not see it in a PR @@ -25,7 +27,7 @@ describe('get ts config from string', () => { it('should correctly resolve the "extends" directive', () => { const result = getTSConfig( - cfg.tsconfigTest({ tsConfigFile: 'extends-tsconfig.json' }), + mockJestConfig(TEST_CASE, { tsConfigFile: 'extends-tsconfig.json' }), ); // snapshot would be enough here, but that adds a security in case we do not see it in a PR @@ -35,7 +37,7 @@ describe('get ts config from string', () => { it('should correctly override any config in the "extends" directive', () => { const result = getTSConfig( - cfg.tsconfigTest({ + mockJestConfig(TEST_CASE, { tsConfigFile: 'extends-with-overrides-tsconfig.json', }), ); From df71945d268d745f327185a0126844c0e7a2f140 Mon Sep 17 00:00:00 2001 From: Huafu Gandon Date: Sun, 29 Jul 2018 22:39:49 +0200 Subject: [PATCH 21/21] doc: adds troubleshooting wiki page links --- .github/ISSUE_TEMPLATE | 24 ------------------------ .github/ISSUE_TEMPLATE.md | 20 ++++++++++++++++++++ COLLABORATORS.md | 5 ++++- README.md | 13 +++---------- 4 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE deleted file mode 100644 index 1e3e0918f8..0000000000 --- a/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1,24 +0,0 @@ -- Issue - -[describe the issue here] - - - -- Expected behavior - -[describe the expected behavior here] - -- Output from your 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 **/node_modules/ts-jest/debug.txt** ] - - -- Link to a minimal repo that reproduces this issue - -[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] - - - -- 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. diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000000..7d0de3f241 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,20 @@ + + +## Issue : + + +## Expected behavior : + + +## Output from debug log : +```bash +# content of debug.txt : + +``` + + +## Minimal repo : + + + diff --git a/COLLABORATORS.md b/COLLABORATORS.md index 5522f6aa44..58da020c47 100644 --- a/COLLABORATORS.md +++ b/COLLABORATORS.md @@ -1,11 +1,14 @@ -**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* +**Table of Contents** - [Collaborator Guidelines](#collaborator-guidelines) - [Installing and building the project](#installing-and-building-the-project) - [Merging PRs](#merging-prs) - [Versioning](#versioning) + - [Tests](#tests) + - [How to add tests](#how-to-add-tests) + - [How to run tests](#how-to-run-tests) diff --git a/README.md b/README.md index 3972142522..c4206a4030 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,11 @@ -# ts-jest +# 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) -[![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/) +**Important note**: Before reporting any issue, be sure to check the [troubleshooting page](https://github.com/kulshekhar/ts-jest/wiki/Troubleshooting). -[![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) - -**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)** > Note: Looking for collaborators. [Want to help improve ts-jest?](https://github.com/kulshekhar/ts-jest/issues/223) -ts-jest is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript. +**ts-jest** is a TypeScript preprocessor with source map support for Jest that lets you use Jest to test projects written in TypeScript. ## Table of Contents @@ -383,7 +377,6 @@ By default Jest ignores everything in `node_modules`. This setting prevents Jest ## Known Limitations ### Known limitations for TS compiler options - You can't use `"target": "ES6"` while using `node v4` in your test environment; -- You can't use `"jsx": "preserve"` for now (see [progress of this issue](https://github.com/kulshekhar/ts-jest/issues/63)); - If you use `"baseUrl": ""`, you also have to change `jest config` a little bit (also check [Module path mapping](#module-path-mapping) section): ```json "jest": {