console-fail-test
Version:
Gently fails test runs if the console was used during them. 📢
39 lines • 1.24 kB
JavaScript
const isMocha = () => {
return typeof afterEach !== "undefined" && typeof beforeEach !== "undefined" && `${afterEach}`.replace(/\s/g, "") === "function(name,fn){suites[0].afterEach(name,fn);}" && `${beforeEach}`.replace(/\s/g, "") === "function(name,fn){suites[0].beforeEach(name,fn);}";
};
const selectMochaEnvironment = () => {
if (!isMocha()) {
return void 0;
}
return {
afterEach: (callback) => {
afterEach(function() {
if (this.currentTest.state !== "passed") {
return;
}
callback({
reportComplaint: ({ error }) => {
error.message = error.message.replace(/\n/g, "\n ");
this.test.error(error);
}
});
});
},
beforeEach,
mapSpyCalls: ({ methodCalls, methodName }) => {
if (methodCalls.length === 0 || methodName !== "log") {
return methodCalls;
}
const lastCall = methodCalls[methodCalls.length - 1];
const first = lastCall[0];
if (typeof first === "string" && first.startsWith(" ")) {
methodCalls = methodCalls.slice(0, methodCalls.length - 1);
}
return methodCalls;
}
};
};
export {
selectMochaEnvironment
};
//# sourceMappingURL=mocha.js.map