test(compartment-mapper): Verify that importArchive can be bundled by makeBundle
MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -304,7 +304,8 @@ export const parseArchive = async (
__shimTransforms__,
Compartment,
});
- return compartment.import(moduleSpecifier);
+ // eslint-disable-next-line dot-notation
+ return compartment['import'](moduleSpecifier);
};
return { import: execute, sha512 };

MODIFY
packages/compartment-mapper/test/test-main.js
packages/compartment-mapper/test/test-main.js
import 'ses';
import test from 'ava';
-import { loadLocation, importArchive } from '../index.js';
+import { loadLocation, importArchive, makeBundle } from '../index.js';
import { scaffold, readPowers, setup } from './scaffold.js';
const fixture = new URL(
@@ -83,6 +83,42 @@ with the current test fixture.`);
assertFixture(t, { namespace, globals });
});
+test('makeBundle / importArchive', async t => {
+ t.plan(fixtureAssertionCount);
+
+ const archiverLocation = new URL(
+ '../src/import-archive.js',
+ import.meta.url,
+ ).toString();
+
+ const archiverBundle = await makeBundle(readPowers.read, archiverLocation);
+ const archiverCompartment = new Compartment({
+ TextEncoder,
+ TextDecoder,
+ URL,
+ assert,
+ });
+ const evasiveArchiverBundle = archiverBundle
+ .replace(/(?<!\.)\bimport\b(?![:"'])/g, 'IMPORT')
+ .replace(/\beval\b/g, 'EVAL');
+ const { importArchive: bundledImportArchive } = archiverCompartment.evaluate(
+ evasiveArchiverBundle,
+ );
+
+ const { globals, modules } = await setup();
+
+ const { namespace } = await bundledImportArchive(
+ readPowers.read,
+ archiveFixture,
+ {
+ globals,
+ modules,
+ Compartment,
+ },
+ );
+ assertFixture(t, { namespace, globals });
+});
+
test('no dev dependencies', async t => {
const { globals, modules } = await setup();

test(compartment-mapper): Verify that importArchive can be bundled by makeBundle