-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: ensure unique sandbox directories for boot tests #5747
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.
| const appJsFile = resolve(__dirname, '../fixtures/application.js'); | ||
| let appJs = fs.readFileSync(appJsFile, 'utf-8'); | ||
| // Adjust the relative path for `import` | ||
| appJs = appJs.replace('../..', '../../..'); |
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.
Can we extract this logic into sandbox.copyFile please? IIRC, copyFile is already detecting JS files and updating sourcemap URL to accommodate the new location, it would be great if we could do the same for import paths.
If it's too work to detect which paths to update, then perhaps copyFile can accept a new options to specify the mapping? Example usage:
await sandbox.copyFile(
resolve(__dirname, '../fixtures/application.js'),
'dist/application.js',
{
transform: text => text.replace('../..', '../../..'),
},
});WDYT?
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.
Maybe we should defer it. The current copyFile does not read the source file and we don't even know if the source is a text or binary file.
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.
For context, here is the current copyFile implementation, you are right that we are not reading the source file.
I have two concerns about your current version:
(1)
The code is a bit involved and at different level of abstraction when compared the surrounding lines.
I'd like to read getApp as a sequence of instructions for copying files, I don't want to be distracted with implementation details of transforming source file content into target.
await sandbox.copyFile(resolve(__dirname, '../fixtures/application.js'), {
// Adjust the relative path for `import`
transform: text => text.replace('../..', '../../..'),
});
await sandbox.copyFile(resolve(__dirname, '../fixtures/package.json'));(2)
The code modifying application.js is duplicated in two test suites. These two places can easily get out of sync and it's likely additional copies will be introduced in the future as more test files are added.
Can you at least extract the code dealing with application.js into a shared test helper please, to avoid duplication?
packages/boot/src/__tests__/acceptance/crud-rest.api-builder.acceptance.ts
Show resolved
Hide resolved
bajtos
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 am not entirely happy with the proposed version, but I guess we can improve it later.
| const appJsFile = resolve(__dirname, '../fixtures/application.js'); | ||
| let appJs = fs.readFileSync(appJsFile, 'utf-8'); | ||
| // Adjust the relative path for `import` | ||
| appJs = appJs.replace('../..', '../../..'); |
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.
For context, here is the current copyFile implementation, you are right that we are not reading the source file.
I have two concerns about your current version:
(1)
The code is a bit involved and at different level of abstraction when compared the surrounding lines.
I'd like to read getApp as a sequence of instructions for copying files, I don't want to be distracted with implementation details of transforming source file content into target.
await sandbox.copyFile(resolve(__dirname, '../fixtures/application.js'), {
// Adjust the relative path for `import`
transform: text => text.replace('../..', '../../..'),
});
await sandbox.copyFile(resolve(__dirname, '../fixtures/package.json'));(2)
The code modifying application.js is duplicated in two test suites. These two places can easily get out of sync and it's likely additional copies will be introduced in the future as more test files are added.
Can you at least extract the code dealing with application.js into a shared test helper please, to avoid duplication?
| } catch (err) { | ||
| console.log(`Stopping the app threw an error: ${err}`); | ||
| } | ||
| await app?.stop(); |
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.
Should we check the state first, for consistency with other stopApp implementations?
| await app?.stop(); | |
| if (app?.state === 'started') await app?.stop(); |
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.
In this case, app.start() is called.
|
@raymondfeng FYI, it looks like these improvements are not enough to fix all booter tests when executed in parallel. Can you please rebase your patch on top of the latest Here are the test failures I am seeing: https://gist.github.com/bajtos/c2f45df9c41384c710d3712186910661 |
| const appJsFile = resolve(__dirname, '../fixtures/application.js'); | ||
| let appJs = fs.readFileSync(appJsFile, 'utf-8'); | ||
| // Adjust the relative path for `import` | ||
| appJs = appJs.replace('../..', '../../..'); |
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.
IIUC, we are trying to fix the following line:
An idea to consider: instead of changing the import/require path in the application file copied to sandbox, can we put a short index.js file into the directory where ../.. points to, to make require('../..') work again?
// index.js
module.exports = require('../');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 prefer to use transform to make it clear - having a magic index.js makes it difficult to understand.
1bc25f5 to
6ad5c9e
Compare
|
@bajtos I added |
I cannot reproduce the issue. With this PR, |
Extracted from #5744 for ease of review.
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈