Skip to content

Latest commit

 

History

History
112 lines (68 loc) · 3.11 KB

README.md

File metadata and controls

112 lines (68 loc) · 3.11 KB

Real package imports E2E tests

A suite of e2e tests to track Endo's compatibility with the npm ecosystem.

Run

First run

npm start

It only needs to be installed once.

To execute tests, run:

npm test

Testing local instance

To test your local Endo, open index.mjs and switch the imports to your local path.

Example

import '../../endo/packages/ses/index.js';
import { importLocation } from '../../endo/packages/compartment-mapper/index.js';

Cases

Dependencies in test-imports/package.json are tested by default.
Each dependency has test cases generated for it checking if it works in cjs and in esm contexts.

You can manually add test cases to test-imports/cases and all files there will run.

Adding cases

Default test cases are generated by running

npm run install-case 'packagename'
npm run generate-cases

Existing files will not be overwritten. To regenerate all cases from dependencies run npm mrun generate-cases overwrite

Test case format

Each file in test-imports/cases is used when you run tests.
A test case must export expected and actual - these two will be passed to Ava's deepEqual assertion.

Known issues

REJECTED cases can be solved by adding a transform. I'm not listing all cases of rejections because there's just too many Scaffolding for these tests adds a transform to avoid the most common ones.

typescript

  • triggers SES_HTML_COMMENT_REJECTED error from comments
  • triggers SES_IMPORT_REJECTED error from comments
  • triggers SES_IMPORT_REJECTED error from string literals in source code

Import example:

Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0: diag(1340, ts.DiagnosticCategory.Error, "Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0_1340", "Module '{0}' does not refer to a type, but is used as a type here. Did you mean 'typeof import('{0}')'?"),
function getImportTypePrefix(moduleSpecifier, quotePreference) {
  var quote = ts.getQuoteFromPreference(quotePreference);
  return 'import('.concat(quote).concat(moduleSpecifier).concat(quote, ').');
}

Replacing import( with import\( in strings should work seamlessly.

node-fetch

  • a dependency attempts to extend intrinsics
    `Cannot add property WebStreamsPolyfill, object is not extensible node_modules/web-streams-polyfill/dist/ponyfill.es2018.js:4:113``

eslint

  • triggers SES_IMPORT_REJECTED error from comments (addressed by the transforms)

  • Throws Cannot use 'import.meta' outside a module on evaluation attempt

  • One of its dependencies attempts to use require.resolve

punycode

  • exports different shapes for esm and cjs. Endo loads only the esm variant regardless of import/require.

acorn

  • issues with loading the right file from exports field in package.json, nothing is exported as a result.

@noble/hashes

  • ./crypto wouldn't load. Not sure why.

json-rpc-engine

  • Minor discrepancies in exported fields availability.

css-loader

  • css-loader/dist/plugins/postcss-import-parser.js:158 - a method named import() - needs stronger evasion