Skip to content
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

fix(webpack-preprocessor): hanging issues with webpack 5 #15611

Merged
merged 25 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4569eb
Fix hanging issues with webpack 5
lukeapage Mar 22, 2021
5af8b76
test: add test
lmiller1990 Jun 7, 2021
6f3a5fb
test: assert deferreds is empty on compilation failure
lmiller1990 Jun 7, 2021
7753121
test: add some tests around deferred promise resolving
lmiller1990 Jun 7, 2021
1040313
chore: merge in develop and resolve conflicts
lmiller1990 Jun 7, 2021
1f471a7
Merge branch 'develop' into fix-15447
lmiller1990 Jun 8, 2021
ad3f75e
Merge branch 'develop' into fix-15547
lmiller1990 Jun 16, 2021
0688c11
remove un-necessary assertions
lmiller1990 Jun 16, 2021
9434b95
use webpack 5
lmiller1990 Jun 16, 2021
00cf55a
update snapshots
lmiller1990 Jun 16, 2021
ec59cd0
Merge branch 'fix-15447' of https://github.com/lukeapage/cypress into…
lmiller1990 Jun 16, 2021
9e6d46a
add webpack 5 specific check
lmiller1990 Jun 17, 2021
769cac3
wip: package.json
lmiller1990 Jun 21, 2021
6bcd11f
update package.json
lmiller1990 Jun 21, 2021
5befbc9
update test script
lmiller1990 Jun 21, 2021
9bbd9cb
update yarn.lock
lmiller1990 Jun 21, 2021
c4dbc1f
reset modules after test
lmiller1990 Jun 21, 2021
9ec32f6
correctly rewrite file
lmiller1990 Jun 21, 2021
ce47156
stringify correctly
lmiller1990 Jun 21, 2021
bda88b3
Merge branch 'develop' into fix-15447
lmiller1990 Jun 21, 2021
c2a8a8b
add note on script
lmiller1990 Jun 21, 2021
01cf2a9
Merge branch 'fix-15447' of https://github.com/lukeapage/cypress into…
lmiller1990 Jun 21, 2021
e61aea5
move webpack to devDependencies
chrisbreiding Jun 21, 2021
348b6c4
fix test in a hacky way
lmiller1990 Jun 22, 2021
f6f08f4
Merge branch 'fix-15447' of https://github.com/lukeapage/cypress into…
lmiller1990 Jun 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions npm/webpack-preprocessor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const debugStats = require('debug')('cypress:webpack:stats')
type FilePath = string
interface BundleObject {
promise: Promise<FilePath>
deferreds: Array<{ resolve: (filePath: string) => void, reject: (error: Error) => void, promise: Promise<string> }>
initial: boolean
}

Expand Down Expand Up @@ -226,16 +227,14 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F

const compiler = webpack(webpackOptions)

// we keep a reference to the latest bundle in this scope
// it's a deferred object that will be resolved or rejected in
// the `handle` function below and its promise is what is ultimately
// returned from this function
let latestBundle = createDeferred<string>()
let firstBundle = createDeferred<string>()

// cache the bundle promise, so it can be returned if this function
// is invoked again with the same filePath
bundles[filePath] = {
promise: latestBundle.promise,
promise: firstBundle.promise,
// we will resolve all reject everything in this array when a compile completes in the `handle` function
deferreds: [firstBundle],
initial: true,
}

Expand All @@ -247,7 +246,11 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F

debug(`errored bundling ${outputPath}`, err.message)

latestBundle.reject(err)
bundles[filePath].deferreds.forEach((deferred) => {
deferred.reject(err)
})

bundles[filePath].deferreds.length = 0
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
}

// this function is called when bundling is finished, once at the start
Expand Down Expand Up @@ -294,7 +297,11 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
// Seems to be a race condition where changing file before next tick
// does not cause build to rerun
Promise.delay(0).then(() => {
latestBundle.resolve(outputPath)
bundles[filePath].deferreds.forEach((deferred) => {
deferred.resolve(outputPath)
})

bundles[filePath].deferreds.length = 0
})
}

Expand All @@ -303,11 +310,10 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F

const onCompile = () => {
debug('compile', filePath)
// we overwrite the latest bundle, so that a new call to this function
// returns a promise that resolves when the bundling is finished
latestBundle = createDeferred<string>()
bundles[filePath].promise = latestBundle.promise
const nextBundle = createDeferred<string>()

bundles[filePath].promise = nextBundle.promise
bundles[filePath].deferreds.push(nextBundle)
bundles[filePath].promise.finally(() => {
debug('- compile finished for %s, initial? %s', filePath, bundles[filePath].initial)
// when the bundling is finished, emit 'rerun' to let Cypress
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-preprocessor/test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('webpack preprocessor', function () {
this.compilerApi.plugin.withArgs('compile').yield()
this.compilerApi.watch.yield(null, this.statsApi)

return Promise.delay(10) // give assertion time till next tick
return Promise.delay(11) // give assertion time till next tick
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
})
.then(() => {
expect(this.file.emit).to.be.calledWith('rerun')
Expand Down