From 93a9439081b5246bcb0287d225453a3e1ed12f7d Mon Sep 17 00:00:00 2001 From: William Killerud Date: Sun, 8 Dec 2024 12:09:34 +0100 Subject: [PATCH] test: confirm configuration is applied if given --- .../features/__tests__/do-diagnostics.test.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 packages/language-services/src/features/__tests__/do-diagnostics.test.ts diff --git a/packages/language-services/src/features/__tests__/do-diagnostics.test.ts b/packages/language-services/src/features/__tests__/do-diagnostics.test.ts new file mode 100644 index 00000000..128597b7 --- /dev/null +++ b/packages/language-services/src/features/__tests__/do-diagnostics.test.ts @@ -0,0 +1,65 @@ +import { test, assert, beforeEach } from "vitest"; +import { + defaultConfiguration, + getLanguageService, +} from "../../language-services"; +import { DiagnosticSeverity } from "../../language-services-types"; +import { getOptions } from "../../utils/test-helpers"; + +const { fileSystemProvider, ...rest } = getOptions(); +const ls = getLanguageService({ fileSystemProvider, ...rest }); + +beforeEach(() => { + ls.clearCache(); + ls.configure(defaultConfiguration); +}); + +test("reports an unknown at-rule", async () => { + const document = fileSystemProvider.createDocument(` +@tailwind base; +`); + + const result = await ls.doDiagnostics(document); + + assert.deepStrictEqual(result, [ + { + code: "unknownAtRules", + message: "Unknown at rule @tailwind", + range: { + start: { + line: 1, + character: 0, + }, + end: { + line: 1, + character: 9, + }, + }, + severity: DiagnosticSeverity.Warning, + source: "scss", + }, + ]); +}); + +test("ignores unknown at-rules if configured", async () => { + const document = fileSystemProvider.createDocument(` +@tailwind base; +`); + + ls.configure({ + ...defaultConfiguration, + scss: { + ...defaultConfiguration.scss, + diagnostics: { + ...defaultConfiguration.scss.diagnostics, + lint: { + ...defaultConfiguration.scss.diagnostics.lint, + unknownAtRules: "ignore", + }, + }, + }, + }); + const result = await ls.doDiagnostics(document); + + assert.deepStrictEqual(result, []); +});