Skip to content

Commit

Permalink
Improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed Jun 5, 2024
1 parent 83b2697 commit 4ffe596
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand Down

0 comments on commit 4ffe596

Please sign in to comment.