From 8a1de28e1d59b8a79884551f661efa047f8e57f8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 18 Dec 2018 22:42:24 +0100 Subject: [PATCH 1/3] feat: handle typescript by default --- CHANGELOG.md | 1 + README.md | 2 +- docs/Configuration.md | 12 +++-- docs/GettingStarted.md | 4 +- .../__snapshots__/show_config.test.js.snap | 8 ++-- examples/typescript/package.json | 13 ------ .../__tests__/__snapshots__/init.test.js.snap | 45 ++----------------- .../jest-cli/src/lib/__tests__/init.test.js | 33 -------------- .../src/lib/init/generate_config_file.js | 17 +------ packages/jest-cli/src/lib/init/index.js | 19 +------- packages/jest-cli/src/lib/init/questions.js | 7 --- packages/jest-config/src/Defaults.js | 4 +- packages/jest-config/src/ValidConfig.js | 8 ++-- .../src/__tests__/normalize.test.js | 9 +++- packages/jest-config/src/constants.js | 2 +- packages/jest-config/src/normalize.js | 15 +++++++ ...runtime_require_module_no_ext.test.js.snap | 2 +- .../src/__tests__/fixtures/jestConfig.js | 4 +- website/pages/en/index.js | 6 +-- 19 files changed, 57 insertions(+), 154 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b67c1e28618..d235e735f6e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - `[jest-haste-map]` [**BREAKING**] Remove name from hash in `HasteMap.getCacheFilePath` ([#7218](https://github.com/facebook/jest/pull/7218)) - `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203)) - `[jest-haste-map]` [**BREAKING**] Expose relative paths when getting the file iterator ([#7321](https://github.com/facebook/jest/pull/7321)) +- `[jest-config]` Handle typescript (`ts` and `tsx`) by default - `[jest-validate]` Add support for comments in `package.json` using a `"//"` key ([#7295](https://github.com/facebook/jest/pull/7295)) - `[jest-config]` Add shorthand for watch plugins and runners ([#7213](https://github.com/facebook/jest/pull/7213)) - `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996)) diff --git a/README.md b/README.md index 2101801f4e6a..70bdce93b131 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Jest can be used in projects that use [webpack](https://webpack.js.org/) to mana ### Using TypeScript -To use TypeScript in your tests you can use [ts-jest](https://github.com/kulshekhar/ts-jest). +To use TypeScript in your tests you install `@babel/preset-typescript` and add it to your Babel config. diff --git a/docs/Configuration.md b/docs/Configuration.md index 0b32ac56fb74..76b65c2f9e69 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -367,12 +367,10 @@ An array of directory names to be searched recursively up from the requiring mod ### `moduleFileExtensions` [array] -Default: `["js", "json", "jsx", "node"]` +Default: `["js", "json", "jsx", "ts", "tsx", "node"]` An array of file extensions your modules use. If you require modules without specifying a file extension, these are the extensions Jest will look for. -If you are using TypeScript this should be `["js", "jsx", "json", "ts", "tsx"]`, check [ts-jest's documentation](https://github.com/kulshekhar/ts-jest). - ### `moduleNameMapper` [object] Default: `null` @@ -832,9 +830,9 @@ Test environment options that will be passed to the `testEnvironment`. The relev ### `testMatch` [array] -(default: `[ "**/__tests__/**/*.js?(x)", "**/?(*.)+(spec|test).js?(x)" ]`) +(default: `[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]`) -The glob patterns Jest uses to detect test files. By default it looks for `.js` and `.jsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. +The glob patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See the [micromatch](https://github.com/jonschlinkert/micromatch) package for details of the patterns you can specify. @@ -850,9 +848,9 @@ These pattern strings match against the full path. Use the `` string to ### `testRegex` [string | Array] -Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$` +Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$` -The pattern or patterns Jest uses to detect test files. By default it looks for `.js` and `.jsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array]](#testmatch-array-string), but note that you cannot specify both options. +The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array]](#testmatch-array-string), but note that you cannot specify both options. The following is a visualization of the default regex: diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index f2d41474a750..b2a0c1feaa9d 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -125,4 +125,6 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m ### Using TypeScript -To use TypeScript in your tests you can use [ts-jest](https://github.com/kulshekhar/ts-jest). +Jest support TypeScript out of the box, via Babel. + +However, there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest). diff --git a/e2e/__tests__/__snapshots__/show_config.test.js.snap b/e2e/__tests__/__snapshots__/show_config.test.js.snap index 3baf9f6336b1..b8da903ee666 100644 --- a/e2e/__tests__/__snapshots__/show_config.test.js.snap +++ b/e2e/__tests__/__snapshots__/show_config.test.js.snap @@ -31,6 +31,8 @@ exports[`--showConfig outputs config info and exits 1`] = ` \\"js\\", \\"json\\", \\"jsx\\", + \\"ts\\", + \\"tsx\\", \\"node\\" ], \\"moduleNameMapper\\": {}, @@ -54,8 +56,8 @@ exports[`--showConfig outputs config info and exits 1`] = ` \\"testEnvironmentOptions\\": {}, \\"testLocationInResults\\": false, \\"testMatch\\": [ - \\"**/__tests__/**/*.js?(x)\\", - \\"**/?(*.)+(spec|test).js?(x)\\" + \\"**/__tests__/**/*.[jt]s?(x)\\", + \\"**/?(*.)+(spec|test).[tj]s?(x)\\" ], \\"testPathIgnorePatterns\\": [ \\"/node_modules/\\" @@ -66,7 +68,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` \\"timers\\": \\"real\\", \\"transform\\": [ [ - \\"^.+\\\\\\\\.jsx?$\\", + \\"^.+\\\\\\\\.[jt]sx?$\\", \\"<>/babel-jest/build/index.js\\" ] ], diff --git a/examples/typescript/package.json b/examples/typescript/package.json index fe9610c671a1..8f1e3978696a 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -15,18 +15,5 @@ }, "scripts": { "test": "jest" - }, - "jest": { - "moduleFileExtensions": [ - "ts", - "tsx", - "js" - ], - "transform": { - "^.+\\.(ts|tsx)$": "babel-jest" - }, - "testMatch": [ - "**/__tests__/*.+(ts|tsx|js)" - ] } } diff --git a/packages/jest-cli/src/lib/__tests__/__snapshots__/init.test.js.snap b/packages/jest-cli/src/lib/__tests__/__snapshots__/init.test.js.snap index 31757651ce28..4d5fcf712ef1 100644 --- a/packages/jest-cli/src/lib/__tests__/__snapshots__/init.test.js.snap +++ b/packages/jest-cli/src/lib/__tests__/__snapshots__/init.test.js.snap @@ -91,6 +91,8 @@ module.exports = { // \\"js\\", // \\"json\\", // \\"jsx\\", + // \\"ts\\", + // \\"tsx\\", // \\"node\\" // ], @@ -158,8 +160,8 @@ module.exports = { // The glob patterns Jest uses to detect test files // testMatch: [ - // \\"**/__tests__/**/*.js?(x)\\", - // \\"**/?(*.)+(spec|test).js?(x)\\" + // \\"**/__tests__/**/*.[jt]s?(x)\\", + // \\"**/?(*.)+(spec|test).[tj]s?(x)\\" // ], // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped @@ -214,42 +216,3 @@ exports[`init project with package.json and no jest config some questions answer } " `; - -exports[`init typescript project should ask "typescript question" when has typescript in dependencies 1`] = ` -Object { - "initial": true, - "message": "Typescript detected, would you like to setup Jest for Typescript?", - "name": "typescript", - "type": "confirm", -} -`; - -exports[`init typescript project should ask "typescript question" when has typescript in devDependencies 1`] = ` -Object { - "initial": true, - "message": "Typescript detected, would you like to setup Jest for Typescript?", - "name": "typescript", - "type": "confirm", -} -`; - -exports[`init typescript project should create configuration for {typescript: true} 1`] = ` -Object { - "globals": Object { - "ts-jest": Object { - "tsConfigFile": "tsconfig.json", - }, - }, - "moduleFileExtensions": Array [ - "ts", - "tsx", - "js", - ], - "testMatch": Array [ - "**/__tests__/*.+(ts|tsx|js)", - ], - "transform": Object { - "^.+\\\\.(ts|tsx)$": "ts-jest", - }, -} -`; diff --git a/packages/jest-cli/src/lib/__tests__/init.test.js b/packages/jest-cli/src/lib/__tests__/init.test.js index 36833446f4f3..cda79a9b6d6b 100644 --- a/packages/jest-cli/src/lib/__tests__/init.test.js +++ b/packages/jest-cli/src/lib/__tests__/init.test.js @@ -181,37 +181,4 @@ describe('init', () => { expect(questionsNames).not.toContain('scripts'); }); }); - - describe('typescript project', () => { - it('should ask "typescript question" when has typescript in dependencies', async () => { - prompts.mockReturnValueOnce({}); - - await init(resolveFromFixture('typescript_in_dependencies')); - - const typescriptQuestion = prompts.mock.calls[0][0][0]; - - expect(typescriptQuestion).toMatchSnapshot(); - }); - - it('should ask "typescript question" when has typescript in devDependencies', async () => { - prompts.mockReturnValueOnce({}); - - await init(resolveFromFixture('typescript_in_dev_dependencies')); - - const typescriptQuestion = prompts.mock.calls[0][0][0]; - - expect(typescriptQuestion).toMatchSnapshot(); - }); - - it('should create configuration for {typescript: true}', async () => { - prompts.mockReturnValueOnce({typescript: true}); - - await init(resolveFromFixture('typescript_in_dev_dependencies')); - - const writtenJestConfig = fs.writeFileSync.mock.calls[0][1]; - const evaluatedConfig = eval(writtenJestConfig); - - expect(evaluatedConfig).toMatchSnapshot(); - }); - }); }); diff --git a/packages/jest-cli/src/lib/init/generate_config_file.js b/packages/jest-cli/src/lib/init/generate_config_file.js index db0cc819fe40..8156f450d6ae 100644 --- a/packages/jest-cli/src/lib/init/generate_config_file.js +++ b/packages/jest-cli/src/lib/init/generate_config_file.js @@ -33,25 +33,10 @@ const stringifyOption = ( }; const generateConfigFile = (results: {[string]: boolean}): string => { - const {typescript, coverage, clearMocks, environment} = results; + const {coverage, clearMocks, environment} = results; const overrides: Object = {}; - if (typescript) { - Object.assign(overrides, { - globals: { - 'ts-jest': { - tsConfigFile: 'tsconfig.json', - }, - }, - moduleFileExtensions: ['ts', 'tsx', 'js'], - testMatch: ['**/__tests__/*.+(ts|tsx|js)'], - transform: { - '^.+\\.(ts|tsx)$': 'ts-jest', - }, - }); - } - if (coverage) { Object.assign(overrides, { coverageDirectory: 'coverage', diff --git a/packages/jest-cli/src/lib/init/index.js b/packages/jest-cli/src/lib/init/index.js index 69dce1f32421..72ab36f64162 100644 --- a/packages/jest-cli/src/lib/init/index.js +++ b/packages/jest-cli/src/lib/init/index.js @@ -11,10 +11,7 @@ import chalk from 'chalk'; import fs from 'fs'; import path from 'path'; import prompts from 'prompts'; -import defaultQuestions, { - typescriptQuestion, - testScriptQuestion, -} from './questions'; +import defaultQuestions, {testScriptQuestion} from './questions'; import {NotFoundPackageJsonError, MalformedPackageJsonError} from './errors'; import {PACKAGE_JSON, JEST_CONFIG} from '../../constants'; import generateConfigFile from './generate_config_file'; @@ -25,7 +22,6 @@ type PromptsResults = { coverage: boolean, environment: boolean, scripts: boolean, - typescript: boolean, }; export default async (rootDir: string = process.cwd()) => { @@ -82,19 +78,6 @@ export default async (rootDir: string = process.cwd()) => { questions.unshift(testScriptQuestion); } - // Try to detect typescript and add a question if needed - const deps: Object = {}; - - Object.assign( - deps, - projectPackageJson.dependencies, - projectPackageJson.devDependencies, - ); - - if (Object.keys(deps).includes('typescript')) { - questions.unshift(typescriptQuestion); - } - // Start the init process console.log(); console.log( diff --git a/packages/jest-cli/src/lib/init/questions.js b/packages/jest-cli/src/lib/init/questions.js index 74183a8dd1fd..ea72185386b6 100644 --- a/packages/jest-cli/src/lib/init/questions.js +++ b/packages/jest-cli/src/lib/init/questions.js @@ -49,10 +49,3 @@ export const testScriptQuestion: Question = { name: 'scripts', type: 'confirm', }; - -export const typescriptQuestion: Question = { - initial: true, - message: 'Typescript detected, would you like to setup Jest for Typescript?', - name: 'typescript', - type: 'confirm', -}; diff --git a/packages/jest-config/src/Defaults.js b/packages/jest-config/src/Defaults.js index cb82c808267a..47e13dab8094 100644 --- a/packages/jest-config/src/Defaults.js +++ b/packages/jest-config/src/Defaults.js @@ -45,7 +45,7 @@ export default ({ providesModuleNodeModules: [], }, moduleDirectories: ['node_modules'], - moduleFileExtensions: ['js', 'json', 'jsx', 'node'], + moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], moduleNameMapper: {}, modulePathIgnorePatterns: [], noStackTrace: false, @@ -70,7 +70,7 @@ export default ({ testEnvironmentOptions: {}, testFailureExitCode: 1, testLocationInResults: false, - testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'], + testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], testPathIgnorePatterns: [NODE_MODULES_REGEXP], testRegex: [], testResultsProcessor: null, diff --git a/packages/jest-config/src/ValidConfig.js b/packages/jest-config/src/ValidConfig.js index 8ffb1455055c..c91c60b938a9 100644 --- a/packages/jest-config/src/ValidConfig.js +++ b/packages/jest-config/src/ValidConfig.js @@ -61,7 +61,7 @@ export default ({ lastCommit: false, logHeapUsage: true, moduleDirectories: ['node_modules'], - moduleFileExtensions: ['js', 'json', 'jsx', 'node'], + moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'], moduleLoader: '', moduleNameMapper: { '^React$': '/node_modules/react', @@ -100,12 +100,12 @@ export default ({ testEnvironmentOptions: {userAgent: 'Agent/007'}, testFailureExitCode: 1, testLocationInResults: false, - testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'], + testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'], testNamePattern: 'test signature', testPathIgnorePatterns: [NODE_MODULES_REGEXP], testRegex: multipleValidOptions( - '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', - ['/__tests__/\\.test\\.jsx?$', '/__tests__/\\.spec\\.jsx?$'], + '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', + ['/__tests__/\\.test\\.[jt]sx?$', '/__tests__/\\.spec\\.[jt]sx?$'], ), testResultsProcessor: 'processor-node-module', testRunner: 'jasmine2', diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 28c2aea79422..1bee96e6fcd1 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1456,7 +1456,14 @@ describe('moduleFileExtensions', () => { it('defaults to something useful', () => { const {options} = normalize({rootDir: '/root'}, {}); - expect(options.moduleFileExtensions).toEqual(['js', 'json', 'jsx', 'node']); + expect(options.moduleFileExtensions).toEqual([ + 'js', + 'json', + 'jsx', + 'ts', + 'tsx', + 'node', + ]); }); it('throws if missing `js`', () => { diff --git a/packages/jest-config/src/constants.js b/packages/jest-config/src/constants.js index 1de63fe6bbbc..a7f20a8d0ca5 100644 --- a/packages/jest-config/src/constants.js +++ b/packages/jest-config/src/constants.js @@ -10,7 +10,7 @@ import path from 'path'; export const NODE_MODULES = path.sep + 'node_modules' + path.sep; -export const DEFAULT_JS_PATTERN = '^.+\\.jsx?$'; +export const DEFAULT_JS_PATTERN = '^.+\\.[jt]sx?$'; export const DEFAULT_REPORTER_LABEL = 'default'; export const PACKAGE_JSON = 'package.json'; export const JEST_CONFIG = 'jest.config.js'; diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 7a16917bcb06..16e31b27bf30 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -137,6 +137,10 @@ const setupBabelJest = (options: InitialOptions) => { const regex = new RegExp(pattern); return regex.test('a.js') || regex.test('a.jsx'); }); + const customTSPattern = Object.keys(transform).find(pattern => { + const regex = new RegExp(pattern); + return regex.test('a.ts') || regex.test('a.tsx'); + }); if (customJSPattern) { const customJSTransformer = transform[customJSPattern]; @@ -148,6 +152,17 @@ const setupBabelJest = (options: InitialOptions) => { babelJest = customJSTransformer; } } + + if (customTSPattern) { + const customTSTransformer = transform[customTSPattern]; + + if (customTSTransformer === 'babel-jest') { + babelJest = require.resolve('babel-jest'); + transform[customTSPattern] = babelJest; + } else if (customTSTransformer.includes('babel-jest')) { + babelJest = customTSTransformer; + } + } } else { babelJest = require.resolve('babel-jest'); options.transform = { diff --git a/packages/jest-runtime/src/__tests__/__snapshots__/runtime_require_module_no_ext.test.js.snap b/packages/jest-runtime/src/__tests__/__snapshots__/runtime_require_module_no_ext.test.js.snap index 5ca57a5456cb..d9a3386a84ea 100644 --- a/packages/jest-runtime/src/__tests__/__snapshots__/runtime_require_module_no_ext.test.js.snap +++ b/packages/jest-runtime/src/__tests__/__snapshots__/runtime_require_module_no_ext.test.js.snap @@ -6,7 +6,7 @@ exports[`Runtime requireModule with no extension throws error pointing out file However, Jest was able to find: './RegularModuleWithWrongExt.txt' -You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'node']. +You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node']. See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string" `; diff --git a/packages/jest-validate/src/__tests__/fixtures/jestConfig.js b/packages/jest-validate/src/__tests__/fixtures/jestConfig.js index fd98e6aa40e5..369509d77048 100644 --- a/packages/jest-validate/src/__tests__/fixtures/jestConfig.js +++ b/packages/jest-validate/src/__tests__/fixtures/jestConfig.js @@ -49,7 +49,7 @@ const defaultConfig = { snapshotSerializers: [], testEnvironment: 'jest-environment-jsdom', testPathIgnorePatterns: [NODE_MODULES_REGEXP], - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', testResultsProcessor: null, testURL: 'http://localhost', timers: 'real', @@ -113,7 +113,7 @@ const validConfig = { testEnvironment: 'jest-environment-jsdom', testNamePattern: 'test signature', testPathIgnorePatterns: [NODE_MODULES_REGEXP], - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$', + testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', testResultsProcessor: 'processor-node-module', testRunner: 'jasmine2', testURL: 'http://localhost', diff --git a/website/pages/en/index.js b/website/pages/en/index.js index f66efc3201f7..720aa9ab6c22 100755 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -389,9 +389,9 @@ class Index extends React.Component { content: ( Jest works with any compile-to-JavaScript language and - integrates seamlessly with [Babel](https://babeljs.io) and - with TypeScript through - [ts-jest](https://github.com/kulshekhar/ts-jest). + integrates seamlessly with [Babel](https://babeljs.io) + which means you can write React, TypeScript and much more + without configuration ), image: '/img/content/feature-typescript.png', From 1ad0a9a8ce944b18fcf2ef05c5e89168c5223ac4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 18 Dec 2018 22:45:38 +0100 Subject: [PATCH 2/3] link to PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d235e735f6e7..ece3e6dbfd5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ - `[jest-haste-map]` [**BREAKING**] Remove name from hash in `HasteMap.getCacheFilePath` ([#7218](https://github.com/facebook/jest/pull/7218)) - `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203)) - `[jest-haste-map]` [**BREAKING**] Expose relative paths when getting the file iterator ([#7321](https://github.com/facebook/jest/pull/7321)) -- `[jest-config]` Handle typescript (`ts` and `tsx`) by default +- `[jest-config]` Handle typescript (`ts` and `tsx`) by default ([#7533](https://github.com/facebook/jest/pull/7533)) - `[jest-validate]` Add support for comments in `package.json` using a `"//"` key ([#7295](https://github.com/facebook/jest/pull/7295)) - `[jest-config]` Add shorthand for watch plugins and runners ([#7213](https://github.com/facebook/jest/pull/7213)) - `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996)) From ba2328c3693e5c1e1b39d1f4e5cffafe1820f08e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 19 Dec 2018 14:01:08 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-Authored-By: SimenB --- README.md | 2 +- docs/GettingStarted.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70bdce93b131..0db7f6dec4e7 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Jest can be used in projects that use [webpack](https://webpack.js.org/) to mana ### Using TypeScript -To use TypeScript in your tests you install `@babel/preset-typescript` and add it to your Babel config. +To use TypeScript in your tests install `@babel/preset-typescript` and add it to your Babel config. diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index b2a0c1feaa9d..7195b589b527 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -125,6 +125,6 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m ### Using TypeScript -Jest support TypeScript out of the box, via Babel. +Jest supports TypeScript out of the box, via Babel. However, there are some caveats to using Typescript with Babel, see http://artsy.github.io/blog/2017/11/27/Babel-7-and-TypeScript/. Another caveat is that Jest will not typecheck your tests. If you want that, you can use [ts-jest](https://github.com/kulshekhar/ts-jest).