Skip to content

Test ES modules don't seem to work without esm package #2262

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

Closed
mightyiam opened this issue Oct 4, 2019 · 4 comments
Closed

Test ES modules don't seem to work without esm package #2262

mightyiam opened this issue Oct 4, 2019 · 4 comments

Comments

@mightyiam
Copy link
Contributor

mightyiam commented Oct 4, 2019

Thank you for my favorite test runner.

The ES modules recipe says:

By default AVA converts ES module syntax to CommonJS. You can disable this.

The Babel recipe also says:

By default our Babel pipeline is applied to test and helper files ending in .js.

And it also says:

By default AVA's stage-4 preset will convert ES module syntax to CommonJS. This can be disabled.

But my tests, which are written in TypeScript and ES modules and are not transpiled to CommonJS, but remain ES modules, are failing AVA. Here is a copy paste from my terminal:

➜  pick-path-router git:(ava-no-esm) head lib/index.test.js
import test from 'ava';
import xs from 'xstream';
import { div } from '@cycle/dom';
import Subject from '.';
import { mockTimeSource } from '@cycle/time';
const testPageSinks = {
    title: xs.of('foo'),
    breadcrumbs: xs.of([]),
    DOM: xs.of(div())
};
➜  pick-path-router git:(ava-no-esm) npx ava    


  ✖ No tests found in lib/index.test.js

  1 uncaught exception

  Uncaught exception in lib/index.test.js

  /home/mightyiam/src/cycle-components/pick-path-router/lib/index.test.ts:4

  /home/mightyiam/src/cycle-components/pick-path-router/lib/index.js:1
  import xs from 'xstream';
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module

Here is the pull request where I am trying to remove usage of the esm package:
https://github.com/cycle-components/pick-path-router/pull/93

Here are the changes.

And here is the failure in the CI log.

@mightyiam
Copy link
Contributor Author

Sorry. Somehow submitted prematurely. Editing.

@mightyiam mightyiam changed the title ES modules don't seem to work without esm package Test ES modules don't seem to work without esm package Oct 4, 2019
@mightyiam
Copy link
Contributor Author

Done editing description.

@novemberborn
Copy link
Member

AVA only transpiles your test files though. This error is coming from a source file.

The good news, as it were, is that we're looking to remove the out-of-the-box transpilation. So at least things will be less confusing.

(I'm closing this issue for housekeeping purposes, but let's keep the conversation going.)

@mightyiam
Copy link
Contributor Author

Thank you for the information, @novemberborn.

So it seems that I'm doing the right thing using the esm package.

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

No branches or pull requests

2 participants