Skip to content

Commit 56b56c1

Browse files
committed
Load compiled helpers if in the "require" configuration
AVA now installs its source map support and precompiler hook *before* processing the "require" paths. This means that helpers can safely be added to the "require" configuration and their compiled versions will be loaded. Fixes #1506.
1 parent 50b0b4e commit 56b56c1

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

lib/test-worker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ globals.options = opts;
2727

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

30+
// Install before processing opts.require, so if helpers are added to the
31+
// require configuration the *compiled* helper will be loaded.
32+
adapter.installSourceMapSupport();
33+
adapter.installPrecompilerHook();
34+
3035
(opts.require || []).forEach(x => {
3136
if (/[/\\]@std[/\\]esm[/\\]index\.js$/.test(x)) {
3237
require = require(x)(module); // eslint-disable-line no-global-assign
@@ -35,9 +40,6 @@ const serializeError = require('./serialize-error');
3540
}
3641
});
3742

38-
adapter.installSourceMapSupport();
39-
adapter.installPrecompilerHook();
40-
4143
const testPath = opts.file;
4244

4345
const dependencies = new Set();

test/cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,10 @@ test('power-assert when babel=false and compileEnhancements=true', t => {
856856
t.end();
857857
});
858858
});
859+
860+
test('workers load compiled helpers if in the require configuration', t => {
861+
execCli(['test/verify.js'], {dirname: 'fixture/require-compiled-helper'}, err => {
862+
t.ifError(err);
863+
t.end();
864+
});
865+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = '🦄';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ava": {
3+
"require": [
4+
"./test/_helper"
5+
]
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import value from '../dependency';
2+
3+
global.value = value;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../../';
2+
3+
test(t => {
4+
t.is(global.value, '🦄');
5+
});

0 commit comments

Comments
 (0)