Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

AVA tests are broken after v0.19.2 for default exports #240

Closed
Lichtjaeger opened this issue Jan 17, 2018 · 10 comments
Closed

AVA tests are broken after v0.19.2 for default exports #240

Lichtjaeger opened this issue Jan 17, 2018 · 10 comments
Labels

Comments

@Lichtjaeger
Copy link

Lichtjaeger commented Jan 17, 2018

In addition to #233.

If I use the import statement for default exports with mjs files (import <packagename> from '<filename>.mjs') it results in an object with a "default" property.

This "default" property contains the real default export. This is also true for imports like import { default as <packagename> } from '<filename>.mjs'.

Here a ZIP file with a small test project.

Named exports do work.

@jdalton
Copy link
Member

jdalton commented Jan 17, 2018

Hi @Lichtjaeger!

Thanks for the repro!

ava uses Babel to process test files so you'll want to use the @std/esm option of

"@std/esm": "cjs"

or long form

"@std/esm" {
  "cjs": true,
  "esm": "js"
}

Then your tests will work properly.

Update:

I added the ava options tip to readme.
When ava adds their how-to, I'll link to that.

@Lichtjaeger
Copy link
Author

Is it possible to limit this behavior only to AVA?

I would like to use esm in my source files the most native way. For example, if I use the "cjs" option it will be possible to use __dirname and I'm not forced to use import.meta.url, so I can accidentally use __dirname. If I switch to native esm or copy my code into a project with native esm support this could result in an error.

@jdalton
Copy link
Member

jdalton commented Jan 17, 2018

Is it possible to limit this behavior only to AVA?

It will be in the next release of AVA. They will make it so that when you use @std/esm it will bypass Babel and allow you to load without it. I'll also look into making sure .esmrc files in the test folder can be used.

@Lichtjaeger
Copy link
Author

Thanks a lot. Sounds great.

@Lichtjaeger
Copy link
Author

I can confirm: it works with the "cjs" option.

@jdalton
Copy link
Member

jdalton commented Jan 17, 2018

Oh hey, you can also use the option:

"@std/esm": {
  "cjs": {
    "interop": true
  }
}

to just get the Babel CJS compat.

@Lichtjaeger
Copy link
Author

Nice. Do you also know how to make this work with wallaby.js?

@jdalton
Copy link
Member

jdalton commented Jan 18, 2018

I've asked at wallabyjs/public#1468.

@ArtemGovorov
Copy link

Added the @std/esm configuration notes to wallaby docs.

@jdalton
Copy link
Member

jdalton commented Jan 19, 2018

Thank you @ArtemGovorov!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants