microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/npm/qsharp/test/languageService.js

83lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4// @ts-check
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { log } from "../dist/log.js";
9import { getLanguageService } from "../dist/main.js";
10
11log.setLogLevel("warn");
12
13// Minimal IProjectHost implementation for testing
14const dummyHost = {
15 readFile: async () => null,
16 listDirectory: async () => [],
17 resolvePath: async (a, b) => b,
18 fetchGithub: async () => "",
19 findManifestDirectory: async () => null,
20};
21
22test("devDiagnostics configuration works", async () => {
23 const languageService = getLanguageService(dummyHost);
24
25 try {
26 // Collect diagnostics events as they are raised
27 const diagnosticEvents = [];
28 languageService.addEventListener("diagnostics", (event) => {
29 diagnosticEvents.push({
30 uri: event.detail.uri,
31 diagnostics: event.detail.diagnostics.map((diag) => ({
32 code: diag.code,
33 })),
34 });
35 });
36
37 // Enable dev diagnostics
38 await languageService.updateConfiguration({
39 devDiagnostics: true,
40 });
41
42 // Update a document
43 await languageService.updateDocument(
44 "test.qs",
45 1,
46 "namespace Test { @EntryPoint() operation Main() : Unit {} }",
47 "qsharp",
48 );
49
50 await new Promise((resolve) => setTimeout(resolve, 0));
51
52 // Should have received diagnostic events
53 assert.deepEqual(diagnosticEvents, [
54 {
55 diagnostics: [
56 {
57 code: "Qdk.Dev.DocumentStatus",
58 },
59 ],
60 uri: "test.qs",
61 },
62 ]);
63
64 // Test disabling dev diagnostics
65 diagnosticEvents.length = 0;
66
67 await languageService.updateConfiguration({
68 devDiagnostics: false,
69 });
70
71 await new Promise((resolve) => setTimeout(resolve, 0));
72
73 // Diagnostics should be cleared
74 assert.deepEqual(diagnosticEvents, [
75 {
76 diagnostics: [],
77 uri: "test.qs",
78 },
79 ]);
80 } finally {
81 await languageService.dispose();
82 }
83});
84