From 040f61f213961ce3e94a865057a87494e2e2eb1f Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 6 Mar 2019 17:31:09 -0800 Subject: [PATCH] Add --no-esm flag to disable '-r esm' behavior Re #517 Re #516 --- bin/run.js | 16 +++++++++++++--- bin/usage.txt | 5 +++++ docs/cli/index.md | 5 +++++ package.json | 4 ++-- test/run.js | 9 ++++----- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bin/run.js b/bin/run.js index 0452b422e..68f02789a 100755 --- a/bin/run.js +++ b/bin/run.js @@ -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, @@ -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 @@ -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 = {} @@ -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) diff --git a/bin/usage.txt b/bin/usage.txt index 37eb39bef..97b851e1b 100644 --- a/bin/usage.txt +++ b/bin/usage.txt @@ -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 --jobs= Run up to test files in parallel Note that this causes tests to be run in "buffered" mode, so line-by-line results diff --git a/docs/cli/index.md b/docs/cli/index.md index b6017491b..f3e3acba3 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -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 --jobs= Run up to test files in parallel Note that this causes tests to be run in "buffered" mode, so line-by-line results diff --git a/package.json b/package.json index 5abbcee4d..0f5ee19cf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/run.js b/test/run.js index 9bc3c4e55..bb3f8895a 100644 --- a/test/run.js +++ b/test/run.js @@ -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', @@ -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() @@ -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() @@ -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()