-
Notifications
You must be signed in to change notification settings - Fork 989
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
[Testing] Configuration for e2e testing in jest #731
Conversation
@@ -2,11 +2,24 @@ require('@testing-library/jest-dom') | |||
require('whatwg-fetch') | |||
|
|||
const { server } = require('@redwoodjs/testing') | |||
const camelCase = require('lodash/camelCase') | |||
const { PrismaClient } = require('@prisma/client') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to import the db.js
from the API side of the app, but Jest won't transpile it because it's outside of the rooDir (I think).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can take a look at this, which steps should I take to reproduce this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Checkout
https://github.com/RobertBroersma/redwood-testing
- Checkout this PR
- Replace in this file the direct
PrismaClient
import with thedb.js
import. - Run
yarn rw test web
in theredwood-testing
repo
Thanks!
const redwoodPaths = getPaths() | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { PrismaClient } = require('@prisma/client') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Jest won't let me import the db from the src of the api side.
I can totally see where you're going with this, but I'm a bit worried that it's too much of an abstraction of the GraphQL Serverless Function, and it might not match a user's expectations... it's super close, but doesn't take into account the context or the current user, and I don't know if it's entirely worth it. |
I've had some time to let it simmer in my head as well, and I think for now we can write it off as "Too soon" or "Too weird" or "Probably easier using Cypress" I might get back to it later because I do like the idea, and I think the context and current user problems are solvable! |
I like it too! It does feel too soon.. like my brain wants to wrap around the idea but it's struggling! |
This PR enables E2E-like testing on the web side like so: https://github.com/RobertBroersma/redwood-testing/blob/master/web/src/pages/BlogPostPage/BlogPostPage.test.js without having to spin up any HTTP servers!
It still allows the user to override calls with MSW.
There are some weird things in this PR that probably have a better way to do it, which is why I opened it as a draft!
For it to work and not destroy your dev database all the time this PR requires #691 to be reach consensus and be merged first.
On a side note I would like to say I've never written my tests in this way before, but I'm quite excited about the possibility! So I'm curious to hear what others think about this method. Might it be redundant to do this if we can just spin up the server and run Cypress?