Skip to content

Commit

Permalink
test: simplify flags logic for esm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Jan 4, 2019
1 parent bdcbdae commit 146681b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
15 changes: 7 additions & 8 deletions test/es-module/test-esm-loader-dependency.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import '../fixtures/es-modules/test-esm-ok.mjs';

// We just test that this module doesn't fail loading

const flag = '--loader=./test/fixtures/es-module-loaders/loader-with-dep.mjs';
if (!process.execArgv.includes(flag)) {
(async () => {
const { requireFlags } = await import('../common');
// Include `--experimental-modules` explicitly for workers.
requireFlags('--experimental-modules', flag);
})();
}
(async () => {
const { requireFlags } = await import('../common');
requireFlags(
'--experimental-modules',
'--loader=./test/fixtures/es-module-loaders/loader-with-dep.mjs'
);
})();
11 changes: 4 additions & 7 deletions test/es-module/test-esm-loader-invalid-format.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { expectsError, mustCall, requireFlags } from '../common';
import assert from 'assert';

const flag =
'--loader=./test/fixtures/es-module-loaders/loader-invalid-format.mjs';

if (!process.execArgv.includes(flag)) {
// Include `--experimental-modules` explicitly for workers.
requireFlags('--experimental-modules', flag);
}
requireFlags(
'--experimental-modules',
'--loader=./test/fixtures/es-module-loaders/loader-invalid-format.mjs'
);

import('../fixtures/es-modules/test-esm-ok.mjs')
.then(assert.fail, expectsError({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { expectsError, requireFlags } from '../common';

const flag =
const longFlag =
'--loader=' +
'./test/fixtures/es-module-loaders/missing-dynamic-instantiate-hook.mjs';

if (!process.execArgv.includes(flag)) {
// Include `--experimental-modules` explicitly for workers.
requireFlags('--experimental-modules', flag);
}
requireFlags('--experimental-modules', longFlag);

import('test').catch(expectsError({
code: 'ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
Expand Down
10 changes: 4 additions & 6 deletions test/es-module/test-esm-named-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { readFile } from 'fs';
import assert from 'assert';
import ok from '../fixtures/es-modules/test-esm-ok.mjs';

const flag =
'--loader=./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs';
if (!process.execArgv.includes(flag)) {
// Include `--experimental-modules` explicitly for workers.
requireFlags('--experimental-modules', flag);
}
requireFlags(
'--experimental-modules',
'--loader=./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs'
);

assert(ok);
assert(readFile);
9 changes: 4 additions & 5 deletions test/es-module/test-esm-shared-loader-dep.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import assert from 'assert';
import '../fixtures/es-modules/test-esm-ok.mjs';
import dep from '../fixtures/es-module-loaders/loader-dep.js';

const flag = '--loader=./test/fixtures/es-module-loaders/loader-shared-dep.mjs';
if (!process.execArgv.includes(flag)) {
// Include `--experimental-modules` explicitly for workers.
requireFlags('--experimental-modules', flag);
}
requireFlags(
'--experimental-modules',
'--loader=./test/fixtures/es-module-loaders/loader-shared-dep.mjs'
);

assert.strictEqual(dep.format, 'esm');

0 comments on commit 146681b

Please sign in to comment.