mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

This commit also adds a suggestion flag (if exists) when ERR_ACCESS_DENIED is thrown, so users don't need to jump into the documentation to see how to manage that permission error. PR-URL: https://github.com/nodejs/node/pull/57585 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
32 lines
679 B
JavaScript
32 lines
679 B
JavaScript
// Flags: --permission --allow-fs-read=*
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const {
|
|
Worker,
|
|
isMainThread,
|
|
} = require('worker_threads');
|
|
|
|
if (!isMainThread) {
|
|
common.skip('This test only works on a main thread');
|
|
}
|
|
|
|
const assert = require('assert');
|
|
|
|
// Guarantee the initial state
|
|
{
|
|
assert.ok(!process.permission.has('worker'));
|
|
}
|
|
|
|
if (isMainThread) {
|
|
assert.throws(() => {
|
|
new Worker(__filename);
|
|
}, common.expectsError({
|
|
message: 'Access to this API has been restricted. Use --allow-worker to manage permissions.',
|
|
code: 'ERR_ACCESS_DENIED',
|
|
permission: 'WorkerThreads',
|
|
}));
|
|
} else {
|
|
assert.fail('it should not be called');
|
|
}
|