UNPKG

console-fail-test

Version:

Gently fails test runs if the console was used during them. 📢

41 lines • 1.35 kB
import { formatComplaintCall } from "../complaining/index.js"; const isNodeTap = (testFramework) => { return typeof testFramework !== "undefined" && typeof testFramework.afterEach === "function" && typeof testFramework.beforeEach === "function" && typeof testFramework.fail === "function" && typeof testFramework.jobs === "number" && typeof testFramework.pool === "object" && testFramework.name === "TAP"; }; const selectNodeTapEnvironment = ({ testFramework }) => { if (!isNodeTap(testFramework)) { return void 0; } return { afterEach: (callback) => { testFramework.afterEach((onFinishAfterEach) => { callback({ reportComplaint({ methodComplaints }) { for (const { methodCalls, methodName } of methodComplaints) { for (const methodCall of methodCalls) { testFramework.fail( `console.${methodName} was called with: ${formatComplaintCall( methodCall )}` ); } } } }); onFinishAfterEach(); }); }, beforeEach: (callback) => { testFramework.beforeEach((onFinishBeforeEach) => { callback(); onFinishBeforeEach(); }); } }; }; export { selectNodeTapEnvironment }; //# sourceMappingURL=nodeTap.js.map