-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-module-hooks-load-async-and-sync.js
More file actions
32 lines (27 loc) · 1.26 KB
/
test-module-hooks-load-async-and-sync.js
File metadata and controls
32 lines (27 loc) · 1.26 KB
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
'use strict';
// This tests that sync and async hooks can be mixed.
require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
const app = fixtures.path('module-hooks', 'sync-and-async', 'app.js');
const testCases = [
// When mixing sync and async hooks, the sync ones always run first.
{ preload: ['sync-customize', 'async-customize'], stdout: 'customized by sync hook' },
{ preload: ['async-customize', 'sync-customize'], stdout: 'customized by sync hook' },
// It should still work when neither hook does any customization.
{ preload: ['sync-forward', 'async-forward'], stdout: 'Hello world' },
{ preload: ['async-forward', 'sync-forward'], stdout: 'Hello world' },
// It should work when only one hook is customizing.
{ preload: ['sync-customize', 'async-forward'], stdout: 'customized by sync hook' },
{ preload: ['async-customize', 'sync-forward'], stdout: 'customized by async hook' },
];
for (const { preload, stdout } of testCases) {
const importArgs = [];
for (const p of preload) {
importArgs.push('--import', fixtures.fileURL(`module-hooks/sync-and-async/${p}.js`));
}
spawnSyncAndAssert(process.execPath, [...importArgs, app], {
stdout,
trim: true,
});
}