• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts.projectSystem {
2    describe("unittests:: tsserver:: typeReferenceDirectives", () => {
3        it("when typeReferenceDirective contains UpperCasePackage", () => {
4            const libProjectLocation = `${tscWatch.projectRoot}/lib`;
5            const typeLib: File = {
6                path: `${libProjectLocation}/@types/UpperCasePackage/index.d.ts`,
7                content: `declare class BrokenTest {
8    constructor(name: string, width: number, height: number, onSelect: Function);
9    Name: string;
10    SelectedFile: string;
11}`
12            };
13            const appLib: File = {
14                path: `${libProjectLocation}/@app/lib/index.d.ts`,
15                content: `/// <reference types="UpperCasePackage" />
16declare class TestLib {
17    issue: BrokenTest;
18    constructor();
19    test(): void;
20}`
21            };
22            const testProjectLocation = `${tscWatch.projectRoot}/test`;
23            const testFile: File = {
24                path: `${testProjectLocation}/test.ts`,
25                content: `class TestClass1 {
26
27    constructor() {
28        var l = new TestLib();
29
30    }
31
32    public test2() {
33        var x = new BrokenTest('',0,0,null);
34
35    }
36}`
37            };
38            const testConfig: File = {
39                path: `${testProjectLocation}/tsconfig.json`,
40                content: JSON.stringify({
41                    compilerOptions: {
42                        module: "amd",
43                        typeRoots: ["../lib/@types", "../lib/@app"]
44                    }
45                })
46            };
47
48            const files = [typeLib, appLib, testFile, testConfig, libFile];
49            const host = createServerHost(files);
50            const service = createProjectService(host);
51            service.openClientFile(testFile.path);
52            checkNumberOfProjects(service, { configuredProjects: 1 });
53            const project = service.configuredProjects.get(testConfig.path)!;
54            checkProjectActualFiles(project, files.map(f => f.path));
55            host.writeFile(appLib.path, appLib.content.replace("test()", "test2()"));
56            host.checkTimeoutQueueLengthAndRun(2);
57        });
58
59        it("when typeReferenceDirective is relative path and in a sibling folder", () => {
60            const projectPath = `${tscWatch.projectRoot}/background`;
61            const file: File = {
62                path: `${projectPath}/a.ts`,
63                content: "let x = 10;"
64            };
65            const tsconfig: File = {
66                path: `${projectPath}/tsconfig.json`,
67                content: JSON.stringify({
68                    compilerOptions: {
69                        types: [
70                            "../typedefs/filesystem"
71                        ]
72                    }
73                })
74            };
75            const filesystem: File = {
76                path: `${tscWatch.projectRoot}/typedefs/filesystem.d.ts`,
77                content: `interface LocalFileSystem { someProperty: string; }`
78            };
79            const files = [file, tsconfig, filesystem, libFile];
80            const host = createServerHost(files);
81            const service = createProjectService(host);
82            service.openClientFile(file.path);
83        });
84    });
85}
86