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

chore(docs): update tutorial testing chapter #709

Merged
merged 3 commits into from
Dec 8, 2020

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 prevented Jest from exiting. This issue was fixed in a9ca189 using a workaround by passing the --forceExit flag to Jest.

This PR adds a proper fix for #678

@shreyas44 shreyas44 changed the title Update the testing part of the tutorial docs: Update the testing part of the tutorial Dec 7, 2020
@codecov
Copy link

codecov bot commented Dec 7, 2020

Codecov Report

Merging #709 (54d3770) into develop (a9ca189) will decrease coverage by 0.00%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop     #709      +/-   ##
===========================================
- Coverage    93.62%   93.62%   -0.01%     
===========================================
  Files           44       46       +2     
  Lines         2887     2900      +13     
  Branches       678      679       +1     
===========================================
+ Hits          2703     2715      +12     
- Misses         182      183       +1     
  Partials         2        2              


export interface Context {
db: PrismaClient
}

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

Choose a reason for hiding this comment

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

Can you update this to match https://github.com/graphql-nexus/tutorial/blob/master/api/context.ts

I don't think we need a db modular just to instantiate a Prisma client :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need db to modular, but we do need to store the instance of the Prisma Client in either an object or variable which is exported so that it can be accessed in tests/__helpers.ts. The same Prisma Client used in the context of Nexus should be accessible in __helpers.ts as a new connection is created for every instance of Prisma Client.

There are two options, one is keep it as I've updated it.

Another is, to export an object from 'context.ts' and disconnect the connection of that

export const context: Context = {
  db: new PrismaClient()
}

and in __helpers.ts

import { context } from '../api/context.ts'

... 

function graphqlTestContext() {
  ...
  
  return {
    async before() {
      ...
      serverInstance.server.on('close', async () => {
        await context.db.$disconnect()
      })
    },
    ...
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep good point. then a singleton db module is a simple solution indeed. If you're inclined update the tutorial repo otherwise we'll try to do it soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already done graphql-nexus/tutorial#13 🙂 !

@jasonkuhrt
Copy link
Contributor

Awesome! Just one thing

@jasonkuhrt jasonkuhrt changed the title docs: Update the testing part of the tutorial chore(docs): update tutorial testing chapter Dec 8, 2020
@jasonkuhrt jasonkuhrt merged commit c2a3ef9 into graphql-nexus:develop Dec 8, 2020
danielrearden pushed a commit to danielrearden/schema that referenced this pull request Dec 8, 2020
danielrearden pushed a commit to danielrearden/schema that referenced this pull request Dec 8, 2020
danielrearden pushed a commit to danielrearden/schema that referenced this pull request 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