Skip to content

Commit 040f61f

Browse files
committed
Add --no-esm flag to disable '-r esm' behavior
Re #517 Re #516
1 parent e2c0c1d commit 040f61f

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

bin/run.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ const constructDefaultArgs = _ => {
124124
const defaultTimeout = global.__coverage__ ? 240 : 30
125125

126126
const defaultArgs = {
127-
nodeArgs: [ '-r', require.resolve('esm') ],
127+
nodeArgs: [],
128128
nycArgs: [],
129129
testArgs: [],
130130
timeout: +process.env.TAP_TIMEOUT || defaultTimeout,
131131
color: !!colorSupport.level,
132132
reporter: null,
133133
files: [],
134+
esm: true,
134135
grep: [],
135136
grepInvert: false,
136137
bail: false,
@@ -262,6 +263,14 @@ const parseArgs = (args, options) => {
262263
defaultCoverage = true
263264
continue
264265

266+
case '--no-esm':
267+
options.esm = false
268+
continue
269+
270+
case '--esm':
271+
options.esm = true
272+
continue
273+
265274
case '--no-browser':
266275
options.browser = false
267276
continue
@@ -706,6 +715,7 @@ const runAllFiles = (options, saved, tap) => {
706715

707716
options.files = filterFiles(options.files, saved, parallelOk)
708717
let tapChildId = 0
718+
const esmArg = options.esm ? ['-r', require.resolve('esm')] : []
709719

710720
for (let i = 0; i < options.files.length; i++) {
711721
const opt = {}
@@ -738,10 +748,10 @@ const runAllFiles = (options, saved, tap) => {
738748
opt.buffered = isParallelOk(parallelOk, file) !== false
739749

740750
if (file.match(/\.m?js$/)) {
741-
const args = options.nodeArgs.concat(file).concat(options.testArgs)
751+
const args = esmArg.concat(options.nodeArgs).concat(file).concat(options.testArgs)
742752
tap.spawn(node, args, opt, file)
743753
} else if (file.match(/\.ts$/)) {
744-
const args = options.nodeArgs.concat(file).concat(options.testArgs)
754+
const args = esmArg.concat(options.nodeArgs).concat(file).concat(options.testArgs)
745755
tap.spawn(tsNode, args, opt, file)
746756
} else if (isexe.sync(options.files[i]))
747757
tap.spawn(options.files[i], options.testArgs, opt, file)

bin/usage.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Coverage is never enabled for stdin.
1717

1818
Options:
1919

20+
--esm Support ES Modules in *.js and *.mjs files.
21+
(Default)
22+
23+
--no-esm Do not add support for ES Modules.
24+
2025
-j<n> --jobs=<n> Run up to <n> test files in parallel
2126
Note that this causes tests to be run in
2227
"buffered" mode, so line-by-line results

docs/cli/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Coverage is never enabled for stdin.
2727
2828
Options:
2929
30+
--esm Support ES Modules in *.js and *.mjs files.
31+
(Default)
32+
33+
--no-esm Do not add support for ES Modules.
34+
3035
-j<n> --jobs=<n> Run up to <n> test files in parallel
3136
Note that this causes tests to be run in
3237
"buffered" mode, so line-by-line results

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"repository": "https://github.com/tapjs/node-tap.git",
6161
"scripts": {
6262
"regen-fixtures": "node scripts/generate-test-test.js test-legacy/test/*.js",
63-
"snap": "TAP_SNAPSHOT=1 node bin/run.js test/*.js -J",
64-
"test": "node bin/run.js test/*.js --100 -J --nyc-arg=--include={lib,bin} -c",
63+
"snap": "TAP_SNAPSHOT=1 node bin/run.js --no-esm test/*.js -J",
64+
"test": "node bin/run.js --no-esm test/*.js --100 -J --nyc-arg=--include={lib,bin} -c",
6565
"test-all": "node bin/run.js test/*.js test-legacy/*.js --100 -J --nyc-arg=--include={lib,bin} && npm run test-browser",
6666
"test-browser": "node browser-test.js",
6767
"unit": "bash scripts/unit.sh",

test/run.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ t.test('dump config stuff', t => {
133133
t.equal(er, null)
134134
t.match(JSON.parse(o), {
135135
nodeArgs:
136-
[ '-r', 'esm',
137-
'--expose-gc',
136+
[ '--expose-gc',
138137
'--use_strict',
139138
'--debug',
140139
'--debug-brk',
@@ -642,7 +641,7 @@ t.test('mjs', t => {
642641
import t from ${tap}
643642
t.pass('this is fine')
644643
`)
645-
run([ok], {}, (er, o, e) => {
644+
run([ok, '--esm'], {}, (er, o, e) => {
646645
t.equal(er, null)
647646
t.matchSnapshot(clean(o))
648647
t.end()
@@ -654,7 +653,7 @@ t.test('esm', t => {
654653
import {t} from ${tap}
655654
t.pass('this is fine')
656655
`)
657-
run([ok], {}, (er, o, e) => {
656+
run([ok, '--esm'], {}, (er, o, e) => {
658657
t.equal(er, null)
659658
t.matchSnapshot(clean(o))
660659
t.end()
@@ -666,7 +665,7 @@ t.test('ts', t => {
666665
import * as t from ${tap}
667666
t.pass('this is fine')
668667
`)
669-
run([ok], {}, (er, o, e) => {
668+
run([ok, '--esm'], {}, (er, o, e) => {
670669
t.equal(er, null)
671670
t.matchSnapshot(clean(o))
672671
t.end()

0 commit comments

Comments
 (0)