diff --git a/backend/api.js b/backend/api.js index cb4c806..5b9b621 100644 --- a/backend/api.js +++ b/backend/api.js @@ -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) => { diff --git a/backend/test-runner.js b/backend/test-runner.js index 3ca350f..2e63b9b 100644 --- a/backend/test-runner.js +++ b/backend/test-runner.js @@ -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"]; } diff --git a/backend/util.js b/backend/util.js index 4e5d7b4..6e672e8 100644 --- a/backend/util.js +++ b/backend/util.js @@ -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); } diff --git a/frontend/src/app.js b/frontend/src/app.js index 9e4c4b4..1115bb2 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -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) { diff --git a/langs/javascript.yaml b/langs/javascript.yaml new file mode 100644 index 0000000..adb7bcc --- /dev/null +++ b/langs/javascript.yaml @@ -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) | .[]' \ No newline at end of file