Skip to content

Commit

Permalink
refactor: tests; error instance checking
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburnell committed Aug 10, 2024
1 parent 18ac3c0 commit 6505424
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 141 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm ci
- run: node --test
- if: ${{ github.event.release.tag_name != '' && env.NPM_PUBLISH_TAG != '' }}
run: npm publish --provenance --access=public --tag=${{ env.NPM_PUBLISH_TAG }}
env:
Expand Down
51 changes: 0 additions & 51 deletions .gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
.prettierrc
.prettierignore
test
test.js
check-invalid-datetimes.test.js
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"tabWidth": 4
"tabWidth": 4,
"trailingComma": "all"
}
File renamed without changes.
73 changes: 73 additions & 0 deletions check-invalid-datetimes.test.js
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, "");
});
});
Loading

0 comments on commit 6505424

Please # to comment.