From 0def87db44b43ea7fddb16fa4489a4176502b3f8 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:01:26 +0100 Subject: [PATCH] test(ses): update Hermes smoke test --- packages/ses/test/hermes-smoke.js | 97 +++++++++++++++++-------------- 1 file changed, 53 insertions(+), 44 deletions(-) diff --git a/packages/ses/test/hermes-smoke.js b/packages/ses/test/hermes-smoke.js index 6015fc04f2..8244ba0e89 100644 --- a/packages/ses/test/hermes-smoke.js +++ b/packages/ses/test/hermes-smoke.js @@ -1,44 +1,53 @@ -// TODO: equivalent of: -// import '../dist/ses.cjs'; -// import '../src/assert-shim.js'; -// Since Hermes has no native support for I/O - -// Test lockdown - -lockdown(); - -// Test Compartment - -const c = new Compartment(); - -c.evaluate('1+1'); -c.evaluate("const c2 = new Compartment(); c2.evaluate('1+2')"); - -// Test importHook and resolveHook - -// https://github.com/facebook/hermes/blob/main/doc/Features.md -// In Progress: ES modules (`import` and `export`) - -const resolveHook = (a) => a; - -async function importHook() { - return { - imports: [], - exports: ['meaning'], - execute(exports) { - exports.meaning = 42; - }, - }; -} - -const compartment = new Compartment({}, {}, { resolveHook, importHook }); - -const module = compartment.module('.'); - -// const { -// namespace: { _meaning }, -// } = await compartment.import('.'); - -assert(module); -// t.is(meaning, 42, 'exports seen'); -// t.is(module.meaning, 42, 'exports seen through deferred proxy'); +// Hermes doesn't support native I/O, +// so we concat the SES shim above, +// when running this test on the `hermesc`. + +/** + * Test calling SES lockdown. + */ +const testLockdown = () => { + lockdown(); +}; + +testLockdown(); + +/** + * TODO: Test creating a new Compartment. + */ +// eslint-disable-next-line no-unused-vars +const testCompartment = () => { + // eslint-disable-next-line no-unused-vars + const c = new Compartment(); +}; + +// testCompartment(); + +/** + * TODO: Test Compartment import hook and resolve hook. + */ +// eslint-disable-next-line no-unused-vars +const testCompartmentHooks = async () => { + const resolveHook = a => a; + + async function importHook() { + return { + imports: [], + exports: ['meaning'], + execute(exports) { + exports.meaning = 42; + }, + }; + } + + const compartment = new Compartment({}, {}, { resolveHook, importHook }); + + const module = compartment.module('.'); + + const { + namespace: { _meaning }, + } = await compartment.import('.'); + + assert(module); +}; + +// testCompartmentHooks();