From 4ffe5961d48bd06a38e28078405e743a2d9104cd Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Wed, 5 Jun 2024 18:21:12 -0400 Subject: [PATCH] Improve error reporting --- test/test.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index 182656f..1788849 100644 --- a/test/test.js +++ b/test/test.js @@ -20,17 +20,33 @@ 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); }); };