From 64ce4c5c293212c63f9dc4225ecaaff8bf093da9 Mon Sep 17 00:00:00 2001 From: jugglinmike Date: Mon, 10 Jun 2024 21:43:24 -0400 Subject: [PATCH] Improve error reporting (#56) --- test/test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 9c1d7d0..03c906e 100644 --- a/test/test.js +++ b/test/test.js @@ -20,17 +20,35 @@ const invert = promise => () => {}, ); +/** + * Format a string as a Markdown quote by prefixing every line with `> `. + * + * @param {string} stderr + * + * @returns {string} + */ +const quote = stderr => + stderr + .trim() + .split('\n') + .map(line => `> ${line}`) + .join('\n'); + suite('at-driver', () => { const children = []; const run = args => { const child = child_process.spawn(process.execPath, [executable, ...args]); + let stderr = ''; children.push(child); const whenClosed = new Promise((resolve, reject) => { child.on('error', reject); - child.on('close', () => reject(new Error('Server closed unexpectedly'))); + child.on('close', () => reject(new Error(`Server closed unexpectedly\n\n${quote(stderr)}`))); }); return new Promise((resolve, reject) => { - child.stderr.on('data', () => resolve({ whenClosed })); + child.stderr.on('data', chunk => { + stderr += chunk; + resolve({ whenClosed }); + }); whenClosed.catch(reject); }); };