mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
test: use common spawnSync helpers in more tests
The helpers report the command, both streams, and the exit condition on failure, so mismatches are diagnosed consistently across tests. Signed-off-by: greenhead <greenheadhq@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65552 Refs: https://github.com/nodejs/node/pull/65377 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
a2bf6702bf
commit
b7bca07db0
6 files changed
+46
-49
No files matched your search
@@ -1,14 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('node:assert/strict');
|
||||
const childProcess = require('node:child_process');
|
||||
const { spawnSyncAndExit } = require('../common/child_process');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
const child = childProcess.spawnSync(
|
||||
const { child } = spawnSyncAndExit(
|
||||
process.execPath,
|
||||
[ '--no-warnings', '--run'],
|
||||
{ cwd: fixtures.path('run-script'), encoding: 'utf8' },
|
||||
{ status: 9, signal: null },
|
||||
);
|
||||
assert.strictEqual(child.status, 9);
|
||||
console.log(child.stderr);
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as common from '../common/index.mjs';
|
||||
import tmpdir from '../common/tmpdir.js';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { spawnSyncAndExitWithoutError } from '../common/child_process.js';
|
||||
import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path';
|
||||
import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises';
|
||||
import { glob, globSync, Dirent, chmodSync, writeFileSync, rmSync } from 'node:fs';
|
||||
@@ -722,12 +722,11 @@ describe('glob - seen cache', function() {
|
||||
`;
|
||||
|
||||
const seenDir = tmpdir.resolve('glob-seen');
|
||||
const child = spawnSync(
|
||||
spawnSyncAndExitWithoutError(
|
||||
process.execPath,
|
||||
['--expose-internals', '-e', script, seenDir],
|
||||
{ encoding: 'utf8' },
|
||||
);
|
||||
assert.strictEqual(child.status, 0, child.stderr || child.stdout);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndAssert } = require('../common/child_process');
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
|
||||
tmpdir.refresh();
|
||||
@@ -38,11 +39,10 @@ const entry = tmpdir.resolve('main.mjs');
|
||||
fs.writeFileSync(entry, 'import { which } from "dep"; console.log(which);');
|
||||
|
||||
// Sanity check: the export resolves while the package config is readable.
|
||||
{
|
||||
const child = spawnSync(process.execPath, [entry], { encoding: 'utf8' });
|
||||
assert.strictEqual(child.stdout.trim(), 'real');
|
||||
assert.strictEqual(child.status, 0, child.stderr);
|
||||
}
|
||||
spawnSyncAndAssert(process.execPath, [entry], { encoding: 'utf8' }, {
|
||||
stdout: 'real',
|
||||
trim: true,
|
||||
});
|
||||
|
||||
fs.chmodSync(depPackageJson, 0o000);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import '../common/index.mjs';
|
||||
import { before, describe, it } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { cp } from 'node:fs/promises';
|
||||
import tmpdir from '../common/tmpdir.js';
|
||||
import fixtures from '../common/fixtures.js';
|
||||
import { spawnSyncAndAssert } from '../common/child_process.js';
|
||||
const skipIfNoInspector = {
|
||||
skip: !process.features.inspector ? 'inspector disabled' : false
|
||||
};
|
||||
@@ -57,14 +57,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
|
||||
'--test-reporter=tap',
|
||||
'--no-experimental-strip-types',
|
||||
];
|
||||
const result = spawnSync(process.execPath, args, {
|
||||
spawnSyncAndAssert(process.execPath, args, {
|
||||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
|
||||
cwd: tmpdir.path
|
||||
}, {
|
||||
stderr: '',
|
||||
stdout: new RegExp(RegExp.escape(report)),
|
||||
});
|
||||
|
||||
assert.strictEqual(result.stderr.toString(), '');
|
||||
assert(result.stdout.toString().includes(report));
|
||||
assert.strictEqual(result.status, 0);
|
||||
});
|
||||
|
||||
it('should exclude test files from coverage by default', async () => {
|
||||
@@ -74,14 +73,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
|
||||
'--experimental-test-coverage',
|
||||
'--test-reporter=tap',
|
||||
];
|
||||
const result = spawnSync(process.execPath, args, {
|
||||
spawnSyncAndAssert(process.execPath, args, {
|
||||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
|
||||
cwd: tmpdir.path
|
||||
}, {
|
||||
stderr: '',
|
||||
stdout: assertDefaultExclusions,
|
||||
});
|
||||
|
||||
assert.strictEqual(result.stderr.toString(), '');
|
||||
assertDefaultExclusions(result.stdout.toString());
|
||||
assert.strictEqual(result.status, 0);
|
||||
});
|
||||
|
||||
it('should exclude ts test files', async () => {
|
||||
@@ -91,14 +89,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
|
||||
'--disable-warning=ExperimentalWarning',
|
||||
'--test-reporter=tap',
|
||||
];
|
||||
const result = spawnSync(process.execPath, args, {
|
||||
spawnSyncAndAssert(process.execPath, args, {
|
||||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
|
||||
cwd: tmpdir.path
|
||||
}, {
|
||||
stderr: '',
|
||||
stdout: assertDefaultExclusions,
|
||||
});
|
||||
|
||||
assert.strictEqual(result.stderr.toString(), '');
|
||||
assertDefaultExclusions(result.stdout.toString());
|
||||
assert.strictEqual(result.status, 0);
|
||||
});
|
||||
|
||||
it('should exclude dotfile test files from coverage by default', async () => {
|
||||
@@ -109,14 +106,15 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => {
|
||||
'--test-reporter=tap',
|
||||
'test/.dotfile.cjs',
|
||||
];
|
||||
const result = spawnSync(process.execPath, args, {
|
||||
spawnSyncAndAssert(process.execPath, args, {
|
||||
env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path },
|
||||
cwd: tmpdir.path
|
||||
}, {
|
||||
stderr: '',
|
||||
stdout(output) {
|
||||
assertDefaultExclusions(output);
|
||||
assert.doesNotMatch(output, /#\s+\.dotfile\.cjs\s+\|/);
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(result.stderr.toString(), '');
|
||||
assertDefaultExclusions(result.stdout.toString());
|
||||
assert.doesNotMatch(result.stdout.toString(), /#\s+\.dotfile\.cjs\s+\|/);
|
||||
assert.strictEqual(result.status, 0);
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@
|
||||
const common = require('../common');
|
||||
const assert = require('node:assert');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { spawnSyncAndExit } = require('../common/child_process');
|
||||
const { readdirSync } = require('node:fs');
|
||||
const { test } = require('node:test');
|
||||
const fixtures = require('../common/fixtures');
|
||||
@@ -172,23 +173,24 @@ for (const coverage of coverages) {
|
||||
});
|
||||
|
||||
test(`test failing ${coverage.flag} with dot reporter`, () => {
|
||||
const result = spawnSync(process.execPath, [
|
||||
const { child } = spawnSyncAndExit(process.execPath, [
|
||||
'--test',
|
||||
'--experimental-test-coverage',
|
||||
'--test-coverage-exclude=!test/**',
|
||||
`${coverage.flag}=99`,
|
||||
'--test-reporter', 'dot',
|
||||
fixture,
|
||||
]);
|
||||
|
||||
const stdout = result.stdout.toString();
|
||||
assert.match(
|
||||
stdout,
|
||||
RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`)
|
||||
);
|
||||
assert.match(stdout, /start of coverage report/);
|
||||
assert.match(stdout, /end of coverage report/);
|
||||
assert.strictEqual(result.status, 1);
|
||||
assert(!findCoverageFileForPid(result.pid));
|
||||
], {
|
||||
status: 1,
|
||||
stdout(output) {
|
||||
assert.match(
|
||||
output,
|
||||
RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`)
|
||||
);
|
||||
assert.match(output, /start of coverage report/);
|
||||
assert.match(output, /end of coverage report/);
|
||||
},
|
||||
});
|
||||
assert(!findCoverageFileForPid(child.pid));
|
||||
});
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
|
||||
|
||||
function isOnlcrEnabled() {
|
||||
const { stdout, stderr, status } = spawnSync('stty', ['-a'], {
|
||||
const { child: { stdout } } = spawnSyncAndExitWithoutError('stty', ['-a'], {
|
||||
encoding: 'utf8',
|
||||
stdio: ['inherit', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
assert.strictEqual(status, 0, stderr);
|
||||
return /(?:^|[\s;])onlcr(?:[\s;]|$)/.test(stdout);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user