-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: Ensuring spec file presence prior to webpack-dev-server compilation #21550
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
Changes from 2 commits
18b18a7
fc336dd
4f8258c
0c1d3d9
b265ee9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,16 @@ export class CypressCTWebpackPlugin { | |
} | ||
}; | ||
|
||
private beforeCompile = () => { | ||
if (!this.compilation) { | ||
return | ||
} | ||
|
||
// Ensure we don't try to load files that have been removed from the file system | ||
// but have not yet been detected by the onSpecsChange handler | ||
this.files = (this.files || []).filter((file) => fs.existsSync(file.absolute)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://webpack.js.org/api/compiler-hooks/#beforecompile can work with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or - is the point we must do this async, so we avoid the race condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just need this to execute prior to the compile phase, which should happen regardless of whether we're sync/async here. Given that we're not actively manipulating the compile params here, we might as well use async and get whatever benefit that might have. Your example branch was helpful, thank you. I thought about going with a Promise.all rather than running them in series. Something like: const foundFiles = await Promise.all(this.files.map(async (file) => {
try {
const exists = await fs.pathExists(file.absolute)
return exists ? file : null
} catch (e) {
return null
}
}))
this.files = foundFiles.filter((file) => file !== null) Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine 💯 |
||
} | ||
|
||
/* | ||
* After compiling, we check for errors and inform the server of them. | ||
*/ | ||
|
@@ -96,7 +106,7 @@ export class CypressCTWebpackPlugin { | |
} | ||
} | ||
|
||
// After emitting assets, we tell the server complitation was successful | ||
// After emitting assets, we tell the server compilation was successful | ||
// so it can trigger a reload the AUT iframe. | ||
private afterEmit = () => { | ||
if (!this.compilation?.getStats().hasErrors()) { | ||
|
@@ -152,6 +162,7 @@ export class CypressCTWebpackPlugin { | |
const _compiler = compiler as Compiler | ||
|
||
this.devServerEvents.on('dev-server:specs:changed', this.onSpecsChange) | ||
_compiler.hooks.beforeCompile.tap('CypressCTPlugin', this.beforeCompile) | ||
_compiler.hooks.afterCompile.tap('CypressCTPlugin', this.afterCompile) | ||
_compiler.hooks.afterEmit.tap('CypressCTPlugin', this.afterEmit) | ||
_compiler.hooks.compilation.tap('CypressCTPlugin', (compilation) => this.addCompilationHooks(compilation as Webpack45Compilation)) | ||
|
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 test, the cy-in-cy tests for the dev-servers are so darn cool.
Uh oh!
There was an error while loading. Please reload this page.
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.
They are quite cool, but I wonder if a regression test would be best added in the actual
npm/webpack-dev-server
@tbiethman? This test is quite far away from the actual code it is related to. Not sure how practical it is to add unit/integration test inside of webpack-dev-server, though.