From 18ad1c187ab0bc4ea12ef929db2ee0679a22b63c Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Tue, 13 Aug 2019 09:14:38 +0200 Subject: [PATCH] treat '--require esm' as Node option (#3983) --- bin/mocha | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/mocha b/bin/mocha index df7cf48ca3..865f5b1f07 100755 --- a/bin/mocha +++ b/bin/mocha @@ -117,6 +117,16 @@ if (nodeArgs.gc) { delete nodeArgs.gc; } +// --require/-r is treated as Mocha flag except when 'esm' is preloaded +if (mochaArgs.require && mochaArgs.require.includes('esm')) { + nodeArgs.require = ['esm']; + mochaArgs.require = mochaArgs.require.filter(mod => mod !== 'esm'); + if (!mochaArgs.require.length) { + delete mochaArgs.require; + } + delete mochaArgs.r; +} + if (Object.keys(nodeArgs).length) { const {spawn} = require('child_process'); const mochaPath = require.resolve('../lib/cli/cli.js');