0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-vm-module-cached-data.js
Antoine du Hamel 8f742bb13f
test: ensure never settling promises are detected
PR-URL: https://github.com/nodejs/node/pull/50318
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-10-23 17:55:50 +00:00

31 lines
697 B
JavaScript

'use strict';
// Flags: --experimental-vm-modules
const common = require('../common');
const assert = require('assert');
const { SourceTextModule } = require('vm');
{
const m = new SourceTextModule('const a = 1');
const cachedData = m.createCachedData();
new SourceTextModule('const a = 1', { cachedData });
assert.throws(() => {
new SourceTextModule('differentSource', { cachedData });
}, {
code: 'ERR_VM_MODULE_CACHED_DATA_REJECTED',
});
}
assert.rejects(async () => {
const m = new SourceTextModule('const a = 1');
await m.link(() => {});
m.evaluate();
m.createCachedData();
}, {
code: 'ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA',
}).then(common.mustCall());