Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: tests live binding on a let (demonstrates: #2431) #2432

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/compartment-mapper/test/bundle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const fixture = new URL(
'fixtures-0/node_modules/bundle/main.js',
import.meta.url,
).toString();
const fixtureUnsupported = new URL(
'fixtures-0/node_modules/bundle/unsupported.js',
import.meta.url,
).toString();

const { read } = makeReadPowers({ fs, url });

Expand Down Expand Up @@ -83,6 +87,16 @@ test('equivalent archive behaves the same as bundle', async t => {
t.deepEqual(log, expectedLog);
});

test('unsupported: live binding in bundle throws', async t => {
const bundle = await makeBundle(read, fixtureUnsupported);
const compartment = new Compartment({
__options__: true,
});
t.throws(() => {
compartment.evaluate(bundle);
},{message: /buzz is not defined/});
});

// This is failing because it requires support for missing dependencies.
// Cannot bundle: encountered deferredError Cannot find file for internal module "./spam"
test.failing('bundle cjs-compat', async t => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions packages/ses/test/import-gauntlet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,32 @@ test('live binding', async t => {
t.is(namespace.default, 'Hello, World!');
});

test.only('live binding but it was defined first', async t => {
t.plan(1);

const makeImportHook = makeNodeImporter({
'https://example.com/main.js': `
let quuux = null;
// Live binding of an exported variable.
quuux = 'Hello, World!';
export { quuux };
`,
});

const compartment = new Compartment({
resolveHook: resolveNode,
importHook: makeImportHook('https://example.com'),
__noNamespaceBox__: true,
__options__: true,
});

// to preview what it's importing:
// console.log(await makeImportHook('https://example.com')('./main.js'))
// The only reason this ever works is moduleLexicals
const namespace = await compartment.import('./main.js');
t.is(namespace.quuux, 'Hello, World!');
});

test('live binding through reexporting intermediary', async t => {
t.plan(2);

Expand Down
Loading