-
Notifications
You must be signed in to change notification settings - Fork 88
Use test fixtures #34
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
Conversation
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.
whoa this is clever, very awesome !!!!!!!
thought: i was originally using appendFile to create the next config if it doesn't exist in the project so in this test 'create next.config.js with correct target if file does not exist'
i first tried using mock-fs or trying to mock appendFile and it was such a pain that i switched to make-file. would this fixture approach work for mocking appendFile and if so, how?
Good point! |
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.
this is so awesome, i def have a lot more to learn and a lot more experience to gain with node 🙏 thank you for doing this!!!!!!!
utils.build.failBuild.mockReset() | ||
utils.run.command.mockReset() | ||
jest.clearAllMocks() | ||
jest.resetAllMocks() | ||
|
||
this.restoreCwd() | ||
await this.cleanup() |
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.
what does cleanup do and why is it async?
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.
Added some code comment 👍
b1a9e64
to
b31cf24
Compare
Quick run-through of the setup:
Then, some tests might need to use a specific fixture directory instead of an empty temporary directory. To do this:
|
* chore: big reorg * chore: simplify content handling * chore: add comments * feat: another refactor * fix: content filtering logic * chore: promise all style * chore: update eslint override path * chore: update readme * fix: update missed server content paths * chore: update FetchCacheValue type * chore: make content type logic more explicit
I am hitting two issues with
mock-fs
: here and there.When I try to add more tests, I get:
Apparently, the issue is the following: after filesystem has been mocked,
jest
lazily try torequire('chalk')
by usingfs
instead. But because mocking is in place, this crashes.This new lazy loading behavior was added to
mock-fs@4
. I tried downgrading tomock-fs@3
but an error message shows me it won't run on Node15
.This PR implements an alternative: using a fixtures directory with static files committed to
git
, then doprocess.chdir()
inside tests that need filesystem access.