#Jest globalSetup + GraphQL weird issue

22 messages · Page 1 of 1 (latest)

upbeat wigeon
#

Hello everyone 👋🏻

Note: E2E tests.
When I use globalSetup of Jest with GraphQL I always get this error:

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

or something similar to it.

Note that this error happens AFTER globalSetup finishes, particularly when I call app.init() in the tests.

If I remove globalSetup code works normally.
Ironically if I have globalTeardown only, no errors happen... I'm really confused 😫

Thanks in advance,
Second time posting something here... not a good week 🤦🏻‍♂️

#

I forgot to mention that npm run start:dev works normally too.

#

Oook... I created a minimal reproduceble code dto.

#
import { Field, ObjectType } from '@nestjs/graphql';
import { ResponseDto } from './response.dto';

@ObjectType()
export class ResponsesDto {
  @Field(() => [ResponseDto])
  data: ResponseDto[];
}

#

Happens on nested objects/dtos.

upbeat wigeon
#

This will get you to the bug in less than a minute... it starts the server by itself. close it and run npm run test:e2e.

upbeat wigeon
#

Hello @marble sky, I noticed that a similar issue got closed because it was deemed not a bug. I've been searching for like the last 2 working days on this Discord and on Google. No solution were found. The minimal reprouctiobn code can be easily run from here.

I might be missing something, or searching in the wrong place. Anyway... I'm pretty much lost at this point, any help?

upbeat wigeon
#

As a temporary workaround I just imported only the needed modules in setup.ts.

narrow heath
#

your graphql types are conflicting

#

nestjs also looks at your resolver

#

oh responses then maybe not 😄

#

nullable expects boolean?

upbeat wigeon
# narrow heath nullable expects boolean?

I've tried this with... many different variations 😅

What makes me kind of sure that it's not (?) a graphql problem, is that the app works on development and on testing if I omit setup.ts from jest config.

I eventually got tired of it and decided to import only the needed modules in setup.ts and teadown.ts, which thankfully do not include GraphQLModule.

upbeat wigeon
#

same issue retaliates (:

shut kiln
#

@upbeat wigeon I'm having the same issue while using globalSetup, will post an update if I find something useful..

calm otter
#

@upbeat wigeon @shut kiln Have you found a solution for this? I'm having the same problem. Both with jest and vitest.

upbeat wigeon
#

Hello @shut kiln & @calm otter , sorry for the late reply.

I resorted to creating custom scripts for setup and teardown, something like this:
npm run test:setup && cross-env NODE_ENV=test jest --config ./test/jest-e2e.json --runInBand --detectOpenHandles --forceExit && npm run test:teardown

Later I've ditched Jest for node built-in test runner, I advise you to give a a try. It is MUCH faster, at least from my experience.

#

Also with the new --env-file flag I ditched dotenv too 🙂

npm run test:setup && cross-env NODE_ENV=test node --test --experimental-test-isolation=none --experimental-test-coverage --test-reporter lcov --test-reporter-destination .coverage --test-force-exit \"**/*spec.js\" && npm run test:teardown

#

I'm still using it here though 🙈