GeezerVison is showing github.com — test: use common spawnSync helpers in more tests · nodejs/node@b7bca07
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| 3 | 3 | require('../common'); | 4 | | -const assert = require('node:assert/strict'); | 5 | | -const childProcess = require('node:child_process'); | | 4 | +const { spawnSyncAndExit } = require('../common/child_process'); | 6 | 5 | const fixtures = require('../common/fixtures'); | 7 | 6 |
| 8 | | -const child = childProcess.spawnSync( | | 7 | +const { child } = spawnSyncAndExit( | 9 | 8 | process.execPath, | 10 | 9 | [ '--no-warnings', '--run'], | 11 | 10 | { cwd: fixtures.path('run-script'), encoding: 'utf8' }, | | 11 | + { status: 9, signal: null }, | 12 | 12 | ); | 13 | | -assert.strictEqual(child.status, 9); | 14 | 13 | console.log(child.stderr); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-glob.mjs +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import * as common from '../common/index.mjs'; | 2 | 2 | import tmpdir from '../common/tmpdir.js'; | 3 | | -import { spawnSync } from 'node:child_process'; | | 3 | +import { spawnSyncAndExitWithoutError } from '../common/child_process.js'; | 4 | 4 | import { resolve, dirname, sep, relative, join, isAbsolute } from 'node:path'; | 5 | 5 | import { mkdir, writeFile, symlink, glob as asyncGlob } from 'node:fs/promises'; | 6 | 6 | import { glob, globSync, Dirent, chmodSync, writeFileSync, rmSync } from 'node:fs'; | @@ -722,12 +722,11 @@ describe('glob - seen cache', function() { | 722 | 722 | `; | 723 | 723 |
| 724 | 724 | const seenDir = tmpdir.resolve('glob-seen'); | 725 | | - const child = spawnSync( | | 725 | + spawnSyncAndExitWithoutError( | 726 | 726 | process.execPath, | 727 | 727 | ['--expose-internals', '-e', script, seenDir], | 728 | 728 | { encoding: 'utf8' }, | 729 | 729 | ); | 730 | | - assert.strictEqual(child.status, 0, child.stderr || child.stdout); | 731 | 730 | }); | 732 | 731 | }); | 733 | 732 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-module-unreadable-package-json.js +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,6 +18,7 @@ const assert = require('assert'); | 18 | 18 | const fs = require('fs'); | 19 | 19 | const path = require('path'); | 20 | 20 | const { spawnSync } = require('child_process'); | | 21 | +const { spawnSyncAndAssert } = require('../common/child_process'); | 21 | 22 | const tmpdir = require('../common/tmpdir'); | 22 | 23 |
| 23 | 24 | tmpdir.refresh(); | @@ -38,11 +39,10 @@ const entry = tmpdir.resolve('main.mjs'); | 38 | 39 | fs.writeFileSync(entry, 'import { which } from "dep"; console.log(which);'); | 39 | 40 |
| 40 | 41 | // Sanity check: the export resolves while the package config is readable. | 41 | | -{ | 42 | | - const child = spawnSync(process.execPath, [entry], { encoding: 'utf8' }); | 43 | | - assert.strictEqual(child.stdout.trim(), 'real'); | 44 | | - assert.strictEqual(child.status, 0, child.stderr); | 45 | | -} | | 42 | +spawnSyncAndAssert(process.execPath, [entry], { encoding: 'utf8' }, { | | 43 | + stdout: 'real', | | 44 | + trim: true, | | 45 | +}); | 46 | 46 |
| 47 | 47 | fs.chmodSync(depPackageJson, 0o000); | 48 | 48 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage-default-exclusion.mjs +20-22Lines changed: 20 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import '../common/index.mjs'; | 2 | 2 | import { before, describe, it } from 'node:test'; | 3 | 3 | import assert from 'node:assert'; | 4 | | -import { spawnSync } from 'node:child_process'; | 5 | 4 | import { cp } from 'node:fs/promises'; | 6 | 5 | import tmpdir from '../common/tmpdir.js'; | 7 | 6 | import fixtures from '../common/fixtures.js'; | | 7 | +import { spawnSyncAndAssert } from '../common/child_process.js'; | 8 | 8 | const skipIfNoInspector = { | 9 | 9 | skip: !process.features.inspector ? 'inspector disabled' : false | 10 | 10 | }; | @@ -57,14 +57,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => { | 57 | 57 | '--test-reporter=tap', | 58 | 58 | '--no-experimental-strip-types', | 59 | 59 | ]; | 60 | | - const result = spawnSync(process.execPath, args, { | | 60 | + spawnSyncAndAssert(process.execPath, args, { | 61 | 61 | env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | 62 | 62 | cwd: tmpdir.path | | 63 | + }, { | | 64 | + stderr: '', | | 65 | + stdout: new RegExp(RegExp.escape(report)), | 63 | 66 | }); | 64 | | - | 65 | | - assert.strictEqual(result.stderr.toString(), ''); | 66 | | - assert(result.stdout.toString().includes(report)); | 67 | | - assert.strictEqual(result.status, 0); | 68 | 67 | }); | 69 | 68 |
| 70 | 69 | it('should exclude test files from coverage by default', async () => { | @@ -74,14 +73,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => { | 74 | 73 | '--experimental-test-coverage', | 75 | 74 | '--test-reporter=tap', | 76 | 75 | ]; | 77 | | - const result = spawnSync(process.execPath, args, { | | 76 | + spawnSyncAndAssert(process.execPath, args, { | 78 | 77 | env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | 79 | 78 | cwd: tmpdir.path | | 79 | + }, { | | 80 | + stderr: '', | | 81 | + stdout: assertDefaultExclusions, | 80 | 82 | }); | 81 | | - | 82 | | - assert.strictEqual(result.stderr.toString(), ''); | 83 | | - assertDefaultExclusions(result.stdout.toString()); | 84 | | - assert.strictEqual(result.status, 0); | 85 | 83 | }); | 86 | 84 |
| 87 | 85 | it('should exclude ts test files', async () => { | @@ -91,14 +89,13 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => { | 91 | 89 | '--disable-warning=ExperimentalWarning', | 92 | 90 | '--test-reporter=tap', | 93 | 91 | ]; | 94 | | - const result = spawnSync(process.execPath, args, { | | 92 | + spawnSyncAndAssert(process.execPath, args, { | 95 | 93 | env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | 96 | 94 | cwd: tmpdir.path | | 95 | + }, { | | 96 | + stderr: '', | | 97 | + stdout: assertDefaultExclusions, | 97 | 98 | }); | 98 | | - | 99 | | - assert.strictEqual(result.stderr.toString(), ''); | 100 | | - assertDefaultExclusions(result.stdout.toString()); | 101 | | - assert.strictEqual(result.status, 0); | 102 | 99 | }); | 103 | 100 |
| 104 | 101 | it('should exclude dotfile test files from coverage by default', async () => { | @@ -109,14 +106,15 @@ describe('test runner coverage default exclusion', skipIfNoInspector, () => { | 109 | 106 | '--test-reporter=tap', | 110 | 107 | 'test/.dotfile.cjs', | 111 | 108 | ]; | 112 | | - const result = spawnSync(process.execPath, args, { | | 109 | + spawnSyncAndAssert(process.execPath, args, { | 113 | 110 | env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path }, | 114 | 111 | cwd: tmpdir.path | | 112 | + }, { | | 113 | + stderr: '', | | 114 | + stdout(output) { | | 115 | + assertDefaultExclusions(output); | | 116 | + assert.doesNotMatch(output, /#\s+\.dotfile\.cjs\s+\|/); | | 117 | + }, | 115 | 118 | }); | 116 | | - | 117 | | - assert.strictEqual(result.stderr.toString(), ''); | 118 | | - assertDefaultExclusions(result.stdout.toString()); | 119 | | - assert.doesNotMatch(result.stdout.toString(), /#\s+\.dotfile\.cjs\s+\|/); | 120 | | - assert.strictEqual(result.status, 0); | 121 | 119 | }); | 122 | 120 | }); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-coverage-thresholds.js +14-12Lines changed: 14 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | const common = require('../common'); | 3 | 3 | const assert = require('node:assert'); | 4 | 4 | const { spawnSync } = require('node:child_process'); | | 5 | +const { spawnSyncAndExit } = require('../common/child_process'); | 5 | 6 | const { readdirSync } = require('node:fs'); | 6 | 7 | const { test } = require('node:test'); | 7 | 8 | const fixtures = require('../common/fixtures'); | @@ -172,23 +173,24 @@ for (const coverage of coverages) { | 172 | 173 | }); | 173 | 174 |
| 174 | 175 | test(`test failing ${coverage.flag} with dot reporter`, () => { | 175 | | - const result = spawnSync(process.execPath, [ | | 176 | + const { child } = spawnSyncAndExit(process.execPath, [ | 176 | 177 | '--test', | 177 | 178 | '--experimental-test-coverage', | 178 | 179 | '--test-coverage-exclude=!test/**', | 179 | 180 | `${coverage.flag}=99`, | 180 | 181 | '--test-reporter', 'dot', | 181 | 182 | fixture, | 182 | | - ]); | 183 | | - | 184 | | - const stdout = result.stdout.toString(); | 185 | | - assert.match( | 186 | | - stdout, | 187 | | - RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`) | 188 | | - ); | 189 | | - assert.match(stdout, /start of coverage report/); | 190 | | - assert.match(stdout, /end of coverage report/); | 191 | | - assert.strictEqual(result.status, 1); | 192 | | - assert(!findCoverageFileForPid(result.pid)); | | 183 | + ], { | | 184 | + status: 1, | | 185 | + stdout(output) { | | 186 | + assert.match( | | 187 | + output, | | 188 | + RegExp(`Error: ${coverage.actual.toFixed(2)}% ${coverage.name} coverage does not meet threshold of 99%`) | | 189 | + ); | | 190 | + assert.match(output, /start of coverage report/); | | 191 | + assert.match(output, /end of coverage report/); | | 192 | + }, | | 193 | + }); | | 194 | + assert(!findCoverageFileForPid(child.pid)); | 193 | 195 | }); | 194 | 196 | } |
Collapse file Copy file name to clipboardExpand all lines: test/pseudo-tty/test-set-raw-mode-modes.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 | require('../common'); | 3 | 3 | const assert = require('assert'); | 4 | | -const { spawnSync } = require('child_process'); | | 4 | +const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | 5 | 5 |
| 6 | 6 | function isOnlcrEnabled() { | 7 | | - const { stdout, stderr, status } = spawnSync('stty', ['-a'], { | | 7 | + const { child: { stdout } } = spawnSyncAndExitWithoutError('stty', ['-a'], { | 8 | 8 | encoding: 'utf8', | 9 | 9 | stdio: ['inherit', 'pipe', 'pipe'], | 10 | 10 | }); | 11 | 11 |
| 12 | | - assert.strictEqual(status, 0, stderr); | 13 | 12 | return /(?:^|[\s;])onlcr(?:[\s;]|$)/.test(stdout); | 14 | 13 | } | 15 | 14 |
| |
|