From 3756524ad3a5ddb83626604d27649c7a01a2c934 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 8 Mar 2025 02:55:51 +0200 Subject: [PATCH] feat(test): basic tests for ESLint --- src/public/app/services/eslint.spec.ts | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/public/app/services/eslint.spec.ts diff --git a/src/public/app/services/eslint.spec.ts b/src/public/app/services/eslint.spec.ts new file mode 100644 index 000000000..7070e8a69 --- /dev/null +++ b/src/public/app/services/eslint.spec.ts @@ -0,0 +1,29 @@ +import { lint } from "./eslint.js"; +import { trimIndentation } from "../../../../spec/support/utils.js"; +import { describe, expect, it } from "vitest"; + +describe("Linter", () => { + it("reports some basic errors", async () => { + const result = await lint(trimIndentation` + for (const i = 0; i<10; i++) { + } + `); + expect(result).toMatchObject([ + { message: "'i' is constant.", }, + { message: "Empty block statement." } + ]); + }); + + it("reports no error for correct script", async () => { + const result = await lint(trimIndentation` + const foo = "bar"; + console.log(foo.toString()); + for (const x of [ 1, 2, 3]) { + console.log(x?.toString()); + } + + api.showMessage("Hi"); + `); + expect(result.length).toBe(0); + }); +});