Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup: add test for process.dlopen
  • Loading branch information
d3lm committed Sep 7, 2021
commit c676d7299436e200b0291085e09a80433a39e90f
20 changes: 16 additions & 4 deletions test/addons/no-addons/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { Worker } = require('worker_threads');

const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);

const expectError = (error) => {
const assertError = (error) => {
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
Expand All @@ -23,7 +23,19 @@ const expectError = (error) => {
eval: true,
});

worker.on('error', common.mustCall(expectError));
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));
}

{
Expand All @@ -33,7 +45,7 @@ const expectError = (error) => {
execArgv: ['--no-addons'],
});

worker.on('error', common.mustCall(expectError));
worker.on('error', common.mustCall(assertError));
}

{
Expand All @@ -43,5 +55,5 @@ const expectError = (error) => {
execArgv: [],
});

worker.on('error', common.mustCall(expectError));
worker.on('error', common.mustCall(assertError));
}
33 changes: 26 additions & 7 deletions test/addons/no-addons/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,37 @@ const assert = require('assert');

const bindingPath = require.resolve(`./build/${common.buildType}/binding`);

let threw = false;

try {
require(bindingPath);
} catch (error) {
threw = true;
const assertError = (error) => {
assert(error instanceof Error);
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
'Cannot load native addon because loading addons is disabled.'
);
};

{
let threw = false;

try {
require(bindingPath);
} catch (error) {
assertError(error);
threw = true;
}

assert(threw);
}

assert(threw);
{
let threw = false;

try {
process.dlopen({ exports: {} }, bindingPath);
} catch (error) {
assertError(error);
threw = true;
}

assert(threw);
}