Skip to content

Commit

Permalink
Improve error reporting (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored Jun 11, 2024
1 parent aaa05a2 commit 64ce4c5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand Down

0 comments on commit 64ce4c5

Please sign in to comment.