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

Execute hooks in series as per pre-v10 releases #812

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion common.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ module.exports = {
return Promise.resolve()
}

return Promise.all(hooks.map(hookFn => pify(hookFn).apply(this, args)))
const promisified = hooks.map(hookFn => pify(hookFn).bind(this, ...args))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the right way to do this without the spread operator?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact it looks like Node 4 will be EOL at the end of April, so I guess this could stay in if this gets accepted and released after that


return promisified.reduce((previous, current) => {
return previous.then(() => current())
}, Promise.resolve())
},

info: info,
Expand Down
44 changes: 36 additions & 8 deletions test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,51 @@ const util = require('./_util')
function createHookTest (hookName) {
// 2 packages will be built during this test
util.packagerTest(`platform=all test (one arch) (${hookName} hook)`, (t, opts) => {
let hookCalled = false
let fn1 = false
let fn2 = false
let fn3 = false

opts.dir = util.fixtureSubdir('basic')
opts.electronVersion = config.version
opts.arch = 'ia32'
opts.platform = 'all'

opts[hookName] = [(buildPath, electronVersion, platform, arch, callback) => {
hookCalled = true
t.is(electronVersion, opts.electronVersion, `${hookName} electronVersion should be the same as the options object`)
t.is(arch, opts.arch, `${hookName} arch should be the same as the options object`)
callback()
}]
opts[hookName] = [
(buildPath, electronVersion, platform, arch, callback) => {
fn1 = false
fn2 = false
fn3 = false
callback()
},
(buildPath, electronVersion, platform, arch, callback) => {
t.is(electronVersion, opts.electronVersion, `${hookName} electronVersion should be the same as the options object`)
t.is(arch, opts.arch, `${hookName} arch should be the same as the options object`)
setTimeout(() => {
fn1 = true
callback()
})
},
(buildPath, electronVersion, platform, arch, callback) => {
t.true(fn1, 'second hook executes after the first')
t.false(fn3, 'second hook executes before the third')
setTimeout(() => {
fn2 = true
callback()
})
},
(buildPath, electronVersion, platform, arch, callback) => {
t.true(fn1 && fn2, 'third hook executes after the first and second')
setTimeout(() => {
fn3 = true
callback()
})
}
]

return packager(opts)
.then(finalPaths => {
t.is(finalPaths.length, 2, 'packager call should resolve with expected number of paths')
t.true(hookCalled, `${hookName} methods should have been called`)
t.true(fn1 && fn2 && fn3, `${hookName} methods should have been called`)
return util.verifyPackageExistence(finalPaths)
}).then(exists => t.deepEqual(exists, [true, true], 'Packages should be generated for both 32-bit platforms'))
})
Expand Down