Only output on failing tests
This commit is contained in:
parent
66be268a09
commit
02776246bf
3 changed files with 48 additions and 35 deletions
37
lib/testing-utils.js
generated
37
lib/testing-utils.js
generated
|
|
@ -1,27 +1,30 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function wrapOutput(context) {
|
||||
return (str) => {
|
||||
if (typeof str === 'string') {
|
||||
context.testOutput += str;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
function silenceDebugOutput(test) {
|
||||
const typedTest = test;
|
||||
typedTest.beforeEach(t => {
|
||||
t.context.testOutput = "";
|
||||
const processStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
t.context.write = processStdoutWrite;
|
||||
process.stdout.write = (str, encoding, cb) => {
|
||||
// Core library will directly call process.stdout.write for commands
|
||||
// We don't want debug output to be included in tests
|
||||
if (typeof str === "string") {
|
||||
str = str.replace(/::(info|debug|warning).*/, '');
|
||||
if (str.trim() !== "") {
|
||||
processStdoutWrite(str, encoding, cb);
|
||||
}
|
||||
}
|
||||
else {
|
||||
processStdoutWrite(str, encoding, cb);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
t.context.stdoutWrite = processStdoutWrite;
|
||||
process.stdout.write = wrapOutput(t.context);
|
||||
const processStderrWrite = process.stderr.write.bind(process.stderr);
|
||||
t.context.stderrWrite = processStderrWrite;
|
||||
process.stderr.write = wrapOutput(t.context);
|
||||
});
|
||||
typedTest.afterEach(t => {
|
||||
process.stdout.write = t.context.write;
|
||||
typedTest.afterEach.always(t => {
|
||||
process.stdout.write = t.context.stdoutWrite;
|
||||
process.stderr.write = t.context.stderrWrite;
|
||||
if (!t.passed) {
|
||||
process.stdout.write(t.context.testOutput);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.silenceDebugOutput = silenceDebugOutput;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue