• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts.projectSystem {
2    describe("unittests:: tsserver:: jsDoc tag check", () => {
3        it("works jsDoc tag check", () => {
4            const aUser: File = {
5                path: "/a.ts",
6                content: `import { y } from "./b";
7    y.test()
8    y.test2()
9`
10            };
11            const bUser: File = {
12                path: "/b.ts",
13                content: `
14export class y {
15/**
16 * @ignore
17 */
18static test(): void {
19
20}
21/**
22 * @systemApi
23 */
24static test2(): void {
25
26}
27}`
28            };
29            const tsconfigFile: File = {
30                path: "/tsconfig.json",
31                content: JSON.stringify({
32                    compilerOptions: {
33                        target: "es6",
34                        module: "es6",
35                        baseUrl: "./",  // all paths are relative to the baseUrl
36                        paths: {
37                            "~/*": ["*"]   // resolve any `~/foo/bar` to `<baseUrl>/foo/bar`
38                        }
39                    },
40                    exclude: [
41                        "api",
42                        "build",
43                        "node_modules",
44                        "public",
45                        "seeds",
46                        "sql_updates",
47                        "tests.build"
48                    ]
49                })
50            };
51
52            const projectFiles = [aUser, bUser, tsconfigFile];
53            const host = createServerHost(projectFiles);
54            host.getTagNameNeededCheckByFile = (containFilePath: string, sourceFilePath: string) => {
55                Debug.log(containFilePath);
56                Debug.log(sourceFilePath);
57                return {
58                    needCheck: true,
59                    checkConfig: [{
60                        tagName: "ignore",
61                        message: "This API has been ignored. exercise caution when using this API.",
62                        needConditionCheck: false,
63                        type: DiagnosticCategory.Warning,
64                        specifyCheckConditionFuncName: "",
65                        tagNameShouldExisted: false,
66                    },{
67                        tagName: "systemApi",
68                        message: "This API is used to develop system apps. exercise caution when using this API.",
69                        needConditionCheck: false,
70                        type: DiagnosticCategory.Warning,
71                        specifyCheckConditionFuncName: "",
72                        tagNameShouldExisted: false,
73                    }]
74                };
75            };
76            host.getExpressionCheckedResultsByFile = (filePath: string, jsDocs: JSDocTagInfo[]) => {
77                Debug.log(filePath);
78                Debug.log(jsDocs.toString());
79                return {
80                    valid: false,
81                };
82            };
83            const session = createSession(host);
84            const projectService = session.getProjectService();
85            const { configFileName } = projectService.openClientFile(aUser.path);
86
87            assert.isDefined(configFileName, `should find config`);
88
89            const project = projectService.configuredProjects.get(tsconfigFile.path)!;
90            const response = project.getLanguageService().getSuggestionDiagnostics(aUser.path);
91            assert.deepEqual(response[0].messageText, "This API has been ignored. exercise caution when using this API.");
92            assert.deepEqual(response[1].messageText, "This API is used to develop system apps. exercise caution when using this API.");
93        });
94    });
95}