diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-06-11 12:41:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-11 11:41:44 +0000 |
commit | 6a356aff1380e79d67738c5b43aa2b5fee76600d (patch) | |
tree | be4aadc62a523ff280820958a1a3829f1a18ca7d /tests/node_compat/test/common/index.js | |
parent | 3d41b486da7dcba49c8a18b45425e356c329d986 (diff) |
chore: sync up Node.js test files for v20.11.1 (#24066)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Diffstat (limited to 'tests/node_compat/test/common/index.js')
-rw-r--r-- | tests/node_compat/test/common/index.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/node_compat/test/common/index.js b/tests/node_compat/test/common/index.js index 9f5b4814c..2ebb22da2 100644 --- a/tests/node_compat/test/common/index.js +++ b/tests/node_compat/test/common/index.js @@ -11,10 +11,12 @@ */ 'use strict'; const assert = require("assert"); +const { spawn } = require('child_process'); const path = require("path"); const util = require("util"); const tmpdir = require("./tmpdir"); + function platformTimeout(ms) { return ms; } @@ -442,6 +444,36 @@ const pwdCommand = isWindows ? ['cmd.exe', ['/d', '/c', 'cd']] : ['pwd', []]; + function spawnPromisified(...args) { + let stderr = ''; + let stdout = ''; + + const child = spawn(...args); + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { stderr += data; }); + child.stdout.setEncoding('utf8'); + child.stdout.on('data', (data) => { stdout += data; }); + + return new Promise((resolve, reject) => { + child.on('close', (code, signal) => { + resolve({ + code, + signal, + stderr, + stdout, + }); + }); + child.on('error', (code, signal) => { + reject({ + code, + signal, + stderr, + stdout, + }); + }); + }); + } + module.exports = { allowGlobals, expectsError, @@ -464,6 +496,7 @@ module.exports = { printSkipMessage, pwdCommand, skipIfDumbTerminal, + spawnPromisified, isDumbTerminal, isWindows, isAIX, |