Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[RFC] Migrate Jest to TypeScript #7554

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -123,6 +123,7 @@ module.exports = {
'^types/(.*)': './types/$1',
},
},
'eslint-import-resolver-typescript': true,
},
},
};
11 changes: 10 additions & 1 deletion babel.config.js
Expand Up @@ -2,6 +2,16 @@

module.exports = {
babelrcRoots: ['examples/*'],
overrides: [
{
presets: ['@babel/preset-flow'],
test: '**/*.js',
},
{
presets: ['@babel/preset-typescript'],
test: '**/*.ts',
},
],
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
Expand All @@ -14,6 +24,5 @@ module.exports = {
targets: {node: 6},
},
],
'@babel/preset-flow',
],
};
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -55,6 +55,6 @@ module.exports = {
'/e2e/__tests__/iterator-to-null-test.js',
],
transform: {
'^.+\\.js$': '<rootDir>/packages/babel-jest',
'^.+\\.[jt]s$': '<rootDir>/packages/babel-jest',
},
};
12 changes: 8 additions & 4 deletions package.json
@@ -1,13 +1,17 @@
{
"private": true,
"devDependencies": {
"@babel/core": "^7.1.0",
"@babel/core": "^7.2.2",
"@babel/plugin-external-helpers": "^7.0.0",
"@babel/plugin-transform-strict-mode": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"@babel/register": "^7.0.0",
"@types/babel__core": "^7.0.0",
"@types/babel__generator": "^7.0.0",
"@types/babel__template": "^7.0.0",
"ansi-regex": "^4.0.0",
"ansi-styles": "^3.2.0",
"babel-eslint": "^9.0.0",
Expand All @@ -17,6 +21,7 @@
"debug": "^4.0.1",
"eslint": "^5.6.0",
"eslint-config-prettier": "^3.1.0",
"eslint-import-resolver-typescript": "^1.1.1",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-import": "^2.6.0",
Expand Down Expand Up @@ -56,17 +61,16 @@
"resolve": "^1.4.0",
"rimraf": "^2.6.2",
"rollup": "^0.66.1",
"rollup-plugin-babel": "^4.0.0",
"rollup-plugin-babel": "^4.1.0",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-builtins": "^2.1.1",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^3.4.0",
"slash": "^2.0.0",
"string-length": "^2.0.0",
"strip-ansi": "^5.0.0",
"typescript": "^3.0.3",
"typescript": "^3.2.2",
"watchify": "^3.9.0"
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-jest/package.json
Expand Up @@ -13,7 +13,8 @@
"babel-preset-jest": "^23.2.0"
},
"devDependencies": {
"@babel/core": "^7.1.0"
"@babel/core": "^7.1.0",
"@types/babel__core": "^7.0.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/expect/package.json
Expand Up @@ -16,6 +16,9 @@
"jest-message-util": "^23.4.0",
"jest-regex-util": "^23.3.0"
},
"devDependencies": {
"@types/ansi-styles": "^3.2.1"
},
"engines": {
"node": ">= 6"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-changed-files/package.json
Expand Up @@ -11,6 +11,9 @@
"execa": "^1.0.0",
"throat": "^4.0.0"
},
"devDependencies": {
"@types/execa": "^0.9.0"
},
"engines": {
"node": ">= 6"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/package.json
Expand Up @@ -23,6 +23,8 @@
"stack-utils": "^1.0.1"
},
"devDependencies": {
"@types/babel__traverse": "^7.0.4",
"@types/stack-utils": "^1.0.1",
"execa": "^1.0.0",
"jest-runtime": "^23.6.0"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/jest-cli/package.json
Expand Up @@ -41,6 +41,23 @@
"which": "^1.2.12",
"yargs": "^12.0.2"
},
"devDependencies": {
"@types/ansi-escapes": "^3.0.0",
"@types/exit": "^0.1.30",
"@types/glob": "^7.1.1",
"@types/graceful-fs": "^4.1.2",
"@types/is-ci": "^1.1.0",
"@types/istanbul-lib-coverage": "^1.1.0",
"@types/istanbul-lib-instrument": "^1.7.2",
"@types/istanbul-lib-source-maps": "^1.2.1",
"@types/micromatch": "^2.3.30",
"@types/node-notifier": "^0.0.28",
"@types/prompts": "^1.2.0",
"@types/rimraf": "^2.0.2",
"@types/string-length": "^2.0.0",
"@types/which": "^1.3.1",
"@types/yargs": "^12.0.2"
},
"bin": {
"jest": "./bin/jest.js"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-config/package.json
Expand Up @@ -23,6 +23,11 @@
"micromatch": "^2.3.11",
"pretty-format": "^23.6.0"
},
"devDependencies": {
"@types/babel__core": "^7.0.4",
"@types/glob": "^7.1.1",
"@types/micromatch": "^2.3.30"
},
"engines": {
"node": ">= 6"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-diff/package.json
Expand Up @@ -13,6 +13,9 @@
"jest-get-type": "^22.1.0",
"pretty-format": "^23.6.0"
},
"devDependencies": {
"@types/diff": "^3.5.2"
},
"engines": {
"node": ">= 6"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-docblock/package.json
Expand Up @@ -10,6 +10,9 @@
"dependencies": {
"detect-newline": "^2.1.0"
},
"devDependencies": {
"@types/detect-newline": "^2.1.0"
},
"engines": {
"node": ">= 6"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-environment-jsdom/package.json
Expand Up @@ -12,6 +12,9 @@
"jest-util": "^23.4.0",
"jsdom": "^11.5.1"
},
"devDependencies": {
"@types/jsdom": "^11.12.0"
},
"engines": {
"node": ">= 6"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-haste-map/package.json
Expand Up @@ -16,6 +16,13 @@
"micromatch": "^2.3.11",
"sane": "^3.0.0"
},
"devDependencies": {
"@types/fb-watchman": "^2.0.0",
"@types/graceful-fs": "^4.1.2",
"@types/invariant": "^2.2.29",
"@types/micromatch": "^2.3.30",
"@types/sane": "^2.0.0"
},
"engines": {
"node": ">= 6"
}
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/package.json
Expand Up @@ -22,6 +22,7 @@
"pretty-format": "^23.6.0"
},
"devDependencies": {
"@types/babel__traverse": "^7.0.4",
"jest-runtime": "^23.6.0"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-leak-detector/package.json
Expand Up @@ -11,6 +11,7 @@
"pretty-format": "^23.6.0"
},
"devDependencies": {
"@types/weak": "^1.0.0",
"weak": "^1.0.1"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-message-util/package.json
Expand Up @@ -16,5 +16,10 @@
"micromatch": "^2.3.11",
"slash": "^2.0.0",
"stack-utils": "^1.0.1"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.0",
"@types/micromatch": "^2.3.30",
"@types/stack-utils": "^1.0.1"
}
}
3 changes: 3 additions & 0 deletions packages/jest-repl/package.json
Expand Up @@ -15,6 +15,9 @@
"repl": "^0.1.3",
"yargs": "^12.0.2"
},
"devDependencies": {
"@types/yargs": "^12.0.2"
},
"bin": {
"jest-repl": "./bin/jest-repl.js"
},
Expand Down
1 change: 1 addition & 0 deletions packages/jest-resolve/package.json
Expand Up @@ -14,6 +14,7 @@
"realpath-native": "^1.0.0"
},
"devDependencies": {
"@types/browser-resolve": "^0.0.5",
"jest-haste-map": "^23.6.0"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-runner/package.json
Expand Up @@ -22,6 +22,11 @@
"source-map-support": "^0.5.6",
"throat": "^4.0.0"
},
"devDependencies": {
"@types/exit": "^0.1.30",
"@types/graceful-fs": "^4.1.2",
"@types/source-map-support": "^0.4.1"
},
"engines": {
"node": ">= 6"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/jest-runtime/package.json
Expand Up @@ -32,6 +32,15 @@
"yargs": "^12.0.2"
},
"devDependencies": {
"@types/babel__core": "^7.0.4",
"@types/convert-source-map": "^1.5.1",
"@types/exit": "^0.1.30",
"@types/glob": "^7.1.1",
"@types/graceful-fs": "^4.1.2",
"@types/micromatch": "^2.3.30",
"@types/strip-bom": "3.0.0",
"@types/write-file-atomic": "^2.1.1",
"@types/yargs": "^12.0.2",
"jest-environment-jsdom": "^23.4.0",
"jest-environment-node": "^23.4.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-snapshot/package.json
Expand Up @@ -20,6 +20,8 @@
"semver": "^5.5.0"
},
"devDependencies": {
"@types/mkdirp": "^0.5.2",
"@types/semver": "^5.5.0",
"prettier": "^1.13.4"
},
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-util/package.json
Expand Up @@ -18,6 +18,10 @@
"source-map": "^0.6.0"
},
"devDependencies": {
"@types/callsites": "^2.0.0",
"@types/graceful-fs": "^4.1.2",
"@types/is-ci": "^1.0.10",
"@types/mkdirp": "^0.5.2",
"jest-mock": "^23.2.0"
},
"engines": {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-validate/package.json
Expand Up @@ -14,6 +14,10 @@
"leven": "^2.1.0",
"pretty-format": "^23.6.0"
},
"devDependencies": {
"@types/camelcase": "^4.1.0",
"@types/leven": "^2.1.1"
},
"engines": {
"node": ">= 6"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-watcher/package.json
Expand Up @@ -9,6 +9,10 @@
"jest-util": "^23.4.0",
"string-length": "^2.0.0"
},
"devDependencies": {
"@types/ansi-escapes": "^3.0.0",
"@types/string-length": "^2.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest"
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-worker/package.json
Expand Up @@ -12,6 +12,8 @@
"supports-color": "^5.5.0"
},
"devDependencies": {
"@types/merge-stream": "^1.1.2",
"@types/supports-color": "^5.3.0",
"worker-farm": "^1.6.0"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions packages/pretty-format/package.json
Expand Up @@ -15,6 +15,8 @@
"ansi-styles": "^3.2.0"
},
"devDependencies": {
"@types/ansi-regex": "^4.0.0",
"@types/ansi-styles": "^3.2.1",
"immutable": "4.0.0-rc.9",
"react": "*",
"react-dom": "*",
Expand Down
Expand Up @@ -4,17 +4,16 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Config, Printer, Refs} from 'types/PrettyFormat';
import {Config, Printer, Refs} from './';

const getKeysOfEnumerableProperties = (object: Object) => {
const keys = Object.keys(object).sort();
const keys: Array<string | symbol> = Object.keys(object).sort();

if (Object.getOwnPropertySymbols) {
Object.getOwnPropertySymbols(object).forEach(symbol => {
//$FlowFixMe because property enumerable is missing in undefined
// @ts-ignore: because property enumerable is missing in undefined
if (Object.getOwnPropertyDescriptor(object, symbol).enumerable) {
keys.push(symbol);
}
Expand Down Expand Up @@ -180,7 +179,13 @@ export function printObjectProperties(
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const name = printer(key, config, indentationNext, depth, refs);
const value = printer(val[key], config, indentationNext, depth, refs);
const value = printer(
(val as any)[key],
config,
indentationNext,
depth,
refs,
);

result += indentationNext + name + ': ' + value;

Expand Down