Skip to content

Commit 3d048a7

Browse files
Merge branch 'Larinel-master'
2 parents 2573e26 + b4438af commit 3d048a7

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

content/graphql/cli-plugin.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,47 @@ getCustomTransformers: (program: any) => ({
144144
before: [require('@nestjs/graphql/plugin').before({}, program)]
145145
}),
146146
```
147+
148+
#### Integration with `ts-jest` (e2e tests)
149+
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:
159+
160+
```javascript
161+
const transformer = require('@nestjs/graphql/plugin');
162+
163+
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
165+
module.exports.version = 1;
166+
167+
module.exports.factory = (cs) => {
168+
return transformer.before(
169+
{
170+
// @nestjs/graphql/plugin options (can be empty)
171+
},
172+
cs.tsCompiler.program,
173+
);
174+
};
175+
```
176+
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+
}
189+
}
190+
```

content/openapi/cli-plugin.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,41 @@ getCustomTransformers: (program: any) => ({
159159
before: [require('@nestjs/swagger/plugin').before({}, program)]
160160
}),
161161
```
162+
163+
#### Integration with `ts-jest` (e2e tests)
164+
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:
168+
169+
```javascript
170+
const transformer = require('@nestjs/swagger/plugin');
171+
172+
module.exports.name = 'nestjs-swagger-transformer';
173+
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
174+
module.exports.version = 1;
175+
176+
module.exports.factory = (cs) => {
177+
return transformer.before(
178+
{
179+
// @nestjs/swagger/plugin options (can be empty)
180+
},
181+
cs.tsCompiler.program,
182+
);
183+
};
184+
```
185+
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+
}
198+
}
199+
```

0 commit comments

Comments
 (0)