2016-10-15 04:33:27 +08:00
|
|
|
const originalLog = console.log;
|
|
|
|
const originalWarn = console.warn;
|
|
|
|
const originalError = console.error;
|
|
|
|
|
|
|
|
export default class ConsoleReporter {
|
|
|
|
reportSpecStarting(spec) {
|
|
|
|
const withContext = (log) => {
|
|
|
|
return (...args) => {
|
|
|
|
if (args[0] === '.') {
|
|
|
|
return log(...args);
|
|
|
|
}
|
2016-11-03 03:39:37 +08:00
|
|
|
return log(`[${spec.getFullName()}] ${args[0]}`, ...args.slice(1));
|
2016-10-15 04:33:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log = withContext(originalLog);
|
|
|
|
console.warn = withContext(originalWarn);
|
|
|
|
console.error = withContext(originalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
reportSpecResults() {
|
|
|
|
if (console.log !== originalLog) {
|
|
|
|
console.log = originalLog;
|
|
|
|
}
|
|
|
|
if (console.warn !== originalWarn) {
|
|
|
|
console.warn = originalWarn;
|
|
|
|
}
|
|
|
|
if (console.error !== originalError) {
|
|
|
|
console.error = originalError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|