mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2025-11-09 08:08:16 +00:00
Merge pull request #58 from alan-agius4/feature/jest-conf
feat: move jest config to external file
This commit is contained in:
39
README.md
39
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`.
|
||||
|
||||
18
jest.config.js
Normal file
18
jest.config.js
Normal file
@@ -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'
|
||||
};
|
||||
18
package.json
18
package.json
@@ -22,24 +22,6 @@
|
||||
"tslint": "tslint -c tslint.json -p tsconfig.json",
|
||||
"copy-static-assets": "node copyStaticAssets.js"
|
||||
},
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user