From c6d457f136731f825d00fe39abca9d130c8955c3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Sat, 16 Dec 2017 12:52:06 +0100 Subject: [PATCH] docs: update `jest` section --- README.md | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5cb705b..f2c8892 100644 --- a/README.md +++ b/README.md @@ -318,24 +318,26 @@ npm install -D jest ts-jest `jest` is the testing framework itself, and `ts-jest` is just a simple function to make running TypeScript tests a little easier. ### Configure Jest -Jest's configuration lives in `package.json`, so let's open it up and add the following code: -```json -"jest": { - "globals": { - "__TS_CONFIG__": "tsconfig.json" - }, - "moduleFileExtensions": [ - "ts", - "js" - ], - "transform": { - "^.+\\.(ts)$": "./node_modules/ts-jest/preprocessor.js" - }, - "testMatch": [ - "**/test/**/*.test.(ts|js)" - ], - "testEnvironment": "node" - }, +Jest's configuration lives in `jest.config.js`, so let's open it up and add the following code: +```js +module.exports = { + globals: { + 'ts-jest': { + tsConfigFile: 'tsconfig.json' + } + }, + moduleFileExtensions: [ + 'ts', + 'js' + ], + transform: { + '^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js' + }, + testMatch: [ + '**/test/**/*.test.(ts|js)' + ], + testEnvironment: 'node' +}; ``` Basically we are telling Jest that we want it to consume all files that match the pattern `"**/test/**/*.test.(ts|js)"` (all `.test.ts`/`.test.js` files in the `test` folder), but we want to preprocess the `.ts` files first. This preprocess step is very flexible, but in our case, we just want to compile our TypeScript to JavaScript using our `tsconfig.json`.