/
test-worker.js
59 lines (47 loc) · 1.32 KB
/
test-worker.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
// Flags: --no-addons
'use strict';
const common = require('../../common');
const assert = require('assert');
const path = require('path');
const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const assertError = (error) => {
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
'Cannot load native addon because loading addons is disabled.',
);
};
{
// Flags should be inherited
const worker = new Worker(`require(${JSON.stringify(binding)})`, {
eval: true,
});
worker.on('error', common.mustCall(assertError));
}
{
// Should throw when using `process.dlopen` directly
const worker = new Worker(
`process.dlopen({ exports: {} }, ${JSON.stringify(binding)});`,
{
eval: true,
},
);
worker.on('error', common.mustCall(assertError));
}
{
// Explicitly pass `--no-addons`
const worker = new Worker(`require(${JSON.stringify(binding)})`, {
eval: true,
execArgv: ['--no-addons'],
});
worker.on('error', common.mustCall(assertError));
}
{
// If `execArgv` is overwritten it should still fail to load addons
const worker = new Worker(`require(${JSON.stringify(binding)})`, {
eval: true,
execArgv: [],
});
worker.on('error', common.mustCall(assertError));
}