Skip to content

Commit 5b1e3ae

Browse files
committed
test: fix wrong assumptions
1 parent 48573e2 commit 5b1e3ae

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

test/abort/test-abort-fatal-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (common.isWindows)
2727
const assert = require('assert');
2828
const exec = require('child_process').exec;
2929

30-
let cmdline = `ulimit -c 0; ${process.execPath}`;
30+
let cmdline = `ulimit -c 0; ${JSON.stringify(process.execPath)}`;
3131
cmdline += ' --max-old-space-size=16 --max-semi-space-size=4';
3232
cmdline += ' -e "a = []; for (i = 0; i < 1e9; i++) { a.push({}) }"';
3333

test/es-module/test-esm-dynamic-import.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22
const common = require('../common');
3+
const { pathToFileURL } = require('url');
34
const assert = require('assert');
45

56
const relativePath = '../fixtures/es-modules/test-esm-ok.mjs';
6-
const absolutePath = require.resolve('../fixtures/es-modules/test-esm-ok.mjs');
7-
const targetURL = new URL('file:///');
8-
targetURL.pathname = absolutePath;
7+
const absolutePath = require.resolve(relativePath);
8+
const targetURL = pathToFileURL(absolutePath);
99

1010
function expectModuleError(result, code, message) {
1111
Promise.resolve(result).catch(common.mustCall((error) => {
@@ -41,7 +41,7 @@ function expectFsNamespace(result) {
4141
// expectOkNamespace(import(relativePath));
4242
expectOkNamespace(eval(`import("${relativePath}")`));
4343
expectOkNamespace(eval(`import("${relativePath}")`));
44-
expectOkNamespace(eval(`import("${targetURL}")`));
44+
expectOkNamespace(eval(`import(${JSON.stringify(targetURL)})`));
4545

4646
// Importing a built-in, both direct & via eval
4747
expectFsNamespace(import('fs'));

test/sequential/test-cli-syntax-require.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const { exec } = require('child_process');
5+
const { spawn } = require('child_process');
66
const fixtures = require('../common/fixtures');
77

88
const node = process.execPath;
@@ -17,20 +17,25 @@ const syntaxErrorRE = /^SyntaxError: \b/m;
1717
const preloadFile = fixtures.path('no-wrapper.js');
1818
const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js');
1919
const args = [requireFlag, preloadFile, checkFlag, file];
20-
const cmd = [node, ...args].join(' ');
21-
exec(cmd, common.mustCall((err, stdout, stderr) => {
22-
assert.strictEqual(err instanceof Error, true);
23-
assert.strictEqual(err.code, 1,
24-
`code ${err.code} !== 1 for error:\n\n${err}`);
20+
const cp = spawn(node, args);
2521

26-
// No stdout should be produced
27-
assert.strictEqual(stdout, '');
22+
// No stdout should be produced
23+
cp.stdout.on('data', common.mustNotCall('stdout data event'));
2824

25+
const stderrBuffer = [];
26+
cp.stderr.on('data', (chunk) => stderrBuffer.push(chunk));
27+
28+
cp.on('exit', common.mustCall((code, signal) => {
29+
assert.strictEqual(code, 1);
30+
assert.strictEqual(signal, null);
31+
32+
const stderr = Buffer.concat(stderrBuffer).toString('utf-8');
2933
// stderr should have a syntax error message
3034
assert.match(stderr, syntaxErrorRE);
3135

3236
// stderr should include the filename
3337
assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
3438
}));
39+
3540
});
3641
});

test/sequential/test-watch-mode.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { describe, it } from 'node:test';
77
import { spawn } from 'node:child_process';
88
import { writeFileSync, readFileSync, mkdirSync } from 'node:fs';
99
import { inspect } from 'node:util';
10+
import { pathToFileURL } from 'node:url';
1011
import { createInterface } from 'node:readline';
1112

1213
if (common.isIBMi)
@@ -276,7 +277,7 @@ console.log(values.random);
276277

277278
it('should not load --import modules in main process', async () => {
278279
const file = createTmpFile();
279-
const imported = `file://${createTmpFile('setImmediate(() => process.exit(0));')}`;
280+
const imported = pathToFileURL(createTmpFile('setImmediate(() => process.exit(0));'));
280281
const args = ['--import', imported, file];
281282
const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, args });
282283

@@ -320,7 +321,8 @@ console.log(values.random);
320321
}, async () => {
321322
const dependency = path.join(tmpdir.path, `${tmpFiles++}.mjs`);
322323
const relativeDependencyPath = `./${path.basename(dependency)}`;
323-
const dependant = createTmpFile(`import '${relativeDependencyPath}'`, '.mjs');
324+
const dependant = createTmpFile(`import '${relativeDependencyPath}'import { pathToFileURL } from 'node:url';
325+
`, '.mjs');
324326

325327
await failWriteSucceed({ file: dependant, watchedFile: dependency });
326328
});

0 commit comments

Comments
 (0)