Skip to content

Commit fe8f94e

Browse files
Merge branch 'master' of https://github.com/nestjs/docs.nestjs.com; branch 'master' of https://github.com/Larinel/docs.nestjs.com into Larinel-master
2 parents 2573e26 + f566e94 commit fe8f94e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

content/graphql/cli-plugin.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,41 @@ getCustomTransformers: (program: any) => ({
144144
before: [require('@nestjs/graphql/plugin').before({}, program)]
145145
}),
146146
```
147+
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.`
151+
152+
This happens because jest configuration does not import `@nestjs/graphql/plugin` plugin anywhere.
153+
154+
To fix this, create the following file anywhere:
155+
```javascript
156+
const transformer = require('@nestjs/graphql/plugin');
157+
158+
module.exports.name = 'nestjs-graphql-transformer';
159+
module.exports.version = 1;
160+
161+
module.exports.factory = cs => {
162+
return transformer.before(
163+
{
164+
// your @nestjs/graphql/plugin options(can be empty)
165+
},
166+
cs.tsCompiler.program,
167+
);
168+
};
169+
```
170+
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+
...
183+
}
184+
```

content/openapi/cli-plugin.md

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

0 commit comments

Comments
 (0)