1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2025-11-08 20:27:37 +00:00

Merge branch 'master' into feat/ts-node

This commit is contained in:
Bowden Kelly
2018-01-03 14:35:22 -08:00
committed by GitHub
7 changed files with 100 additions and 90 deletions

View File

@@ -23,6 +23,7 @@ mongod
```
- Build and run the project
```
npm run build
npm start
```
Navigate to `http://localhost:3000`
@@ -73,6 +74,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.ts | 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 +319,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`.