From 15fd9705f4faebee1076b293ebcb900a797864de Mon Sep 17 00:00:00 2001 From: webdevbynight Date: Thu, 16 Jul 2026 01:07:10 +0200 Subject: [PATCH] style: format test files Biome 2.5.4 fixes the way arguments of `describe.each` and `it.each` break. --- test/utils/display-reporting.test.ts | 115 ++++++++++++------------- test/utils/prepare-reporting.test.ts | 12 +-- test/utils/show-version.test.ts | 17 ++-- test/validators/css-validator.test.ts | 70 +++++++-------- test/validators/html-validator.test.ts | 78 ++++++++--------- test/validators/svg-validator.test.ts | 70 +++++++-------- 6 files changed, 175 insertions(+), 187 deletions(-) diff --git a/test/utils/display-reporting.test.ts b/test/utils/display-reporting.test.ts index 2a02ba0..3907dfa 100644 --- a/test/utils/display-reporting.test.ts +++ b/test/utils/display-reporting.test.ts @@ -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(); - }); -}); + } +); diff --git a/test/utils/prepare-reporting.test.ts b/test/utils/prepare-reporting.test.ts index ac9c247..52ccc30 100644 --- a/test/utils/prepare-reporting.test.ts +++ b/test/utils/prepare-reporting.test.ts @@ -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); + } +); diff --git a/test/utils/show-version.test.ts b/test/utils/show-version.test.ts index de4721c..199831f 100644 --- a/test/utils/show-version.test.ts +++ b/test/utils/show-version.test.ts @@ -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); + } +); diff --git a/test/validators/css-validator.test.ts b/test/validators/css-validator.test.ts index 679459d..73f8cf6 100644 --- a/test/validators/css-validator.test.ts +++ b/test/validators/css-validator.test.ts @@ -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); + } +); diff --git a/test/validators/html-validator.test.ts b/test/validators/html-validator.test.ts index 15f8bd2..abc610b 100644 --- a/test/validators/html-validator.test.ts +++ b/test/validators/html-validator.test.ts @@ -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); + } +); diff --git a/test/validators/svg-validator.test.ts b/test/validators/svg-validator.test.ts index ddf8d1e..fb95d0b 100644 --- a/test/validators/svg-validator.test.ts +++ b/test/validators/svg-validator.test.ts @@ -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); + } +);