Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
OnkarRuikar committed Feb 8, 2023
1 parent e4d7b45 commit 0ee9da7
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions testing/tests/filecheck.test.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,67 @@
import fs from "node:fs";
import { fileURLToPath } from "node:url";

import { checkFile, runChecker } from "../../filecheck/checker.js";
import { checkBinaryFile, runChecker } from "../../filecheck/checker.js";

const SAMPLES_DIRECTORY = new URL(
"filechecker/samplefiles-html/",
import.meta.url
);
const SAMPLES_DIRECTORY = new URL("filechecker/files/en-us/", import.meta.url);

function getFilePath(...paths) {
const filePath = fileURLToPath(new URL(...paths, SAMPLES_DIRECTORY));
function getFilePath(path) {
const filePath = fileURLToPath(new URL(path, SAMPLES_DIRECTORY));
// Sanity check the test itself
console.assert(fs.existsSync(filePath), `${filePath} does not exist`);
return filePath;
}

describe("checking files", () => {
it("should spot SVGs with scripts inside them", async () => {
const filePath = getFilePath("samplefiles-html", "script.svg");
const filePath = getFilePath("samplefiles-html/script.svg");
await expect(checkBinaryFile(filePath)).rejects.toThrow(
/ does not appear to be an SVG$/
);
});

it("should spot SVGs with onLoad inside an element", async () => {
const filePath = getFilePath("samplefiles-html", "onhandler.svg");
const filePath = getFilePath("samplefiles-html/onhandler.svg");
await expect(checkBinaryFile(filePath)).rejects.toThrow(
/ does not appear to be an SVG$/
);
});

it("should spot files that are not mentioned in source", async () => {
const filePath = getFilePath("samplefiles-html", "orphan.png");
const filePath = getFilePath("samplefiles-html/orphan.png");
await expect(checkBinaryFile(filePath)).rejects.toThrow(
"is not mentioned in"
);
});

it("should spot files that are not mentioned in md source", async () => {
const filePath = getFilePath("samplefiles-md", "orphan.png");
const filePath = getFilePath("samplefiles-md/orphan.png");
await expect(checkBinaryFile(filePath)).rejects.toThrow(
"is not mentioned in"
);
});

it("should spot files that are completely empty", async () => {
const filePath = getFilePath("samplefiles-html", "zero.gif");
const filePath = getFilePath("samplefiles-html/zero.gif");
await expect(checkBinaryFile(filePath)).rejects.toThrow("is 0 bytes");
});

it("should spot mismatch between file-type and file extension", async () => {
const filePath = getFilePath("samplefiles-html", "png.jpeg");
const filePath = getFilePath("samplefiles-html/png.jpeg");
await expect(checkBinaryFile(filePath)).rejects.toThrow(
"of type 'image/png' should have extension 'png', but has extension '.jpeg'"
);
});

it("should spot files with uppercase file names", async () => {
const filePath = getFilePath("samplefiles-upperCase", "index.md");
const filePath = getFilePath("samplefiles-upperCase/index.md");
await expect(runChecker([filePath], {})).rejects.toThrow(
"Error: Invalid path: samplefiles-upperCase/index.md. All characters must be lowercase."
);
});

it("should spot files with parenthese in file names", async () => {
const filePath = getFilePath("samplefiles-paren(theses)", "index.md");
const filePath = getFilePath("samplefiles-paren(theses)/index.md");
await expect(runChecker([filePath], {})).rejects.toThrow(
"Error: Invalid path: samplefiles-paren(theses)/index.md. File path must not include characters: '(', ')'"
);
Expand Down

0 comments on commit 0ee9da7

Please sign in to comment.