Skip to content

Commit

Permalink
support @std/esm (#1618)
Browse files Browse the repository at this point in the history
* support @std/esm

* fix path test for windows

* fix linter error

* Stricter regex. Use shorthand .esmrc file in fixture.

* update package-lock.json
  • Loading branch information
jamestalmage authored Jan 8, 2018
1 parent 29e5dfd commit 72c53be
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ globals.options = opts;

const serializeError = require('./serialize-error');

(opts.require || []).forEach(x => require(x));
(opts.require || []).forEach(x => {
if (/[/\\]@std[/\\]esm[/\\]index\.js$/.test(x)) {
require = require(x)(module); // eslint-disable-line no-global-assign
} else {
require(x);
}
});

adapter.installSourceMapSupport();
adapter.installPrecompilerHook();
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"update-notifier": "^2.3.0"
},
"devDependencies": {
"@std/esm": "^0.19.1",
"cli-table2": "^0.2.0",
"codecov": "^3.0.0",
"del": "^3.0.0",
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/std-esm/.esmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esm": "cjs"
}
1 change: 1 addition & 0 deletions test/fixture/std-esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'foo';
6 changes: 6 additions & 0 deletions test/fixture/std-esm/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from '../../../';
import m from '.';

test('works', t => {
t.is(m, 'foo');
});
11 changes: 11 additions & 0 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ test('babelrc is ignored', t => {
});
});

test('@std/esm support', t => {
return fork(fixture('std-esm/test.js'), {
require: [require.resolve('@std/esm')]
})
.run({})
.then(info => {
t.is(info.stats.passCount, 1);
t.end();
});
});

// TODO: Skipped until we can do this properly in #1455
test('color support is initialized correctly', t => {
t.plan(1);
Expand Down

2 comments on commit 72c53be

@BenSower
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice, is there any documentation on this, yet? From what I see, this just allows ava to use std-esm out of the box instead of having to add it to the dependencies manually, right?

@novemberborn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenSower you still need to add it to your package's dependencies.

Regarding documentation, there's a stalled PR (#1593, see #1590 for the issue). Perhaps you'd want to pick that up?

Please sign in to comment.