-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild-and-run.ts
51 lines (43 loc) · 1.85 KB
/
build-and-run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Course from "../lib/models/course";
import BaseCommand from "./base";
import CommandTester from "../lib/testers/command-tester";
export default class BuildAndRunCommand extends BaseCommand {
languageFilter: string; // Can be empty string
commandToExecute: string;
outputStreamType: string;
expectedOutput: string;
constructor(languageFilter: string, commandToExecute: string, outputStreamType: string, expectedOutput: string) {
super();
this.languageFilter = languageFilter;
this.commandToExecute = commandToExecute;
this.outputStreamType = outputStreamType;
this.expectedOutput = expectedOutput;
}
async doRun() {
const course = Course.loadFromDirectory(process.cwd());
let testers = [...(await this.commandTestersForCourse(course, this.commandToExecute, this.outputStreamType, this.expectedOutput))];
if (this.#languageSlugsToFilter.length !== 0) {
testers = testers.filter((tester) => this.#languageSlugsToFilter.includes(tester.language.slug));
console.log("Testing languages:", this.#languageSlugsToFilter.join(", "));
} else {
console.log("Testing all languages...");
}
for (const tester of testers) {
if (!(await tester.test())) {
console.error("");
console.error(`${tester.constructor.name} failed. Check the logs above for more details.`);
console.error("");
process.exit(1);
}
}
}
get #languageSlugsToFilter() {
return this.languageFilter
.split(",")
.map((s) => s.trim())
.filter((s) => s !== "");
}
commandTestersForCourse(course: Course, commandToExecute: string, outputStreamType: string, expectedOutput: string): Promise<CommandTester[]> {
return Promise.all(course.latestDockerfiles.map((dockerfile) => new CommandTester(course, dockerfile, commandToExecute, outputStreamType, expectedOutput)));
}
}