|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
| 14 | + * for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +/*global describe, it, expect, beforeAll, afterAll, awaitsFor, awaitsForDone */ |
| 22 | + |
| 23 | +define(function (require, exports, module) { |
| 24 | + |
| 25 | + const SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"); |
| 26 | + |
| 27 | + const IMPLICIT_ANY_MESSAGE = "implicitly has an 'any' type"; |
| 28 | + |
| 29 | + describe("integration:TypeScript LSP", function () { |
| 30 | + const testRootSpec = "/spec/TypeScriptSupport-test-files/"; |
| 31 | + let testFolder = SpecRunnerUtils.getTestPath(testRootSpec), |
| 32 | + testWindow, |
| 33 | + $, |
| 34 | + EditorManager, |
| 35 | + CommandManager, |
| 36 | + Commands, |
| 37 | + CodeInspection; |
| 38 | + |
| 39 | + // The LSP runs only in the desktop app (it spawns the vtsls Node process), so these tests |
| 40 | + // are meaningless in the browser build - register a single skipped placeholder and bail. |
| 41 | + if (!Phoenix.isNativeApp) { |
| 42 | + it("is desktop-only - skipped in the browser build", function () { |
| 43 | + expect(Phoenix.isNativeApp).toBeFalsy(); |
| 44 | + }); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + beforeAll(async function () { |
| 49 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 50 | + $ = testWindow.$; |
| 51 | + EditorManager = testWindow.brackets.test.EditorManager; |
| 52 | + CommandManager = testWindow.brackets.test.CommandManager; |
| 53 | + Commands = testWindow.brackets.test.Commands; |
| 54 | + CodeInspection = testWindow.brackets.test.CodeInspection; |
| 55 | + CodeInspection.toggleEnabled(true); |
| 56 | + // Wait until the extension has attempted to start the language server. |
| 57 | + await awaitsFor(function () { |
| 58 | + return testWindow._TypeScriptSupportReadyToIntegTest; |
| 59 | + }, "TypeScript LSP server to start", 30000); |
| 60 | + }, 30000); |
| 61 | + |
| 62 | + afterAll(async function () { |
| 63 | + testWindow = null; |
| 64 | + $ = null; |
| 65 | + EditorManager = null; |
| 66 | + CommandManager = null; |
| 67 | + Commands = null; |
| 68 | + CodeInspection = null; |
| 69 | + await SpecRunnerUtils.closeTestWindow(); |
| 70 | + }, 30000); |
| 71 | + |
| 72 | + function panelText() { |
| 73 | + return $("#problems-panel").text(); |
| 74 | + } |
| 75 | + |
| 76 | + async function _openInProject(subFolder, fileName) { |
| 77 | + await SpecRunnerUtils.loadProjectInTestWindow(testFolder + subFolder); |
| 78 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName]), "open " + fileName); |
| 79 | + } |
| 80 | + |
| 81 | + it("should report TypeScript type errors from the language server", async function () { |
| 82 | + await _openInProject("ts/", "type-error.ts"); |
| 83 | + // type-error.ts assigns a string to a `number` -> TS2322 "... not assignable ...". |
| 84 | + await awaitsFor(function () { |
| 85 | + return panelText().includes("not assignable"); |
| 86 | + }, "TypeScript type error to be reported", 20000); |
| 87 | + }, 30000); |
| 88 | + |
| 89 | + it("should report implicit-any in a JS project that opts into checkJs", async function () { |
| 90 | + // js-checkjs has a jsconfig.json with checkJs + noImplicitAny, so the untyped parameter |
| 91 | + // in implicit.js IS flagged - and our diagnostic filter keeps it (the project opted in). |
| 92 | + await _openInProject("js-checkjs/", "implicit.js"); |
| 93 | + await awaitsFor(function () { |
| 94 | + return panelText().includes(IMPLICIT_ANY_MESSAGE); |
| 95 | + }, "implicit-any to be reported under checkJs", 20000); |
| 96 | + }, 30000); |
| 97 | + |
| 98 | + it("should NOT report implicit-any in a plain JS project", async function () { |
| 99 | + // Precondition: confirm the server actually produces implicit-any for this exact code |
| 100 | + // (under checkJs), so the plain-project assertion below reflects gating, not just timing. |
| 101 | + await _openInProject("js-checkjs/", "implicit.js"); |
| 102 | + await awaitsFor(function () { |
| 103 | + return panelText().includes(IMPLICIT_ANY_MESSAGE); |
| 104 | + }, "implicit-any under checkJs (precondition)", 20000); |
| 105 | + |
| 106 | + // Same code in a plain JS project (no jsconfig / no @ts-check): the "go add types" nag |
| 107 | + // must not appear. Wait for inspection to settle clean, then assert it is absent. |
| 108 | + await _openInProject("js-plain/", "implicit.js"); |
| 109 | + await awaitsFor(function () { |
| 110 | + return $("#status-inspection").hasClass("inspection-valid"); |
| 111 | + }, "plain JS inspection to settle with no problems", 20000); |
| 112 | + expect(panelText().includes(IMPLICIT_ANY_MESSAGE)).toBe(false); |
| 113 | + }, 30000); |
| 114 | + }); |
| 115 | +}); |
0 commit comments