• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace Harness {
2    export class FourSlashRunner extends RunnerBase {
3        protected basePath: string;
4        protected testSuiteName: TestRunnerKind;
5
6        constructor(private testType: FourSlash.FourSlashTestType) {
7            super();
8            switch (testType) {
9                case FourSlash.FourSlashTestType.Native:
10                    this.basePath = "tests/cases/fourslash";
11                    this.testSuiteName = "fourslash";
12                    break;
13                case FourSlash.FourSlashTestType.OH:
14                    this.basePath = "tests/cases/fourslash/oh";
15                    this.testSuiteName = "fourslash-oh";
16                    break;
17                case FourSlash.FourSlashTestType.Shims:
18                    this.basePath = "tests/cases/fourslash/shims";
19                    this.testSuiteName = "fourslash-shims";
20                    break;
21                case FourSlash.FourSlashTestType.ShimsWithPreprocess:
22                    this.basePath = "tests/cases/fourslash/shims-pp";
23                    this.testSuiteName = "fourslash-shims-pp";
24                    break;
25                case FourSlash.FourSlashTestType.Server:
26                    this.basePath = "tests/cases/fourslash/server";
27                    this.testSuiteName = "fourslash-server";
28                    break;
29                default:
30                    throw ts.Debug.assertNever(testType);
31            }
32        }
33
34        public enumerateTestFiles() {
35            // see also: `enumerateTestFiles` in tests/webTestServer.ts
36            return this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false });
37        }
38
39        public kind() {
40            return this.testSuiteName;
41        }
42
43        public initializeTests() {
44            if (this.tests.length === 0) {
45                this.tests = IO.enumerateTestFiles(this);
46            }
47
48            describe(this.testSuiteName + " tests", () => {
49                this.tests.forEach(test => {
50                    const file = typeof test === "string" ? test : test.file;
51                    describe(file, () => {
52                        let fn = ts.normalizeSlashes(file);
53                        const justName = fn.replace(/^.*[\\\/]/, "");
54
55                        // Convert to relative path
56                        const testIndex = fn.indexOf("tests/");
57                        if (testIndex >= 0) fn = fn.substr(testIndex);
58
59                        if (justName !== "fourslash.ts") {
60                            it(this.testSuiteName + " test " + justName + " runs correctly", () => {
61                                FourSlash.runFourSlashTest(this.basePath, this.testType, fn);
62                            });
63                        }
64                    });
65                });
66            });
67        }
68    }
69
70    export class GeneratedFourslashRunner extends FourSlashRunner {
71        constructor(testType: FourSlash.FourSlashTestType) {
72            super(testType);
73            this.basePath += "/generated/";
74        }
75    }
76}
77