-
Notifications
You must be signed in to change notification settings - Fork 14
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
test setup #74 #75
test setup #74 #75
Conversation
resolves #74 |
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.
Some general things:
- I don't like all the mocking, but I am unsure how to avoid it at this point
- I would prefer component/route tests to be collocated
Co-authored-by: Braydon Hall <[email protected]>
estEnviroment node cause the snowpack build to fail
Thanks for working on this - you are doing some great work 🎊 |
Thanks 🙂 |
package.json
Outdated
"test": "jest --watch --FIRESTORE_EMULATOR_HOST=8080", | ||
"test:ci": "jest", | ||
"test": "jest --watch", | ||
"test:ci": "jest --findRelatedTests", |
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.
--findRelatedTests
forces jest from running cypress's tests (lint-stage for some reason forces jest to run cypresses tests)🙂
So just some reminders for myself, and to mention a few things:
This can be fixed by making the test command use You can see how I got this working in Guild Scrivener:
Looks like the tests are still hanging out under the |
f31837b
to
45b13a3
Compare
But isn't the way you started the
|
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.
@AhmedEldessouki I'll answer some of your questions below 😄
why doesn't it work if you ran it like this
run-s exec:firestore test
If you meant Sorry, this would NOT work. start:firestore
- yes, that would work. But why should I bother about adding in another dependency, when the firebase emulator supports the usecase we have out of the box?run-s
runs things sequentially, and the firestore emulator just runs until stopped - so it would never run the test script.
🤯🤯 no idea whats going on except for most of faker usage
Ask any questions in Discord, and I'll do my best to explain!
are you thinking components/tests or components/{whatever}/tests ? thinking
Neither, actually. That's what I was originally thinking. Now I believe doing something like components/loadingScreen/loadingScreen.test.ts
<-- this will place it right next to the file it is testing.
"start:dev": "snowpack dev", | ||
"start:firestore": "firebase emulators:start --import=./devData --only firestore", | ||
"build": "snowpack build", | ||
"test": "jest --watch", | ||
"test": "jest --watch --FIRESTORE_EMULATOR_HOST=8080", |
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.
when i started testing my app (which is also) using firebase. I used to get my API like this [...API_KEY]. so how did dotenv.config(); fix it? ... i used to think that Kent did something so people like me wouldn't do the mistake of testing using the same backend the app uses.
Dotenv just imported whatever I had in my .env
file, as without those, it would fall over. This also meant that I don't have to worry about var being added or removed. It becomes extremely(!!!!) important to make sure you aren't "leaking" anything out to the real world, however. In Scrivener, I am managing this by using MSW with a catchall:
rest.get('*', (req, res, ctx) => {
const warning = `${req.url} has not been mocked yet... Maybe now is a good time to do that`;
console.warn(warning);
return res(ctx.json(warning));
}),
And then firestore has this really nice feature of the FIRESTORE_EMULATOR_HOST
env var, which will make it point to the emulator instead of real firebase.
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.
Sorry, this would NOT work. run-s runs things sequentially, and the firestore emulator just runs until stopped - so it would never run the test script.
I thought it will run firestore emulator then jest. but even run-p didn't work even thu it worked with start
command.
components/loadingScreen/loadingScreen.test.ts <-- this will place it right next to the file it is testing.
this will surely be a lot cleaner. I will do the changes.
@JacobMGEvans is it okay to do so?
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 see now. that cleared alot of things for me. 🙏🏼 thanks 🙂
using the emulator is way better than using MSW to fake the requests. because firebase url
are pretty damn big.
"test": "jest --watch --FIRESTORE_EMULATOR_HOST=8080", | |
"test": "jest --watch", |
I dont think that the FIRESTORE_EMULATOR_HOST
var works here in this line. when i added it, it was for the test env to pick up on it but the way you wrote the script and configured the env var bypassed its use case.
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.
@AhmedEldessouki the way you set it here doesn't set an env var. You will have to use something like cross-env and set it first - see Guild Scrivener for how I setup a generic "execute firestore" command that everything else hooks off of for a solid example.
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.
thanks for pointing that out 🙂 I will look for it 😁😁
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.
Cant work around this. int the Guild Scrivener you are using Node env. do you think it's possible for @firebase/testing
to work in Jsdom env?
Error: FIRESTORE (8.2.4) INTERNAL ASSERTION FAILED: Unexpected state
I ran into this problem before when i was testing firestore-rules (Node env). after i worked around it, jsdom tests was being unexpected and then i removed firestore-rules test
jest.doMock('../utils/useDocument', () => | ||
jest.fn().mockReturnValue(fetchedDocumentData), | ||
) | ||
jest.doMock('../utils/useCollection', () => | ||
jest.fn().mockReturnValue(fetchedCollectionData), | ||
) | ||
jest.spyOn(console, 'log') |
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.
When we use the emulators, we don't have to mock anything because we are just interfacing with the emulator instead of the real thing - yes you still have to "seed" the data.
This can be done by just importing from the devData
dir for now, as the website is really read-only.
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.
When we use the emulators, we don't have to mock anything
totally agree. i tried it before mocking but when it failed i when with mocking. i will do remove the mocks.
// console.log({ | ||
// name: name.value, | ||
// raidName: raidName.value, | ||
// rate: rate.value, | ||
// description: description.value, | ||
// }) |
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.
Clean up later
) | ||
} | ||
|
||
export * from '@testing-library/react' |
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.
Why is this being exported?
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 believe it is so there is a single import { xyz } from '../path/to/testUtils'
instead of importing things from '@testing-library/react' itself AND 'testUtils'.
Replaced By #83 |
No description provided.