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