Skip to content

Restore the JavaScript test suite - #499

Open
dajiaohuang wants to merge 1 commit into
elixirscript:masterfrom
dajiaohuang:fix/restore-js-test-suite
Open

dajiaohuang wants to merge 1 commit into
elixirscript:masterfrom
dajiaohuang:fix/restore-js-test-suite

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

npm test — which make test and CI both run — cannot start. Three separate problems, all introduced when the JS dependencies were bumped:

1. ava rejects its own config

$ npx ava
× Unexpected Babel configuration for AVA. See https://github.com/avajs/ava/blob/v2.3.0/docs/recipes/babel.md for allowed values.

ava 2 only accepts extensions and testOptions under the babel key. babel-register already reads .babelrc on its own, so the key is redundant and is simply dropped.

2. The test script passes a directory

$ npx ava src/javascript/tests
× src/javascript/tests is not a test file.

ava 2 resolves CLI arguments as literal paths. Its default file patterns already include **/*.spec.js, and every file under src/javascript/tests/ is one, so the argument is not needed.

3. The default import of erlang-types is undefined under babel 6

node_modules/erlang-types/lib/index.js sets __esModule and exports only named bindings, so _interopRequireDefault returns the module unchanged and .default is undefined:

import ErlangTypes from 'erlang-types';   // undefined
const selfPID = new ErlangTypes.PID();    // TypeError

which made every spec fail:

Uncaught exception in src/javascript/tests/for.spec.js
  TypeError: Cannot read properties of undefined (reading 'PID')

The rollup build tolerates the default import because rollup-plugin-commonjs maps a CJS module without a default export onto the namespace object, but a namespace import is the correct form for both toolchains.

Changes

  • package.json: drop the invalid ava.babel key, change test to nyc ava
  • core.js, core/erlang_compat/{erlang,lists,maps}.js: use import * as ErlangTypes from 'erlang-types'

Testing

With these changes:

$ npx ava
  71 tests passed

npm run build still succeeds, and the regenerated priv/testrunner/vendor.build.js is byte-identical to the committed one.

Note on npm test itself: it could not be run end-to-end here. nyc ava aborts with Cannot find module '...\node' because nyc 14 predates the Node version used for this check (the project pins Node 12.8.1 in .travis.yml). nyc is untouched by this PR, which is why the run above uses npx ava directly.

`npm test`, which `make test` and CI run, has not been able to start
since the ava 2.x upgrade:

- ava 2 rejects the `ava.babel` key with "Unexpected Babel configuration
  for AVA". babel-register already reads .babelrc, so the key is
  redundant and can simply be dropped.
- ava 2 treats CLI arguments as literal files and exits with
  "src/javascript/tests is not a test file." when given a directory.
  ava's default file patterns already match
  src/javascript/tests/**/*.spec.js, so no argument is needed.
- `import ErlangTypes from 'erlang-types'` evaluates to undefined under
  babel 6. erlang-types sets __esModule and exports only named bindings,
  so _interopRequireDefault returns the module unchanged and `.default`
  is undefined, which made every spec fail with "Cannot read properties
  of undefined (reading 'PID')". A namespace import is the correct form
  for both babel and the rollup build.

71 tests pass with these changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant