Skip to content

Commit a64a9f6

Browse files
authored
chore(website): improve docs around jest testing (#1296)
1 parent 612561c commit a64a9f6

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

website/content/010-getting-started/03-tutorial/05-chapter-4-testing-your-api.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Then, configure jest and npm scripts in your `package.json`
4242
},
4343
"jest": {
4444
"preset": "ts-jest",
45+
"globals": {
46+
"ts-jest": {
47+
"diagnostics": { "warnOnly": true }
48+
}
49+
},
4550
"testEnvironment": "node"
4651
}
4752
```

website/content/010-getting-started/03-tutorial/07-chapter-6-testing-with-prisma.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Then, configure Jest to use that custom environment in your `package.json`
8989
```json
9090
"jest": {
9191
"preset": "ts-jest",
92+
"globals": {
93+
"ts-jest": {
94+
"diagnostics": { "warnOnly": true }
95+
}
96+
},
9297
- "testEnvironment": "node",
9398
+ "testEnvironment": "./tests/nexus-test-environment.js"
9499
}

website/content/020-guides/05-testing.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ Nexus comes with a special testing module that you can import from `nexus/testin
2525
>
2626
> Since `jest` runs test suites in parallel it means multiple instances of your `app` will be run in parallel too. The testing module takes care of abstracting the mechanics of making this work from you. For example it assigns random ports to each app to run its server and makes sure each test suite's app client is configured to be talking with its respective app instance. You should _never_ have to think about these kinds of details though, and if it turns out you do please open a GitHub issue so we can try to seal the leak you've found in Nexus' abstraction!
2727
28+
### Installing & configuring jest
29+
30+
Install `jest` and `ts-jest`
31+
32+
```
33+
npm install --save-dev jest ts-jest
34+
```
35+
36+
Then configure `jest` to use `ts-jest`. Note: it's important that you set `warnOnly` option to true or Jest will prevent your tests from running in case of type errors.
37+
38+
```js
39+
// jest.config.js
40+
module.exports = {
41+
preset: 'ts-jest',
42+
globals: {
43+
'ts-jest': {
44+
diagnostics: { warnOnly: true }
45+
}
46+
}
47+
}
48+
```
49+
50+
2851
### A little helper
2952

3053
Before jumping into test suites we will wrap the `createTestContext` with a pattern that more tightly integrates it into `jest`. Nexus will probably ship something like as follows or better in the future, but for now you can copy this into your projects:
@@ -174,6 +197,11 @@ Integration between Nexus' test and database systems is young and still missing
174197

175198
module.exports = {
176199
preset: 'ts-jest',
200+
globals: {
201+
'ts-jest': {
202+
diagnostics: { warnOnly: true }
203+
}
204+
},
177205
rootDir: 'tests',
178206
+ testEnvironment: join(__dirname, 'nexus-test-environment.js'),
179207
}

0 commit comments

Comments
 (0)