Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 55 additions & 60 deletions test/utils/display-reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,67 +26,62 @@ afterEach(() => {
vi.clearAllMocks();
});

describe.each(times)("at $expectedTime (timestamp $mockedTimestamp)", ({
mockedTimestamp,
expectedTime
}) => {
it.each(mockedValidResultReporting)("should display a success reporting", ({
language,
reporting,
url,
logs
}) => {
displayReporting(reporting, mockedTimestamp);
expect(consoleGroupSpy).toHaveBeenCalledWith(
`[${expectedTime}]`,
workspaceName,
`[${language.toUpperCase()}]`,
url
describe.each(times)(
"at $expectedTime (timestamp $mockedTimestamp)",
({ mockedTimestamp, expectedTime }) => {
it.each(mockedValidResultReporting)(
"should display a success reporting",
({ language, reporting, url, logs }) => {
displayReporting(reporting, mockedTimestamp);
expect(consoleGroupSpy).toHaveBeenCalledWith(
`[${expectedTime}]`,
workspaceName,
`[${language.toUpperCase()}]`,
url
);
expect(consoleInfoSpy).toHaveBeenCalledWith("\x1b[1;32m\u2714 pass\x1b[0m");
expect(consoleGroupEndSpy).toHaveBeenCalled();
if (reporting.messages && logs) {
for (const log of logs) {
const { message, place, extract } = log;
if (place && extract) {
expect(consoleWarnSpy).toHaveBeenCalledWith("\x1b[1;33mWarning:\x1b[0m", message);
expect(consoleInfoSpy).toHaveBeenCalledWith(`${place}:`, extract);
} else {
expect(consoleInfoSpy).toHaveBeenCalledWith("\x1b[1;34mInfo:\x1b[0m", message);
}
}
} else expect(consoleWarnSpy).not.toHaveBeenCalled();
expect(consoleErrorSpy).not.toHaveBeenCalled();
}
);
expect(consoleInfoSpy).toHaveBeenCalledWith("\x1b[1;32m\u2714 pass\x1b[0m");
expect(consoleGroupEndSpy).toHaveBeenCalled();
if (reporting.messages && logs) {
for (const log of logs) {
const { message, place, extract } = log;
if (place && extract) {
expect(consoleWarnSpy).toHaveBeenCalledWith("\x1b[1;33mWarning:\x1b[0m", message);
expect(consoleInfoSpy).toHaveBeenCalledWith(`${place}:`, extract);
} else {
expect(consoleInfoSpy).toHaveBeenCalledWith("\x1b[1;34mInfo:\x1b[0m", message);
it.each(mockedInvalidResultReporting)(
"should display a fail reporting",
({ language, reporting, url, messages, logs }) => {
displayReporting(reporting, mockedTimestamp);
expect(consoleGroupSpy).toHaveBeenCalledWith(
`[${expectedTime}]`,
workspaceName,
`[${language.toUpperCase()}]`,
url
);
expect(consoleInfoSpy).toHaveBeenCalledWith(
"\x1b[1;31m\u2718 fail\x1b[0m",
`(messages: ${messages})`
);
for (const log of logs) {
const { level, message, place, extract } = log;
if (level === "Error") {
expect(consoleErrorSpy).toHaveBeenCalledWith(`\x1b[1;31m${level}:\x1b[0m`, message);
} else if (level === "Warning") {
expect(consoleWarnSpy).toHaveBeenCalledWith(`\x1b[1;33m${level}:\x1b[0m`, message);
} else {
expect(consoleInfoSpy).toHaveBeenCalledWith(`\x1b[1;34m${level}:\x1b[0m`, message);
}
if (place && extract) expect(consoleInfoSpy).toHaveBeenCalledWith(`${place}:`, extract);
}
expect(consoleGroupEndSpy).toHaveBeenCalled();
}
} else expect(consoleWarnSpy).not.toHaveBeenCalled();
expect(consoleErrorSpy).not.toHaveBeenCalled();
});
it.each(mockedInvalidResultReporting)("should display a fail reporting", ({
language,
reporting,
url,
messages,
logs
}) => {
displayReporting(reporting, mockedTimestamp);
expect(consoleGroupSpy).toHaveBeenCalledWith(
`[${expectedTime}]`,
workspaceName,
`[${language.toUpperCase()}]`,
url
);
expect(consoleInfoSpy).toHaveBeenCalledWith(
"\x1b[1;31m\u2718 fail\x1b[0m",
`(messages: ${messages})`
);
for (const log of logs) {
const { level, message, place, extract } = log;
if (level === "Error") {
expect(consoleErrorSpy).toHaveBeenCalledWith(`\x1b[1;31m${level}:\x1b[0m`, message);
} else if (level === "Warning") {
expect(consoleWarnSpy).toHaveBeenCalledWith(`\x1b[1;33m${level}:\x1b[0m`, message);
} else {
expect(consoleInfoSpy).toHaveBeenCalledWith(`\x1b[1;34m${level}:\x1b[0m`, message);
}
if (place && extract) expect(consoleInfoSpy).toHaveBeenCalledWith(`${place}:`, extract);
}
expect(consoleGroupEndSpy).toHaveBeenCalled();
});
});
}
);
12 changes: 6 additions & 6 deletions test/utils/prepare-reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { mockedValidResultReporting } from "./fixtures/mocked-valid-result-repor

vi.mock("node:process", () => ({ cwd: vi.fn(() => mockedCwd) }));

it.each([
...mockedValidResultReporting,
...mockedInvalidResultReporting
])("should prepare reporting for each document", ({ file, language, result, reporting }) => {
expect(prepareReporting(file, language, result)).toStrictEqual(reporting);
});
it.each([...mockedValidResultReporting, ...mockedInvalidResultReporting])(
"should prepare reporting for each document",
({ file, language, result, reporting }) => {
expect(prepareReporting(file, language, result)).toStrictEqual(reporting);
}
);
17 changes: 9 additions & 8 deletions test/utils/show-version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { showVersion } from "../../src/utils/show-version.js";
const cliOptions = ["-v", "--version"];
const expectedVersion = packageManifest.version;

it.each(
cliOptions
)(`should display a message saying \`${expectedVersion}\` when using the \`%s\` command`, cliOption => {
const mockedConsoleLog = vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(childProcess, "execSync").mockReturnValue(`npx markup-validator ${cliOption}`);
showVersion();
expect(mockedConsoleLog).toHaveBeenCalledWith(expectedVersion);
});
it.each(cliOptions)(
`should display a message saying \`${expectedVersion}\` when using the \`%s\` command`,
cliOption => {
const mockedConsoleLog = vi.spyOn(console, "log").mockImplementation(() => undefined);
vi.spyOn(childProcess, "execSync").mockReturnValue(`npx markup-validator ${cliOption}`);
showVersion();
expect(mockedConsoleLog).toHaveBeenCalledWith(expectedVersion);
}
);
70 changes: 35 additions & 35 deletions test/validators/css-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ it("should be an instance of CSSValidator", () => {
const cssValidator = new CSSValidator("fake-css-content");
expect(cssValidator).toBeInstanceOf(CSSValidator);
});
it.each([
...mockedValidCSSFilesResults,
...mockedInvalidCSSFilesResults
])("should instantiate the object with the file contents", ({ content }) => {
const cssValidator = new CSSValidator(content);
expect(cssValidator).toHaveProperty("content", content);
});
it.each(
mockedValidCSSFilesResults
)("should return a JSON output with an empty array of messages or warning messages", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const cssValidator = new CSSValidator(content, ignoreLevel);
const result = await cssValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(expectedEntryPoint, content, mockedCSSHeaders);
expect(result).toEqual(expectedResult);
});
it.each(
mockedInvalidCSSFilesResults
)("should return a JSON output with messages according to the level requested", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const cssValidator = new CSSValidator(content, ignoreLevel);
const result = await cssValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(expectedEntryPoint, content, mockedCSSHeaders);
expect(result).toEqual(expectedResult);
});
it.each([...mockedValidCSSFilesResults, ...mockedInvalidCSSFilesResults])(
"should instantiate the object with the file contents",
({ content }) => {
const cssValidator = new CSSValidator(content);
expect(cssValidator).toHaveProperty("content", content);
}
);
it.each(mockedValidCSSFilesResults)(
"should return a JSON output with an empty array of messages or warning messages",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const cssValidator = new CSSValidator(content, ignoreLevel);
const result = await cssValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedCSSHeaders
);
expect(result).toEqual(expectedResult);
}
);
it.each(mockedInvalidCSSFilesResults)(
"should return a JSON output with messages according to the level requested",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const cssValidator = new CSSValidator(content, ignoreLevel);
const result = await cssValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedCSSHeaders
);
expect(result).toEqual(expectedResult);
}
);
78 changes: 35 additions & 43 deletions test/validators/html-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,38 @@ it("should be an instance of HTMLValidator", () => {
const htmlValidator = new HTMLValidator("fake-html-content");
expect(htmlValidator).toBeInstanceOf(HTMLValidator);
});
it.each([
...mockedValidHTMLFilesResults,
...mockedInvalidHTMLFilesResults
])("should instantiate the object with the file contents", ({ content }) => {
const htmlValidator = new HTMLValidator(content);
expect(htmlValidator).toHaveProperty("content", content);
});
it.each(
mockedValidHTMLFilesResults
)("should return a JSON output with an empty array of messages or warning messages", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const htmlValidator = new HTMLValidator(content, ignoreLevel);
const result = await htmlValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedHTMLHeaders
);
expect(result).toEqual(expectedResult);
});
it.each(
mockedInvalidHTMLFilesResults
)("should return a JSON output with messages according to the level requested", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const htmlValidator = new HTMLValidator(content, ignoreLevel);
const result = await htmlValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedHTMLHeaders
);
expect(result).toEqual(expectedResult);
});
it.each([...mockedValidHTMLFilesResults, ...mockedInvalidHTMLFilesResults])(
"should instantiate the object with the file contents",
({ content }) => {
const htmlValidator = new HTMLValidator(content);
expect(htmlValidator).toHaveProperty("content", content);
}
);
it.each(mockedValidHTMLFilesResults)(
"should return a JSON output with an empty array of messages or warning messages",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const htmlValidator = new HTMLValidator(content, ignoreLevel);
const result = await htmlValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedHTMLHeaders
);
expect(result).toEqual(expectedResult);
}
);
it.each(mockedInvalidHTMLFilesResults)(
"should return a JSON output with messages according to the level requested",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const htmlValidator = new HTMLValidator(content, ignoreLevel);
const result = await htmlValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedHTMLHeaders
);
expect(result).toEqual(expectedResult);
}
);
70 changes: 35 additions & 35 deletions test/validators/svg-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@ it("should be an instance of SVGValidator", () => {
const svgValidator = new SVGValidator("fake-svg-content");
expect(svgValidator).toBeInstanceOf(SVGValidator);
});
it.each([
...mockedValidSVGFilesResults,
...mockedInvalidSVGFilesResults
])("should instantiate the object with the file contents", ({ content }) => {
const svgValidator = new SVGValidator(content);
expect(svgValidator).toHaveProperty("content", content);
});
it.each(
mockedValidSVGFilesResults
)("should return a JSON output with an empty array of messages or warning messages", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const svgValidator = new SVGValidator(content, ignoreLevel);
const result = await svgValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(expectedEntryPoint, content, mockedSVGHeaders);
expect(result).toEqual(expectedResult);
});
it.each(
mockedInvalidSVGFilesResults
)("should return a JSON output with messages according to the level requested", async ({
content,
ignoreLevel,
expectedEntryPoint,
expectedResult
}) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const svgValidator = new SVGValidator(content, ignoreLevel);
const result = await svgValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(expectedEntryPoint, content, mockedSVGHeaders);
expect(result).toEqual(expectedResult);
});
it.each([...mockedValidSVGFilesResults, ...mockedInvalidSVGFilesResults])(
"should instantiate the object with the file contents",
({ content }) => {
const svgValidator = new SVGValidator(content);
expect(svgValidator).toHaveProperty("content", content);
}
);
it.each(mockedValidSVGFilesResults)(
"should return a JSON output with an empty array of messages or warning messages",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const svgValidator = new SVGValidator(content, ignoreLevel);
const result = await svgValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedSVGHeaders
);
expect(result).toEqual(expectedResult);
}
);
it.each(mockedInvalidSVGFilesResults)(
"should return a JSON output with messages according to the level requested",
async ({ content, ignoreLevel, expectedEntryPoint, expectedResult }) => {
vi.mocked(postDocumentUsingRest).mockResolvedValue(expectedResult);
const svgValidator = new SVGValidator(content, ignoreLevel);
const result = await svgValidator.validate();
expect(postDocumentUsingRest).toHaveBeenCalledWith(
expectedEntryPoint,
content,
mockedSVGHeaders
);
expect(result).toEqual(expectedResult);
}
);