test(compartment-mapper): cover expanded parser capabilities, expose export shape issue
MODIFY
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/index.js
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/index.js
@@ -4,6 +4,7 @@ const moduleinterops = require('./moduleinterops');
const stableOrderJson = require('./assertion-generators/json.cjs');
const cycle1 = require('./cycle1');
const defineprop = require('defineprop');
+const parserStruggles = require('parser-struggles');
// Generated by running v16.13.2: node assertion-generators/expected.cjs
// I chose this behavior because:
@@ -39,6 +40,11 @@ module.exports.assertions = {
);
}
},
+ parserStruggles() {
+ if (!parserStruggles.isOk) {
+ throw Error('Failed to get exports from nested require and no errors ocurred in the process.');
+ }
+ },
packageWithDefaultField() {
assertInteropNameCollisions({
name: 'interops',

MODIFY
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/package.json
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/package.json
"dependencies": {
"callself": "^1.0.0",
"defineprop": "^1.0.0",
- "interops": "^1.0.0"
+ "interops": "^1.0.0",
+ "parser-struggles": "^1.0.0"
}
}

ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/parser-struggles/README.md
+This is a package that poses some problems to the cjs parser when detecting require calls
\ No newline at end of file

ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/parser-struggles/is-ok.js
+module.exports = { isOk: true };

ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/parser-struggles/main.js
+function nothing() {
+ const require = () => {};
+ require('spam', 'asifitsdoingsomething');
+ require('./spam');
+// require('/spam'); // TODO: prevent this from causing errors
+ require('spam');
+ require(Mime);
+ require({ stuff: 1 });
+}
+
+// TODO: fix the export - .default should not be here
+function notMuch(item) {
+ const { isOk } = require('./is-ok').default;
+ return { isOk: item.isOk && isOk };
+}
+module.exports = notMuch(require('./is-ok').default);

ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/parser-struggles/package.json
+{
+ "name": "parser-struggles",
+ "main": "./main.js"
+}

MODIFY
packages/compartment-mapper/test/test-cjs-compat.js
packages/compartment-mapper/test/test-cjs-compat.js
// import "./ses-lockdown.js";
import '../../ses/index.js';
-import fs from 'fs';
-import url from 'url';
import test from 'ava';
-import { loadLocation } from '../src/import.js';
-import { makeReadPowers } from '../src/node-powers.js';
-const readPowers = makeReadPowers({ fs, url });
-const { read } = readPowers;
-
-test('CommonJS modules with cyclic dependency', async t => {
- t.plan(1);
+import { scaffold } from './scaffold.js';
const fixture = new URL(
'fixtures-cjs-compat/node_modules/app/index.js',
import.meta.url,
).toString();
- const application = await loadLocation(read, fixture);
- const {
- namespace: { assertions },
- } = await application.import({});
- assertions.moduleWithCycle();
- t.pass();
-});
-
-test('CommonJS referencing exports', async t => {
- t.plan(1);
+const assertFixture = (t, { namespace }) => {
+ console.error(namespace)
+ const { assertions } = namespace;
- const fixture = new URL(
- 'fixtures-cjs-compat/node_modules/app/index.js',
- import.meta.url,
- ).toString();
-
- const application = await loadLocation(read, fixture);
- const {
- namespace: { assertions },
- } = await application.import({});
assertions.packageReferencingItself();
- t.pass();
-});
-
-test('CommonJS exports include a field named `default`', async t => {
- t.plan(1);
-
- const fixture = new URL(
- 'fixtures-cjs-compat/node_modules/app/index.js',
- import.meta.url,
- ).toString();
-
- const application = await loadLocation(read, fixture);
- const {
- namespace: { assertions },
- } = await application.import({});
assertions.packageWithDefaultField();
assertions.moduleWithDefaultField();
+ assertions.parserStruggles();
+ assertions.moduleWithCycle();
+
t.pass();
-});
+};
+
+const fixtureAssertionCount = 1;
+
+scaffold(
+ 'fixtures-cjs-compat',
+ test,
+ fixture,
+ assertFixture,
+ fixtureAssertionCount,
+);

test(compartment-mapper): cover expanded parser capabilities, expose export shape issue