Move test data to app
This commit is contained in:
parent
58ef480e8e
commit
2b0396d555
|
@ -234,6 +234,8 @@ export class Session {
|
|||
this.logBadMessage(msg);
|
||||
break;
|
||||
}
|
||||
await this.runCode(msg.code)
|
||||
await this.runCode(msg.code, true, msg.expectedOutput);
|
||||
await this.runCode(msg.code, true, msg.expectedOutput);
|
||||
break;
|
||||
case "formatCode":
|
||||
|
@ -286,11 +288,7 @@ export class Session {
|
|||
await this.run(this.privilegedExec(`cat > ${file}`), { input: code });
|
||||
};
|
||||
|
||||
runCode = async (code, isTest = false, expectedOutput) => {
|
||||
console.log('runCode')
|
||||
console.log('code', code)
|
||||
console.log('isTest', isTest)
|
||||
console.log('expectedOutput', expectedOutput)
|
||||
runCode = async (code, isTest = false, expectedOutput, testData = []) => {
|
||||
try {
|
||||
const { name, repl, suffix, createEmpty, compile, run, template } =
|
||||
this.config;
|
||||
|
@ -329,22 +327,22 @@ export class Session {
|
|||
live: true,
|
||||
};
|
||||
this.term = term;
|
||||
|
||||
this.term.pty.stdout.on("end", () => {
|
||||
this.send({
|
||||
event: "stdout end",
|
||||
expectedOutput,
|
||||
isTest,
|
||||
});
|
||||
});
|
||||
this.term.pty.stdout.on("data", (data) => {
|
||||
// Capture term in closure so that we don't keep sending output
|
||||
// from the old pty even after it's been killed (see ghci).
|
||||
if (term.live) {
|
||||
if (isTest) {
|
||||
this.send({
|
||||
event: "testTerminalOutput",
|
||||
output: data.toString(),
|
||||
expectedOutput
|
||||
});
|
||||
} else {
|
||||
this.send({
|
||||
event: "terminalOutput",
|
||||
output: data.toString()
|
||||
});
|
||||
}
|
||||
this.send({
|
||||
event: "terminalOutput",
|
||||
output: data.toString(),
|
||||
});
|
||||
}
|
||||
});
|
||||
this.term.pty.stderr.on("data", (data) => {
|
||||
|
|
|
@ -573,8 +573,8 @@ async function getImageHash(tag) {
|
|||
const output = (
|
||||
await run(["docker", "inspect", `riju:${tag}`], console.error, {
|
||||
suppressOutput: true,
|
||||
})
|
||||
).output;
|
||||
}).output
|
||||
);
|
||||
return JSON.parse(output)[0].Config.Labels["riju.image-hash"];
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,13 @@ export async function run(args, log, options) {
|
|||
if (typeof input === "string") {
|
||||
proc.stdin.end(input);
|
||||
}
|
||||
let output = "";
|
||||
let output = "start\n";
|
||||
proc.stdout.on("data", (data) => {
|
||||
output += `${data}`;
|
||||
});
|
||||
proc.stdout.on("end", () => {
|
||||
output += "\nend"
|
||||
})
|
||||
proc.stderr.on("data", (data) => {
|
||||
output += `${data}`;
|
||||
});
|
||||
|
@ -74,6 +77,7 @@ export async function run(args, log, options) {
|
|||
proc.on("error", reject);
|
||||
proc.on("close", (code, signal) => {
|
||||
output = output.trim();
|
||||
console.log(output)
|
||||
if (output && !suppressOutput) {
|
||||
log(`Output from ${args[0]}:\n` + output);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ async function main() {
|
|||
} catch (e) {
|
||||
console.log("message error: ", e);
|
||||
}
|
||||
console.log("message from codeamigo", msg);
|
||||
});
|
||||
|
||||
function tryConnect() {
|
||||
|
@ -83,6 +82,7 @@ async function main() {
|
|||
socket.addEventListener("open", () => {
|
||||
console.log("Successfully connected to server");
|
||||
});
|
||||
let testData = [];
|
||||
socket.addEventListener("message", (event) => {
|
||||
let message;
|
||||
try {
|
||||
|
@ -112,7 +112,15 @@ async function main() {
|
|||
return;
|
||||
}
|
||||
term.write(message.output);
|
||||
testData.push(message.output);
|
||||
return;
|
||||
case "stdout end":
|
||||
console.log(testData);
|
||||
console.log(msg.isTest);
|
||||
console.log(msg.expectedOutput);
|
||||
console.log(testData);
|
||||
testData = [];
|
||||
return
|
||||
case "testTerminalOutput":
|
||||
if (typeof message.output !== "string") {
|
||||
console.error("Unexpected message from server:", message);
|
||||
|
@ -120,32 +128,46 @@ async function main() {
|
|||
}
|
||||
term.write(message.output);
|
||||
|
||||
const pass = message.output.replace(/\r\n/g, '') == message.expectedOutput
|
||||
|
||||
window.parent.postMessage({
|
||||
event: "total_test_start",
|
||||
type: "test",
|
||||
}, "*");
|
||||
const pass =
|
||||
message.output.replace(/\r\n/g, "") == message.expectedOutput;
|
||||
|
||||
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",
|
||||
window.parent.postMessage(
|
||||
{
|
||||
event: "total_test_start",
|
||||
type: "test",
|
||||
},
|
||||
type: "test",
|
||||
}, "*");
|
||||
"*"
|
||||
);
|
||||
|
||||
window.parent.postMessage({
|
||||
event: "total_test_end",
|
||||
type: "test",
|
||||
}, "*");
|
||||
window.parent.postMessage(
|
||||
{
|
||||
$id: 0,
|
||||
codesandbox: true,
|
||||
event: "test_end",
|
||||
test: {
|
||||
blocks: ["Output"],
|
||||
duration: 1,
|
||||
errors: [
|
||||
`${message.output.replace(/\r\n/g, "")} did not equal ${
|
||||
message.expectedOutput
|
||||
}`,
|
||||
],
|
||||
name: `should be ${message.expectedOutput}.`,
|
||||
path: "",
|
||||
status: pass ? "pass" : "fail",
|
||||
},
|
||||
type: "test",
|
||||
},
|
||||
"*"
|
||||
);
|
||||
|
||||
window.parent.postMessage(
|
||||
{
|
||||
event: "total_test_end",
|
||||
type: "test",
|
||||
},
|
||||
"*"
|
||||
);
|
||||
return;
|
||||
case "lspStopped":
|
||||
if (clientDisposable) {
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
id: "javascript"
|
||||
aliases:
|
||||
- "node"
|
||||
- "js"
|
||||
- "web"
|
||||
- "jsx"
|
||||
- "v8"
|
||||
- "closure"
|
||||
- "nodejs"
|
||||
name: "JavaScript"
|
||||
monacoLang: javascript
|
||||
|
||||
install:
|
||||
apt:
|
||||
- nodejs
|
||||
- yarn
|
||||
riju:
|
||||
- prettier
|
||||
|
||||
repl: |
|
||||
node
|
||||
|
||||
main: "main.js"
|
||||
template: |
|
||||
console.log("Hello, world!");
|
||||
|
||||
run: |
|
||||
node -e "$(< main.js)" -i
|
||||
|
||||
scope:
|
||||
code: |
|
||||
let x = 123 * 234;
|
||||
|
||||
format:
|
||||
run: |
|
||||
prettier --no-config --stdin-filepath=format.js
|
||||
input: |
|
||||
console.log('Hello, world!');
|
||||
|
||||
pkg:
|
||||
install: |
|
||||
yarn add NAME
|
||||
|
||||
uninstall: |
|
||||
yarn remove NAME
|
||||
|
||||
search: |
|
||||
curl -sS 'https://registry.npmjs.org/-/v1/search?text=NAME' | jq -r '.objects | map(.package.name) | .[]'
|
Loading…
Reference in New Issue