-
Notifications
You must be signed in to change notification settings - Fork 50
fix: Failed site creation resets the directory #68
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.
Like other new files in src/__mocks__, these mocks were hoisted here to simplify sharing these foundational module mocks across various test files.
| fs.__setFileContents = ( path: string, fileContents: string | string[] ) => { | ||
| mockFiles[ path ] = fileContents; | ||
| }; |
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.
Sourced from the Jest documentation, implemented to allow simultaneously mocking file contents from different locations.
| /** | ||
| * @jest-environment node | ||
| */ |
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.
Using the node testing environment should provide a more realistic environment for main process tests. Also, the tests should run faster.
| import fs from 'fs'; | ||
| import { loadUserData } from '../user-data'; | ||
|
|
||
| jest.mock( 'fs' ); |
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.
If we want to mock Node's built-in modules (e.g.:
fsorpath), then explicitly calling e.g.jest.mock('path')is required, because built-in modules are not mocked by default.
Simplify mocking foundational modules by placing them in a shared location.
Simplify mocking foundational modules by placing them in a shared location.
Simplify mocking foundational modules by placing them in a shared location.
Simplify retrying site creation by removing all files generated during the process.
The Node.js environment is more applicable than the default `jsdom` environment. This should make tests more realistic and faster.
e5df727 to
5266363
Compare
kozer
left a comment
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 tested it and worked as expected:
Also note, that I run all tests to verify that everything work as expected

Nice work @dcalhoun !
sejas
left a comment
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.
Awesome!, The change looks great! 👍
Now users can re-try after a new site creation fails.
Thank you!
| try { | ||
| await createSiteWorkingDirectory( path ); | ||
| } catch ( error ) { | ||
| // If site creation failed, remove the generated files and re-throw the | ||
| // error so it can be handled by the caller. | ||
| shell.trashItem( path ); | ||
| throw error; | ||
| } |
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.
Nice!, thanks for introducing the logic!


Related to #4 (comment).
Proposed Changes
fsmocks to support reading different files.and faster runs.
Testing Instructions
In addition to the following, exploratory/regression testing around site creation is welcome.
Failed site creation resets the directory
npm startStudiodirectory.Intentional error diff
Pre-merge Checklist