Skip to content

Commit

Permalink
test(ses): update Hermes smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
leotm committed Jul 31, 2024
1 parent 4fa7963 commit 0def87d
Showing 1 changed file with 53 additions and 44 deletions.
97 changes: 53 additions & 44 deletions packages/ses/test/hermes-smoke.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 0def87d

Please sign in to comment.