Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jest exits after tests run #13

Merged

Conversation

shreyas44
Copy link
Contributor

  • Use the Prisma Client created in db.ts in the API Context
  • Disconnect Prisma Client after running each test, allowing Jest to exit. Previously this was an issue as the Prisma Client connection was never closed and prevent Jest from exiting. This issue was fixed yesterday in a9ca189
    using a workaround by passing the --forceExit flag to Jest.

This PR adds a proper fix for graphql-nexus/nexus#678.


export interface Context {
db: PrismaClient
}

export function createContext(): Context {
return {
db: new PrismaClient(),
db,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're passing a function as the context instead of just passing a regular Object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a function is what Apollo Server expects. It is called on every request. Usually work is done here to expose request scoped details to resolvers, like current user.

This needs to be explained better in the tutorial.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually work is done here to expose request scoped details to resolvers, like current user.

Yup, I've actually done that in an app I'm building.

Because a function is what Apollo Server expects.

Apollo Server actually expects either a function or a plain javascript object. It's not really a big deal, but I thought it might've been simpler just passing a context object in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, in the spirit of the tutorial that incrementally builds up on an as-needed basis I would happily accept a PR to make this change!

Copy link
Contributor Author

@shreyas44 shreyas44 Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

@jasonkuhrt jasonkuhrt changed the title Fix jest not closing issue fix: jest exits after tests run Dec 8, 2020
@jasonkuhrt jasonkuhrt merged commit 3aa9a39 into graphql-nexus:master Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants