work.suroh.tk/node_modules/@11ty/eleventy/test/EleventyErrorHandlerTest.js

57 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from "ava";
import EleventyErrorHandler from "../src/EleventyErrorHandler";
let output = [];
test.beforeEach(t => {
output = [];
EleventyErrorHandler.isChalkEnabled = false;
EleventyErrorHandler.logger = {
log: function(str) {
output.push(str);
},
warn: function(str) {
output.push(str);
},
error: function(str) {
output.push(str);
}
};
});
test.afterEach(t => {
EleventyErrorHandler.isChalkEnabled = true;
EleventyErrorHandler.logger = null;
});
test("Disable chalk", t => {
EleventyErrorHandler.isChalkEnabled = false;
t.is(EleventyErrorHandler.isChalkEnabled, false);
});
test("Log a warning, error", t => {
EleventyErrorHandler.warn(new Error("Test warning"), "Hello");
let expected = `Hello: (more in DEBUG output)
> Test warning
\`Error\` was thrown:
Error: Test warning`;
t.is(output.join("\n").substr(0, expected.length), expected);
// normally this would be multiple tests but we do this garbage because
// tests run async and it doesnt work with the static methods in
// EleventyErrorHandler
output = [];
EleventyErrorHandler.error(new Error("Test error"), "Its me");
expected = `Its me: (more in DEBUG output)
> Test error
\`Error\` was thrown:
Error: Test error`;
t.is(output.join("\n").substr(0, expected.length), expected);
});