Skip to content

Commit 72c53be

Browse files
authoredJan 8, 2018
support @std/esm (#1618)
* support @std/esm * fix path test for windows * fix linter error * Stricter regex. Use shorthand .esmrc file in fixture. * update package-lock.json
1 parent 29e5dfd commit 72c53be

File tree

7 files changed

+35
-1
lines changed

7 files changed

+35
-1
lines changed
 

‎lib/test-worker.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ globals.options = opts;
2727

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

30-
(opts.require || []).forEach(x => require(x));
30+
(opts.require || []).forEach(x => {
31+
if (/[/\\]@std[/\\]esm[/\\]index\.js$/.test(x)) {
32+
require = require(x)(module); // eslint-disable-line no-global-assign
33+
} else {
34+
require(x);
35+
}
36+
});
3137

3238
adapter.installSourceMapSupport();
3339
adapter.installPrecompilerHook();

‎package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
"update-notifier": "^2.3.0"
147147
},
148148
"devDependencies": {
149+
"@std/esm": "^0.19.1",
149150
"cli-table2": "^0.2.0",
150151
"codecov": "^3.0.0",
151152
"del": "^3.0.0",

‎test/fixture/std-esm/.esmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"esm": "cjs"
3+
}

‎test/fixture/std-esm/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'foo';

‎test/fixture/std-esm/test.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import test from '../../../';
2+
import m from '.';
3+
4+
test('works', t => {
5+
t.is(m, 'foo');
6+
});

‎test/fork.js

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ test('babelrc is ignored', t => {
135135
});
136136
});
137137

138+
test('@std/esm support', t => {
139+
return fork(fixture('std-esm/test.js'), {
140+
require: [require.resolve('@std/esm')]
141+
})
142+
.run({})
143+
.then(info => {
144+
t.is(info.stats.passCount, 1);
145+
t.end();
146+
});
147+
});
148+
138149
// TODO: Skipped until we can do this properly in #1455
139150
test('color support is initialized correctly', t => {
140151
t.plan(1);

2 commit comments

Comments
 (2)

BenSower commented on Jan 30, 2018

@BenSower

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 commented on Jan 30, 2018

@novemberborn
Member

@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.