forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-loader-worker.js
More file actions
27 lines (22 loc) · 997 Bytes
/
test-loader-worker.js
File metadata and controls
27 lines (22 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
require('../common');
const { spawnSync } = require('child_process');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const { execPath } = require('process');
const { writeFileSync } = require('fs');
const { join } = require('path');
tmpdir.refresh();
writeFileSync(join(tmpdir.path, 'hello.cjs'), 'console.log("hello")', 'utf8');
writeFileSync(join(tmpdir.path, 'loader.mjs'), 'import "./hello.cjs"', 'utf8');
writeFileSync(join(tmpdir.path, 'main.cjs'), 'setTimeout(() => {}, 1000)', 'utf8');
const child = spawnSync(execPath, ['--experimental-loader', './loader.mjs', 'main.cjs'], {
cwd: tmpdir.path
});
const stdout = child.stdout.toString().trim();
const stderr = child.stderr.toString().trim();
const hellos = [...stdout.matchAll(/hello/g)];
const warnings = [...stderr.matchAll(/ExperimentalWarning: Custom ESM Loaders/g)];
assert.strictEqual(child.status, 0);
assert.strictEqual(hellos.length, 1);
assert.strictEqual(warnings.length, 1);