-
-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to #562. One error at a time, better output, tests aroun…
…d EleventyErrorHandler.
- Loading branch information
Showing
3 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 doesn’t work with the static methods in | ||
// EleventyErrorHandler | ||
output = []; | ||
|
||
EleventyErrorHandler.error(new Error("Test error"), "It’s me"); | ||
|
||
expected = `It’s me: (more in DEBUG output) | ||
> Test error | ||
\`Error\` was thrown: | ||
Error: Test error`; | ||
t.is(output.join("\n").substr(0, expected.length), expected); | ||
}); |