Skip to content

Commit

Permalink
Add --no-esm flag to disable '-r esm' behavior
Browse files Browse the repository at this point in the history
Re #517
Re #516
  • Loading branch information
isaacs committed Mar 7, 2019
1 parent e2c0c1d commit 040f61f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
16 changes: 13 additions & 3 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ const constructDefaultArgs = _ => {
const defaultTimeout = global.__coverage__ ? 240 : 30

const defaultArgs = {
nodeArgs: [ '-r', require.resolve('esm') ],
nodeArgs: [],
nycArgs: [],
testArgs: [],
timeout: +process.env.TAP_TIMEOUT || defaultTimeout,
color: !!colorSupport.level,
reporter: null,
files: [],
esm: true,
grep: [],
grepInvert: false,
bail: false,
Expand Down Expand Up @@ -262,6 +263,14 @@ const parseArgs = (args, options) => {
defaultCoverage = true
continue

case '--no-esm':
options.esm = false
continue

case '--esm':
options.esm = true
continue

case '--no-browser':
options.browser = false
continue
Expand Down Expand Up @@ -706,6 +715,7 @@ const runAllFiles = (options, saved, tap) => {

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

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

if (file.match(/\.m?js$/)) {
const args = options.nodeArgs.concat(file).concat(options.testArgs)
const args = esmArg.concat(options.nodeArgs).concat(file).concat(options.testArgs)
tap.spawn(node, args, opt, file)
} else if (file.match(/\.ts$/)) {
const args = options.nodeArgs.concat(file).concat(options.testArgs)
const args = esmArg.concat(options.nodeArgs).concat(file).concat(options.testArgs)
tap.spawn(tsNode, args, opt, file)
} else if (isexe.sync(options.files[i]))
tap.spawn(options.files[i], options.testArgs, opt, file)
Expand Down
5 changes: 5 additions & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Coverage is never enabled for stdin.

Options:

--esm Support ES Modules in *.js and *.mjs files.
(Default)

--no-esm Do not add support for ES Modules.

-j<n> --jobs=<n> Run up to <n> test files in parallel
Note that this causes tests to be run in
"buffered" mode, so line-by-line results
Expand Down
5 changes: 5 additions & 0 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Coverage is never enabled for stdin.
Options:
--esm Support ES Modules in *.js and *.mjs files.
(Default)
--no-esm Do not add support for ES Modules.
-j<n> --jobs=<n> Run up to <n> test files in parallel
Note that this causes tests to be run in
"buffered" mode, so line-by-line results
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"repository": "https://github.com/tapjs/node-tap.git",
"scripts": {
"regen-fixtures": "node scripts/generate-test-test.js test-legacy/test/*.js",
"snap": "TAP_SNAPSHOT=1 node bin/run.js test/*.js -J",
"test": "node bin/run.js test/*.js --100 -J --nyc-arg=--include={lib,bin} -c",
"snap": "TAP_SNAPSHOT=1 node bin/run.js --no-esm test/*.js -J",
"test": "node bin/run.js --no-esm test/*.js --100 -J --nyc-arg=--include={lib,bin} -c",
"test-all": "node bin/run.js test/*.js test-legacy/*.js --100 -J --nyc-arg=--include={lib,bin} && npm run test-browser",
"test-browser": "node browser-test.js",
"unit": "bash scripts/unit.sh",
Expand Down
9 changes: 4 additions & 5 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ t.test('dump config stuff', t => {
t.equal(er, null)
t.match(JSON.parse(o), {
nodeArgs:
[ '-r', 'esm',
'--expose-gc',
[ '--expose-gc',
'--use_strict',
'--debug',
'--debug-brk',
Expand Down Expand Up @@ -642,7 +641,7 @@ t.test('mjs', t => {
import t from ${tap}
t.pass('this is fine')
`)
run([ok], {}, (er, o, e) => {
run([ok, '--esm'], {}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o))
t.end()
Expand All @@ -654,7 +653,7 @@ t.test('esm', t => {
import {t} from ${tap}
t.pass('this is fine')
`)
run([ok], {}, (er, o, e) => {
run([ok, '--esm'], {}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o))
t.end()
Expand All @@ -666,7 +665,7 @@ t.test('ts', t => {
import * as t from ${tap}
t.pass('this is fine')
`)
run([ok], {}, (er, o, e) => {
run([ok, '--esm'], {}, (er, o, e) => {
t.equal(er, null)
t.matchSnapshot(clean(o))
t.end()
Expand Down

0 comments on commit 040f61f

Please sign in to comment.