From 26592b9c8d76ac141138d86ed929905adacd530b Mon Sep 17 00:00:00 2001 From: Mary Marchini Date: Fri, 14 Jul 2023 21:27:06 -0700 Subject: [PATCH] chore(test): improve log output on error --- test/common.js | 7 +++++++ test/test-executables.js | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/common.js b/test/common.js index 563c344..0666f65 100644 --- a/test/common.js +++ b/test/common.js @@ -64,8 +64,15 @@ function startFixtureProcess(t, withInspector = false, port = '0') { execArgv.push('--inspect'); } const child = fork('./test/fixtures/default-program.js', { execArgv, silent: true}); + let output = ''; + child.stdout.setEncoding('utf-8'); + child.stdout.on('data', (data) => output += `[${ child.pid }][stdout] ${ data }`); + child.stderr.setEncoding('utf-8'); + child.stderr.on('data', (data) => output += `[${ child.pid }][stderr] ${ data }`); const fixture = new FixtureProcess(child); fixture.on('timeout', t.fail); + t.once('result', ({ ok }) => { if (!ok) { console.log(output) } }); + t.teardown(() => fixture.send('exit')); return fixture; } diff --git a/test/test-executables.js b/test/test-executables.js index b2fa8d7..d115b6d 100644 --- a/test/test-executables.js +++ b/test/test-executables.js @@ -19,7 +19,6 @@ test('observe heap-profile', async (t) => { t.notEqual(head, undefined); const { callFrame } = head; t.notEqual(callFrame, undefined); - f.send('exit'); t.end(); }); }); @@ -33,7 +32,6 @@ test('observe heap-profile to file', async (t) => { t.notEqual(head, undefined); const { callFrame } = head; t.notEqual(callFrame, undefined); - f.send('exit'); t.end(); }); }); @@ -49,7 +47,6 @@ test('observe heap-snapshot', async (t) => { t.notEqual(nodes, undefined); t.notEqual(edges, undefined); t.notEqual(strings, undefined); - f.send('exit'); t.end(); }); }); @@ -65,7 +62,6 @@ test('observe heap-snapshot to file', async (t) => { t.notEqual(nodes, undefined); t.notEqual(edges, undefined); t.notEqual(strings, undefined); - f.send('exit'); t.end(); }); }); @@ -77,7 +73,6 @@ test('observe cpu-profile', async (t) => { const options = { pid: f.pid, port, options: ['-d', 1]}; const result = await runObserveExecutable('cpu-profile', options); t.ok(validateCpuProfile(result)); - f.send('exit'); t.end(); }); }); @@ -89,7 +84,6 @@ test('observe cpu-profile to file', async (t) => { const options = { pid: f.pid, port, toFile: true, options: ['-d', 1]}; const result = await runObserveExecutable('cpu-profile', options); t.ok(validateCpuProfile(result)); - f.send('exit'); t.end(); }); }); @@ -103,7 +97,6 @@ test('observe --close', async (t) => { setTimeout(async () => { t.notOk(await isPortInUse(port)); t.ok(validateCpuProfile(result)); - f.send('exit'); t.end(); }, 500); });