Page MenuHomePhorge

test_child_process_execfile_promisify.cjs
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

test_child_process_execfile_promisify.cjs

const { promisify } = require('util');
const { execFile } = require('child_process');
const path = require('path');
async function main() {
if (typeof promisify.custom !== 'symbol') {
throw new Error('expected util.promisify.custom to be a symbol');
}
if (typeof execFile[promisify.custom] !== 'function') {
throw new Error('expected execFile to define util.promisify.custom');
}
const execFileAsync = promisify(execFile);
const child = path.join(__dirname, 'fixtures', 'execfile_promisify_child.cjs');
const result = await execFileAsync(process.execPath, [child]);
if (!result || typeof result !== 'object' || Array.isArray(result)) {
throw new Error(`expected object result, got ${Object.prototype.toString.call(result)}`);
}
if (result.stdout !== 'OUT') {
throw new Error(`expected stdout to be OUT, got ${JSON.stringify(result.stdout)}`);
}
if (result.stderr !== 'ERR') {
throw new Error(`expected stderr to be ERR, got ${JSON.stringify(result.stderr)}`);
}
console.log('util.promisify(execFile) resolves { stdout, stderr }');
}
main().catch((err) => {
console.error(err && err.stack ? err.stack : String(err));
process.exit(1);
});

File Metadata

Mime Type
application/javascript
Expires
Fri, May 1, 11:43 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
542976
Default Alt Text
test_child_process_execfile_promisify.cjs (1 KB)

Event Timeline