Skip to content

Commit d66e94d

Browse files
committed
ExternalCompileRunner works with submodules
If there is a test.json in the directory, it expects to find a submodule in the directory. The submodule should have the same name as the directory itself. test.json contains a list of global types that need to be available, or the empty list if none.
1 parent 9d56f7b commit d66e94d

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter"]
2+
path = tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
3+
url = https://github.com/Microsoft/TypeScript-React-Starter
4+
[submodule "tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter"]
5+
path = tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
6+
url = https://github.com/Microsoft/TypeScript-Node-Starter.git

src/harness/externalCompileRunner.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ interface ExecResult {
99
status: number;
1010
}
1111

12+
interface UserConfig {
13+
types: string[];
14+
}
15+
1216
abstract class ExternalCompileRunnerBase extends RunnerBase {
1317
abstract testDir: string;
1418
abstract report(result: ExecResult, cwd: string): string;
@@ -33,18 +37,34 @@ abstract class ExternalCompileRunnerBase extends RunnerBase {
3337
const cp = require("child_process");
3438

3539
it("should build successfully", () => {
36-
const cwd = path.join(__dirname, "../../", this.testDir, directoryName);
40+
let cwd = path.join(__dirname, "../../", this.testDir, directoryName);
3741
const timeout = 600000; // 600s = 10 minutes
42+
const stdio = isWorker ? "pipe" : "inherit";
43+
let types: string[];
44+
if (fs.existsSync(path.join(cwd, "test.json"))) {
45+
const update = cp.spawnSync('git', ["submodule", "update", "--remote"], { cwd, timeout, shell: true, stdio })
46+
if (update.status !== 0) throw new Error(`git submodule update for ${directoryName} failed!`);
47+
48+
const config = JSON.parse(fs.readFileSync(path.join(cwd, "test.json"), { encoding: "utf8" })) as UserConfig;
49+
ts.Debug.assert(!!config.types, "Git is the only reason for using test.json right now");
50+
types = config.types;
51+
52+
cwd = path.join(cwd, directoryName);
53+
}
3854
if (fs.existsSync(path.join(cwd, "package.json"))) {
3955
if (fs.existsSync(path.join(cwd, "package-lock.json"))) {
4056
fs.unlinkSync(path.join(cwd, "package-lock.json"));
4157
}
42-
const stdio = isWorker ? "pipe" : "inherit";
4358
const install = cp.spawnSync(`npm`, ["i"], { cwd, timeout, shell: true, stdio });
4459
if (install.status !== 0) throw new Error(`NPM Install for ${directoryName} failed!`);
4560
}
61+
const args = [path.join(__dirname, "tsc.js")];
62+
if (types) {
63+
args.push("--types", types.join(","));
64+
}
65+
args.push("--noEmit");
4666
Harness.Baseline.runBaseline(`${this.kind()}/${directoryName}.log`, () => {
47-
return this.report(cp.spawnSync(`node`, [path.join(__dirname, "tsc.js")], { cwd, timeout, shell: true }), cwd);
67+
return this.report(cp.spawnSync(`node`, args, { cwd, timeout, shell: true }), cwd);
4868
});
4969
});
5070
});

0 commit comments

Comments
 (0)