Skip to content

Commit b4438af

Browse files
content(): some tweaks to ts-jest integration (plugins)
1 parent fe8f94e commit b4438af

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

content/graphql/cli-plugin.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,40 +145,46 @@ getCustomTransformers: (program: any) => ({
145145
}),
146146
```
147147

148-
#### Usage with `ts-jest`
149-
When using e2e tests with this plugin you probably will run into issue with compiling schema
150-
like `Object type <name> must define one or more fields.`
148+
#### Integration with `ts-jest` (e2e tests)
151149

152-
This happens because jest configuration does not import `@nestjs/graphql/plugin` plugin anywhere.
150+
When running e2e tests with this plugin enabled, you may run into issues with compiling schema. For example, one of the most common errors is:
151+
152+
```json
153+
Object type <name> must define one or more fields.
154+
```
155+
156+
This happens because `jest` configuration does not import `@nestjs/graphql/plugin` plugin anywhere.
157+
158+
To fix this, create the following file in your e2e tests directory:
153159

154-
To fix this, create the following file anywhere:
155160
```javascript
156161
const transformer = require('@nestjs/graphql/plugin');
157162

158163
module.exports.name = 'nestjs-graphql-transformer';
164+
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
159165
module.exports.version = 1;
160166

161-
module.exports.factory = cs => {
167+
module.exports.factory = (cs) => {
162168
return transformer.before(
163169
{
164-
// your @nestjs/graphql/plugin options(can be empty)
170+
// @nestjs/graphql/plugin options (can be empty)
165171
},
166172
cs.tsCompiler.program,
167173
);
168174
};
169175
```
170176

171-
Then import it within yours `jest.config.js`
172-
```javascript
173-
module.exports = {
174-
...
175-
globals: {
176-
'ts-jest': {
177-
astTransformers: {
178-
before: ['<path to plugin>'],
179-
},
180-
},
181-
},
182-
...
177+
With this in place, import AST transformer within your `jest` configuration file. By default (in the starter application), e2e tests configuration file is located under the `test` folder and is named `jest-e2e.json`.
178+
179+
```json
180+
{
181+
... // other configuration
182+
"globals": {
183+
"ts-jest": {
184+
"astTransformers": {
185+
"before": ["<path to the file created above>"],
186+
}
187+
}
188+
}
183189
}
184190
```

content/openapi/cli-plugin.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,39 +160,40 @@ getCustomTransformers: (program: any) => ({
160160
}),
161161
```
162162

163-
#### Usage with `ts-jest` in e2e tests
163+
#### Integration with `ts-jest` (e2e tests)
164164

165-
You need to do the following steps in order to make `jest` e2e tests working with this plugin.
166-
This happens because `jest` configuration does not import `@nestjs/swagger/plugin` plugin anywhere.
165+
To run e2e tests, `ts-jest` compiles your source code files on the fly, in memory. This means, it doesn't use Nest CLI compiler and does not apply any plugins or perform AST transformations.
166+
167+
To enable the plugin, create the following file in your e2e tests directory:
167168

168-
To fix this, create the following file anywhere:
169169
```javascript
170170
const transformer = require('@nestjs/swagger/plugin');
171171

172172
module.exports.name = 'nestjs-swagger-transformer';
173-
module.exports.version = 1; // you should change this anytime you change the configuration below
173+
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
174+
module.exports.version = 1;
174175

175-
module.exports.factory = cs => {
176+
module.exports.factory = (cs) => {
176177
return transformer.before(
177178
{
178-
// your @nestjs/swagger/plugin options(can be empty)
179+
// @nestjs/swagger/plugin options (can be empty)
179180
},
180181
cs.tsCompiler.program,
181182
);
182183
};
183184
```
184185

185-
Then import it within yours `jest.config.js`
186-
```javascript
187-
module.exports = {
188-
...
189-
globals: {
190-
'ts-jest': {
191-
astTransformers: {
192-
before: ['<path to plugin>'],
193-
},
194-
},
195-
},
196-
...
186+
With this in place, import AST transformer within your `jest` configuration file. By default (in the starter application), e2e tests configuration file is located under the `test` folder and is named `jest-e2e.json`.
187+
188+
```json
189+
{
190+
... // other configuration
191+
"globals": {
192+
"ts-jest": {
193+
"astTransformers": {
194+
"before": ["<path to the file created above>"],
195+
}
196+
}
197+
}
197198
}
198199
```

0 commit comments

Comments
 (0)