Give testing a shot
This commit is contained in:
parent
ba21821df7
commit
9ec4d2741c
|
@ -229,6 +229,13 @@ export class Session {
|
||||||
}
|
}
|
||||||
await this.runCode(msg.code);
|
await this.runCode(msg.code);
|
||||||
break;
|
break;
|
||||||
|
case "testCode":
|
||||||
|
if (typeof msg.code !== "string") {
|
||||||
|
this.logBadMessage(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await this.runCode(msg.code, true, msg.expectedOutput);
|
||||||
|
break;
|
||||||
case "formatCode":
|
case "formatCode":
|
||||||
if (typeof msg.code !== "string") {
|
if (typeof msg.code !== "string") {
|
||||||
this.logBadMessage(msg);
|
this.logBadMessage(msg);
|
||||||
|
@ -279,7 +286,7 @@ export class Session {
|
||||||
await this.run(this.privilegedExec(`cat > ${file}`), { input: code });
|
await this.run(this.privilegedExec(`cat > ${file}`), { input: code });
|
||||||
};
|
};
|
||||||
|
|
||||||
runCode = async (code) => {
|
runCode = async (code, isTest = false, expectedOutput) => {
|
||||||
try {
|
try {
|
||||||
const { name, repl, suffix, createEmpty, compile, run, template } =
|
const { name, repl, suffix, createEmpty, compile, run, template } =
|
||||||
this.config;
|
this.config;
|
||||||
|
@ -322,7 +329,18 @@ export class Session {
|
||||||
// Capture term in closure so that we don't keep sending output
|
// Capture term in closure so that we don't keep sending output
|
||||||
// from the old pty even after it's been killed (see ghci).
|
// from the old pty even after it's been killed (see ghci).
|
||||||
if (term.live) {
|
if (term.live) {
|
||||||
this.send({ event: "terminalOutput", output: data.toString() });
|
if (isTest) {
|
||||||
|
this.send({
|
||||||
|
event: "testTerminalOutput",
|
||||||
|
output: data.toString(),
|
||||||
|
expectedOutput
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.send({
|
||||||
|
event: "terminalOutput",
|
||||||
|
output: data.toString()
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.term.pty.stderr.on("data", (data) => {
|
this.term.pty.stderr.on("data", (data) => {
|
||||||
|
|
|
@ -113,6 +113,40 @@ async function main() {
|
||||||
}
|
}
|
||||||
term.write(message.output);
|
term.write(message.output);
|
||||||
return;
|
return;
|
||||||
|
case "testTerminalOutput":
|
||||||
|
if (typeof message.output !== "string") {
|
||||||
|
console.error("Unexpected message from server:", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
term.write(message.output);
|
||||||
|
|
||||||
|
const pass = message.output == message.expectedOutput
|
||||||
|
|
||||||
|
window.parent.postMessage({
|
||||||
|
event: "total_test_start",
|
||||||
|
type: "test",
|
||||||
|
});
|
||||||
|
|
||||||
|
window.parent.postMessage({
|
||||||
|
$id: 0,
|
||||||
|
codesandbox: true,
|
||||||
|
event: "test_end",
|
||||||
|
test: {
|
||||||
|
blocks: ["Output"],
|
||||||
|
duration: 1,
|
||||||
|
errors: [],
|
||||||
|
name: `should be ${message.expectedOutput}.`,
|
||||||
|
path: "",
|
||||||
|
status: pass ? "pass" : "fail",
|
||||||
|
},
|
||||||
|
type: "test",
|
||||||
|
});
|
||||||
|
|
||||||
|
window.parent.postMessage({
|
||||||
|
event: "total_test_end",
|
||||||
|
type: "test",
|
||||||
|
});
|
||||||
|
return;
|
||||||
case "lspStopped":
|
case "lspStopped":
|
||||||
if (clientDisposable) {
|
if (clientDisposable) {
|
||||||
clientDisposable.dispose();
|
clientDisposable.dispose();
|
||||||
|
|
Loading…
Reference in New Issue