|
| 1 | +import test from "ava"; |
| 2 | +import {createVirtualLanguageServiceHost} from "../../../../src/linter/ui5Types/host.js"; |
| 3 | +import LinterContext from "../../../../src/linter/LinterContext.js"; |
| 4 | +import SharedLanguageService from "../../../../src/linter/ui5Types/SharedLanguageService.js"; |
| 5 | + |
| 6 | +// List of TypeScript library files that are loaded by default in the virtual language service host. |
| 7 | +const LIB_TYPE_FILES = [ |
| 8 | + "/types/typescript/lib/lib.es5.d.ts", |
| 9 | + "/types/typescript/lib/lib.es2015.d.ts", |
| 10 | + "/types/typescript/lib/lib.es2016.d.ts", |
| 11 | + "/types/typescript/lib/lib.es2017.d.ts", |
| 12 | + "/types/typescript/lib/lib.es2018.d.ts", |
| 13 | + "/types/typescript/lib/lib.es2019.d.ts", |
| 14 | + "/types/typescript/lib/lib.es2020.d.ts", |
| 15 | + "/types/typescript/lib/lib.es2021.d.ts", |
| 16 | + "/types/typescript/lib/lib.es2022.d.ts", |
| 17 | + "/types/typescript/lib/lib.dom.d.ts", |
| 18 | + "/types/typescript/lib/lib.es2015.core.d.ts", |
| 19 | + "/types/typescript/lib/lib.es2015.collection.d.ts", |
| 20 | + "/types/typescript/lib/lib.es2015.generator.d.ts", |
| 21 | + "/types/typescript/lib/lib.es2015.iterable.d.ts", |
| 22 | + "/types/typescript/lib/lib.es2015.promise.d.ts", |
| 23 | + "/types/typescript/lib/lib.es2015.proxy.d.ts", |
| 24 | + "/types/typescript/lib/lib.es2015.reflect.d.ts", |
| 25 | + "/types/typescript/lib/lib.es2015.symbol.d.ts", |
| 26 | + "/types/typescript/lib/lib.es2015.symbol.wellknown.d.ts", |
| 27 | + "/types/typescript/lib/lib.es2016.array.include.d.ts", |
| 28 | + "/types/typescript/lib/lib.es2016.intl.d.ts", |
| 29 | + "/types/typescript/lib/lib.es2017.arraybuffer.d.ts", |
| 30 | + "/types/typescript/lib/lib.es2017.date.d.ts", |
| 31 | + "/types/typescript/lib/lib.es2017.object.d.ts", |
| 32 | + "/types/typescript/lib/lib.es2017.sharedmemory.d.ts", |
| 33 | + "/types/typescript/lib/lib.es2017.string.d.ts", |
| 34 | + "/types/typescript/lib/lib.es2017.intl.d.ts", |
| 35 | + "/types/typescript/lib/lib.es2017.typedarrays.d.ts", |
| 36 | + "/types/typescript/lib/lib.es2018.asyncgenerator.d.ts", |
| 37 | + "/types/typescript/lib/lib.es2018.asynciterable.d.ts", |
| 38 | + "/types/typescript/lib/lib.es2018.intl.d.ts", |
| 39 | + "/types/typescript/lib/lib.es2018.promise.d.ts", |
| 40 | + "/types/typescript/lib/lib.es2018.regexp.d.ts", |
| 41 | + "/types/typescript/lib/lib.es2019.array.d.ts", |
| 42 | + "/types/typescript/lib/lib.es2019.object.d.ts", |
| 43 | + "/types/typescript/lib/lib.es2019.string.d.ts", |
| 44 | + "/types/typescript/lib/lib.es2019.symbol.d.ts", |
| 45 | + "/types/typescript/lib/lib.es2019.intl.d.ts", |
| 46 | + "/types/typescript/lib/lib.es2020.bigint.d.ts", |
| 47 | + "/types/typescript/lib/lib.es2020.date.d.ts", |
| 48 | + "/types/typescript/lib/lib.es2020.promise.d.ts", |
| 49 | + "/types/typescript/lib/lib.es2020.sharedmemory.d.ts", |
| 50 | + "/types/typescript/lib/lib.es2020.string.d.ts", |
| 51 | + "/types/typescript/lib/lib.es2020.symbol.wellknown.d.ts", |
| 52 | + "/types/typescript/lib/lib.es2020.intl.d.ts", |
| 53 | + "/types/typescript/lib/lib.es2020.number.d.ts", |
| 54 | + "/types/typescript/lib/lib.es2021.promise.d.ts", |
| 55 | + "/types/typescript/lib/lib.es2021.string.d.ts", |
| 56 | + "/types/typescript/lib/lib.es2021.weakref.d.ts", |
| 57 | + "/types/typescript/lib/lib.es2021.intl.d.ts", |
| 58 | + "/types/typescript/lib/lib.es2022.array.d.ts", |
| 59 | + "/types/typescript/lib/lib.es2022.error.d.ts", |
| 60 | + "/types/typescript/lib/lib.es2022.intl.d.ts", |
| 61 | + "/types/typescript/lib/lib.es2022.object.d.ts", |
| 62 | + "/types/typescript/lib/lib.es2022.string.d.ts", |
| 63 | + "/types/typescript/lib/lib.es2022.regexp.d.ts", |
| 64 | + "/types/typescript/lib/lib.decorators.d.ts", |
| 65 | + "/types/typescript/lib/lib.decorators.legacy.d.ts", |
| 66 | +]; |
| 67 | + |
| 68 | +test("createVirtualLanguageServiceHost: Empty project", async (t) => { |
| 69 | + const sharedLanguageService = new SharedLanguageService(); |
| 70 | + |
| 71 | + const fileContents = new Map<string, string>([ |
| 72 | + ["/resources/test/test.js", ""], |
| 73 | + ]); |
| 74 | + const sourceMaps = new Map<string, string>(); |
| 75 | + const context = new LinterContext({ |
| 76 | + rootDir: "/", |
| 77 | + namespace: "test", |
| 78 | + }); |
| 79 | + const projectScriptVersion = sharedLanguageService.getNextProjectScriptVersion(); |
| 80 | + |
| 81 | + const host = await createVirtualLanguageServiceHost( |
| 82 | + {}, fileContents, sourceMaps, context, projectScriptVersion, undefined |
| 83 | + ); |
| 84 | + |
| 85 | + sharedLanguageService.acquire(host); |
| 86 | + |
| 87 | + const program = sharedLanguageService.getProgram(); |
| 88 | + |
| 89 | + // Check for the minimum loaded files. This needs to be adjusted when the default compiler options |
| 90 | + // are changed or additional type definitions are added. |
| 91 | + const sourceFileNames = program.getSourceFiles().map((sf) => sf.fileName); |
| 92 | + t.deepEqual(sourceFileNames, [ |
| 93 | + ...LIB_TYPE_FILES, |
| 94 | + "/resources/test/test.js", |
| 95 | + "/types/@types/jquery/JQueryStatic.d.ts", |
| 96 | + "/types/@types/jquery/JQuery.d.ts", |
| 97 | + "/types/@types/jquery/misc.d.ts", |
| 98 | + "/types/@types/jquery/legacy.d.ts", |
| 99 | + "/types/@types/jquery/index.d.ts", |
| 100 | + "/types/@types/qunit/index.d.ts", |
| 101 | + "/types/@types/sizzle/index.d.ts", |
| 102 | + "/types/@ui5/linter/types/jquery.sap.mobile.d.ts", |
| 103 | + "/types/@ui5/linter/types/jquery.sap.d.ts", |
| 104 | + "/types/@ui5/linter/types/index.d.ts", |
| 105 | + "/types/@sapui5/types/types/sap.ui.core.d.ts", |
| 106 | + "/types/@ui5/linter/types/pseudo-modules/sap.ui.core.d.ts", |
| 107 | + "/types/@ui5/linter/types/sapui5/sap.ui.core.d.ts", |
| 108 | + ]); |
| 109 | +}); |
| 110 | + |
| 111 | +test("createVirtualLanguageServiceHost: Minimal project with sap/m/Button import", async (t) => { |
| 112 | + const sharedLanguageService = new SharedLanguageService(); |
| 113 | + |
| 114 | + const fileContents = new Map<string, string>([ |
| 115 | + ["/resources/test/test.js", "sap.ui.define(['sap/m/Button'], function() {});"], |
| 116 | + ]); |
| 117 | + const sourceMaps = new Map<string, string>(); |
| 118 | + const context = new LinterContext({ |
| 119 | + rootDir: "/", |
| 120 | + namespace: "test", |
| 121 | + }); |
| 122 | + const projectScriptVersion = sharedLanguageService.getNextProjectScriptVersion(); |
| 123 | + |
| 124 | + const host = await createVirtualLanguageServiceHost( |
| 125 | + {}, fileContents, sourceMaps, context, projectScriptVersion, undefined |
| 126 | + ); |
| 127 | + |
| 128 | + sharedLanguageService.acquire(host); |
| 129 | + |
| 130 | + const program = sharedLanguageService.getProgram(); |
| 131 | + |
| 132 | + // Check for the minimum loaded files. This needs to be adjusted when the default compiler options |
| 133 | + // are changed or additional type definitions are added. |
| 134 | + const sourceFileNames = program.getSourceFiles().map((sf) => sf.fileName); |
| 135 | + t.deepEqual(sourceFileNames, [ |
| 136 | + ...LIB_TYPE_FILES, |
| 137 | + "/types/@sapui5/types/types/sap.ui.core.d.ts", |
| 138 | + "/types/@ui5/linter/types/pseudo-modules/sap.ui.core.d.ts", |
| 139 | + "/types/@ui5/linter/types/sapui5/sap.ui.core.d.ts", |
| 140 | + "/types/@sapui5/types/types/sap.ui.unified.d.ts", |
| 141 | + "/types/@ui5/linter/types/pseudo-modules/sap.ui.unified.d.ts", |
| 142 | + "/types/@ui5/linter/types/sapui5/sap.ui.unified.d.ts", |
| 143 | + "/types/@sapui5/types/types/sap.m.d.ts", |
| 144 | + "/types/@ui5/linter/types/pseudo-modules/sap.m.d.ts", |
| 145 | + "/types/@ui5/linter/types/sapui5/sap.m.d.ts", |
| 146 | + "/resources/test/test.js", |
| 147 | + "/types/@types/jquery/JQueryStatic.d.ts", |
| 148 | + "/types/@types/jquery/JQuery.d.ts", |
| 149 | + "/types/@types/jquery/misc.d.ts", |
| 150 | + "/types/@types/jquery/legacy.d.ts", |
| 151 | + "/types/@types/jquery/index.d.ts", |
| 152 | + "/types/@types/qunit/index.d.ts", |
| 153 | + "/types/@types/sizzle/index.d.ts", |
| 154 | + "/types/@ui5/linter/types/jquery.sap.mobile.d.ts", |
| 155 | + "/types/@ui5/linter/types/jquery.sap.d.ts", |
| 156 | + "/types/@ui5/linter/types/index.d.ts", |
| 157 | + ]); |
| 158 | +}); |
0 commit comments