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

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-02 12:22:45 +00:00
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);
});