From b98bb4c90d87a64378bd0a566c5653790a9e84e9 Mon Sep 17 00:00:00 2001 From: Elias Skogevall Date: Tue, 25 Jun 2024 09:28:58 +0000 Subject: [PATCH] test: add tests to language service --- .../src/features/__fixtures__/hover.html | 3 ++ .../features/__fixtures__/hover.viewmodel.ts | 3 ++ .../src/features/hover.spec.ts | 41 +++++++++++++++++++ packages/language-service/tsconfig.json | 4 +- packages/language-service/tsconfig.lib.json | 3 +- 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 packages/language-service/src/features/__fixtures__/hover.html create mode 100644 packages/language-service/src/features/__fixtures__/hover.viewmodel.ts create mode 100644 packages/language-service/src/features/hover.spec.ts diff --git a/packages/language-service/src/features/__fixtures__/hover.html b/packages/language-service/src/features/__fixtures__/hover.html new file mode 100644 index 0000000..5c9fd2b --- /dev/null +++ b/packages/language-service/src/features/__fixtures__/hover.html @@ -0,0 +1,3 @@ + +

+ diff --git a/packages/language-service/src/features/__fixtures__/hover.viewmodel.ts b/packages/language-service/src/features/__fixtures__/hover.viewmodel.ts new file mode 100644 index 0000000..f15b597 --- /dev/null +++ b/packages/language-service/src/features/__fixtures__/hover.viewmodel.ts @@ -0,0 +1,3 @@ +export default class { + hello = "hello"; +} diff --git a/packages/language-service/src/features/hover.spec.ts b/packages/language-service/src/features/hover.spec.ts new file mode 100644 index 0000000..df55527 --- /dev/null +++ b/packages/language-service/src/features/hover.spec.ts @@ -0,0 +1,41 @@ +import { LanguageService } from "../index.js"; +import { readFile } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; + +describe("hover", () => { + let service: LanguageService; + let fileName: string; + + beforeAll(async () => { + service = new LanguageService({ + worker: false, + }); + fileName = fileURLToPath( + new URL("__fixtures__/hover.html", import.meta.url), + ); + const text = await readFile(fileName, "utf8"); + await service.openDocument(fileName, text); + }); + + it("provides hover details for bindings (name)", async () => { + const hover = await service.getHover({ + fileName: fileName, + position: { + line: 1, + column: 17, + }, + }); + expect(hover).not.toBe(null); + }); + + it("provides hover details for viewmodel property", async () => { + const hover = await service.getHover({ + fileName: fileName, + position: { + line: 1, + column: 23, + }, + }); + expect(hover).not.toBe(null); + }); +}); diff --git a/packages/language-service/tsconfig.json b/packages/language-service/tsconfig.json index 79e5b05..84d11f3 100644 --- a/packages/language-service/tsconfig.json +++ b/packages/language-service/tsconfig.json @@ -1,7 +1,7 @@ { "references": [ - { "path": "tsconfig.lib.json" } - // { "path": "tsconfig.spec.json" } + { "path": "tsconfig.lib.json" }, + { "path": "tsconfig.spec.json" } ], "include": [] } diff --git a/packages/language-service/tsconfig.lib.json b/packages/language-service/tsconfig.lib.json index a42d6f2..efd3a03 100644 --- a/packages/language-service/tsconfig.lib.json +++ b/packages/language-service/tsconfig.lib.json @@ -1,4 +1,5 @@ { "extends": ["@tools/tsconfig/node.json"], - "include": ["src"] + "include": ["src"], + "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "**/__fixtures__"] }