-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tests; error instance checking
- Loading branch information
1 parent
18ac3c0
commit 6505424
Showing
13 changed files
with
461 additions
and
141 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
.prettierrc | ||
.prettierignore | ||
test | ||
test.js | ||
check-invalid-datetimes.test.js |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"tabWidth": 4 | ||
"tabWidth": 4, | ||
"trailingComma": "all" | ||
} |
File renamed without changes.
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,73 @@ | ||
import assert from "node:assert/strict"; | ||
import { describe, it } from "node:test"; | ||
import { checkInvalidDateTimes } from "./src/checkInvalidDateTimes.js"; | ||
|
||
const options = { | ||
directory: "test", | ||
quiet: true, | ||
}; | ||
|
||
const getErrorInstances = (errors) => { | ||
return errors.flatMap((object) => { | ||
return object.instances; | ||
}); | ||
}; | ||
|
||
describe("check-invalid-datetimes", () => { | ||
it("Should return an array of errors", async () => { | ||
const cli = new checkInvalidDateTimes(); | ||
cli.setOptions(options); | ||
const result = await cli.run(); | ||
|
||
const errorInstances = getErrorInstances(result.errors); | ||
|
||
assert.strictEqual(errorInstances.length, 5); | ||
}); | ||
|
||
it("Should be able to check only specified file types", async () => { | ||
const cli = new checkInvalidDateTimes(); | ||
cli.setOptions(Object.assign({}, options, { fileTypes: "html" })); | ||
const result = await cli.run(); | ||
|
||
const errorInstances = getErrorInstances(result.errors); | ||
|
||
assert.strictEqual(errorInstances.length, 2); | ||
}); | ||
|
||
it("Should return the location of found errors", async () => { | ||
const cli = new checkInvalidDateTimes(); | ||
cli.setOptions(Object.assign({}, options, { fileTypes: "xml" })); | ||
const result = await cli.run(); | ||
|
||
const errorInstances = getErrorInstances(result.errors); | ||
|
||
assert.strictEqual(errorInstances[0].lineNumber, 6); | ||
assert.strictEqual(errorInstances[0].columnNumber, 11); | ||
assert.strictEqual( | ||
errorInstances[0].string, | ||
"<updated>Invalid DateTime</updated>", | ||
); | ||
|
||
assert.strictEqual(errorInstances[1].lineNumber, 12); | ||
assert.strictEqual(errorInstances[1].columnNumber, 12); | ||
assert.strictEqual( | ||
errorInstances[1].string, | ||
"<updated>Invalid DateTime</updated>", | ||
); | ||
|
||
assert.strictEqual(errorInstances[2].lineNumber, 13); | ||
assert.strictEqual(errorInstances[2].columnNumber, 14); | ||
assert.strictEqual( | ||
errorInstances[2].string, | ||
"<published>Invalid DateTime</published>", | ||
); | ||
}); | ||
|
||
it("Should return a message summarising the result", async () => { | ||
const cli = new checkInvalidDateTimes(); | ||
cli.setOptions(Object.assign({}, options, { fileTypes: "xml" })); | ||
const result = await cli.run(); | ||
|
||
assert.notStrictEqual(result.message, ""); | ||
}); | ||
}); |
Oops, something went wrong.