mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

Make changes so that tests will pass when the comma-dangle settings applied to the rest of the code base are also applied to tests. PR-URL: https://github.com/nodejs/node/pull/37930 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// Flags: --experimental-vm-modules
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { SourceTextModule } = require('vm');
|
|
|
|
async function testBasic() {
|
|
const m = new SourceTextModule('globalThis.importMeta = import.meta;', {
|
|
initializeImportMeta: common.mustCall((meta, module) => {
|
|
assert.strictEqual(module, m);
|
|
meta.prop = 42;
|
|
})
|
|
});
|
|
await m.link(common.mustNotCall());
|
|
await m.evaluate();
|
|
const result = globalThis.importMeta;
|
|
delete globalThis.importMeta;
|
|
assert.strictEqual(typeof result, 'object');
|
|
assert.strictEqual(Object.getPrototypeOf(result), null);
|
|
assert.strictEqual(result.prop, 42);
|
|
assert.deepStrictEqual(Reflect.ownKeys(result), ['prop']);
|
|
}
|
|
|
|
async function testInvalid() {
|
|
for (const invalidValue of [
|
|
null, {}, 0, Symbol.iterator, [], 'string', false,
|
|
]) {
|
|
assert.throws(() => {
|
|
new SourceTextModule('', {
|
|
initializeImportMeta: invalidValue
|
|
});
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError'
|
|
});
|
|
}
|
|
}
|
|
|
|
(async () => {
|
|
await testBasic();
|
|
await testInvalid();
|
|
})().then(common.mustCall());
|