nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Bug: Jest tests fail when using globalSetup option #2393

Closed iamkhalidbashir closed 2 years ago

iamkhalidbashir commented 2 years ago

Is there an existing issue for this?

Current behavior

Jest e2e tests fail when using globalSetup option I suspect the issue has something to do with circular dependency between Dto files (as shown in the attached Minimum reproduction code)

@kamilmysliwiec Before you close this issue without any reason, please note that I have already posted this issue on discord with no luck, and it has been a month on discord and no one has been able to solve it. It is definitely a bug within the source code in this lib, please have a look Screenshot from 2022-09-09 16-39-17

Minimum reproduction code

https://github.com/iamkhalidbashir/nestjs-graphql-jest-error

Steps to reproduce

To reproduce failing tests:-

  1. npm run ci
  2. npm run build
  3. npm run test:e2e

To check why the tests fail

  1. Comment line
  2. npm run test:e2e <--- The tests will pass

Expected behavior

Should pass regardless of using globalSetup in jest options or not

Package version

10.1.1

Graphql version

graphql: 16.6.0 apollo-server-express: 3.10.2 apollo-server-fastify: null

NestJS version

10.1.1

Node.js version

v14.20.0

In which operating systems have you tested?

Other

Logs from the minimum reproduction code (https://github.com/iamkhalidbashir/nestjs-graphql-jest-error)

> jest --config ./test/jest-e2e.json

Determining test suites to run...[class AppResolver]
 FAIL  test/app.e2e-spec.ts
  AppController (e2e)
    ✕ getMembers
    ✕ getGroups

  ● AppController (e2e) › getMembers

    Cannot determine a GraphQL output type for the "name". Make sure your class is decorated with an appropriate decorator.

      at OutputTypeFactory.create (../node_modules/@nestjs/graphql/dist/schema-builder/factories/output-type.factory.js:19:23)
          at Array.forEach (<anonymous>)

  ● AppController (e2e) › getGroups

    Cannot determine a GraphQL output type for the "name". Make sure your class is decorated with an appropriate decorator.

      at OutputTypeFactory.create (../node_modules/@nestjs/graphql/dist/schema-builder/factories/output-type.factory.js:19:23)
          at Array.forEach (<anonymous>)

Test Suites: 1 failed, 1 total
Tests:       2 failed, 2 total
Snapshots:   0 total
Time:        0.838 s, estimated 1 s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nest-typescript-starter@1.0.0 test:e2e: `jest --config ./test/jest-e2e.json`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nest-typescript-starter@1.0.0 test:e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bashir/.npm/_logs/2022-09-08T14_12_22_004Z-debug.log
kamilmysliwiec commented 2 years ago

When I close an issue, saying for checking out our Discord channel, or StackOverflow, that means this isn't a bug and yes, I'm sure about this. Please, respect that.

We are using GitHub to track bugs, feature requests, and potential improvements.