diff --git a/README.md b/README.md index 09c4c0b9..f2c88923 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ The full folder structure of this app is explained below: | .env.example | API keys, tokens, passwords, database URI. Clone this, but don't check it in to public repos. | | .travis.yml | Used to configure Travis CI build | | .copyStaticAssets.js | Build script that copies images, fonts, and JS libs to the dist folder | +| jest.config.js | Used to configure Jest | | package.json | File that contains npm dependencies as well as [build scripts](#what-if-a-library-isnt-on-definitelytyped) | | tsconfig.json | Config settings for compiling server code written in TypeScript | | tsconfig.tests.json | Config settings for compiling tests written in TypeScript | @@ -317,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`. diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..6ea5c4a8 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,18 @@ +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' +}; \ No newline at end of file diff --git a/package.json b/package.json index 2fb4c758..b5d57f52 100644 --- a/package.json +++ b/package.json @@ -24,24 +24,6 @@ "serve-debug": "nodemon --inspect dist/server.js", "watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\"" }, - "jest": { - "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" - }, "dependencies": { "async": "^2.5.0", "bcrypt-nodejs": "^0.0.3",