fix: Failed site creation resets the directory - #68
Conversation
There was a problem hiding this comment.
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.
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.
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.
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
sejas
left a comment
There was a problem hiding this comment.
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.
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