/
hooks.js
82 lines (73 loc) · 2.91 KB
/
hooks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict'
const config = require('./config.json')
const hooks = require('../hooks')
const packager = require('..')
const test = require('ava')
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
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()
}]
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`)
return util.verifyPackageExistence(finalPaths)
}).then(exists => t.deepEqual(exists, [true, true], 'Packages should be generated for both 32-bit platforms'))
})
}
createHookTest('afterCopy')
createHookTest('afterPrune')
createHookTest('afterExtract')
test('promisifyHooks executes functions in parallel', t => {
let output = '0'
const testHooks = [
done => { output += ' 1'; done() },
done => { setTimeout(() => { output += ' 2'; done() }, 1000) },
done => { output += ' 3'; done() },
done => { setTimeout(() => { output += ' 4'; done() }, 1000) },
done => { output += ' 5'; done() },
done => { setTimeout(() => { output += ' 6'; done() }, 1000) },
done => { output += ' 7'; done() },
done => { setTimeout(() => { output += ' 8'; done() }, 1000) },
done => { output += ' 9'; done() },
done => { setTimeout(() => { output += ' 10'; done() }, 1000) }
]
return hooks.promisifyHooks(testHooks)
.then(() => t.not(output, '0 1 2 3 4 5 6 7 8 9 10', 'should not be in sequential order'))
})
test('serialHooks executes functions serially', t => {
let output = '0'
const timeoutFunc = number => {
return () => new Promise(resolve => { // eslint-disable-line promise/avoid-new
setTimeout(() => {
output += ` ${number}`
resolve()
}, 1000)
})
}
const testHooks = [
() => { output += ' 1'; return Promise.resolve() },
timeoutFunc(2),
() => { output += ' 3'; return Promise.resolve() },
timeoutFunc(4),
() => { output += ' 5'; return Promise.resolve() },
timeoutFunc(6),
() => { output += ' 7'; return Promise.resolve() },
timeoutFunc(8),
() => { output += ' 9'; return Promise.resolve() },
timeoutFunc(10)
]
return hooks.serialHooks(testHooks)(() => output)
.then(result => t.is(result, '0 1 2 3 4 5 6 7 8 9 10', 'should be in sequential order'))
})