Move test data to app
This commit is contained in:
parent
58ef480e8e
commit
2b0396d555
|
@ -234,6 +234,8 @@ export class Session {
|
||||||
this.logBadMessage(msg);
|
this.logBadMessage(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
await this.runCode(msg.code)
|
||||||
|
await this.runCode(msg.code, true, msg.expectedOutput);
|
||||||
await this.runCode(msg.code, true, msg.expectedOutput);
|
await this.runCode(msg.code, true, msg.expectedOutput);
|
||||||
break;
|
break;
|
||||||
case "formatCode":
|
case "formatCode":
|
||||||
|
@ -286,11 +288,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, isTest = false, expectedOutput) => {
|
runCode = async (code, isTest = false, expectedOutput, testData = []) => {
|
||||||
console.log('runCode')
|
|
||||||
console.log('code', code)
|
|
||||||
console.log('isTest', isTest)
|
|
||||||
console.log('expectedOutput', expectedOutput)
|
|
||||||
try {
|
try {
|
||||||
const { name, repl, suffix, createEmpty, compile, run, template } =
|
const { name, repl, suffix, createEmpty, compile, run, template } =
|
||||||
this.config;
|
this.config;
|
||||||
|
@ -329,23 +327,23 @@ export class Session {
|
||||||
live: true,
|
live: true,
|
||||||
};
|
};
|
||||||
this.term = term;
|
this.term = term;
|
||||||
|
|
||||||
|
this.term.pty.stdout.on("end", () => {
|
||||||
|
this.send({
|
||||||
|
event: "stdout end",
|
||||||
|
expectedOutput,
|
||||||
|
isTest,
|
||||||
|
});
|
||||||
|
});
|
||||||
this.term.pty.stdout.on("data", (data) => {
|
this.term.pty.stdout.on("data", (data) => {
|
||||||
// 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) {
|
||||||
if (isTest) {
|
|
||||||
this.send({
|
|
||||||
event: "testTerminalOutput",
|
|
||||||
output: data.toString(),
|
|
||||||
expectedOutput
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.send({
|
this.send({
|
||||||
event: "terminalOutput",
|
event: "terminalOutput",
|
||||||
output: data.toString()
|
output: data.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.term.pty.stderr.on("data", (data) => {
|
this.term.pty.stderr.on("data", (data) => {
|
||||||
if (term.live) {
|
if (term.live) {
|
||||||
|
|
|
@ -573,8 +573,8 @@ async function getImageHash(tag) {
|
||||||
const output = (
|
const output = (
|
||||||
await run(["docker", "inspect", `riju:${tag}`], console.error, {
|
await run(["docker", "inspect", `riju:${tag}`], console.error, {
|
||||||
suppressOutput: true,
|
suppressOutput: true,
|
||||||
})
|
}).output
|
||||||
).output;
|
);
|
||||||
return JSON.parse(output)[0].Config.Labels["riju.image-hash"];
|
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") {
|
if (typeof input === "string") {
|
||||||
proc.stdin.end(input);
|
proc.stdin.end(input);
|
||||||
}
|
}
|
||||||
let output = "";
|
let output = "start\n";
|
||||||
proc.stdout.on("data", (data) => {
|
proc.stdout.on("data", (data) => {
|
||||||
output += `${data}`;
|
output += `${data}`;
|
||||||
});
|
});
|
||||||
|
proc.stdout.on("end", () => {
|
||||||
|
output += "\nend"
|
||||||
|
})
|
||||||
proc.stderr.on("data", (data) => {
|
proc.stderr.on("data", (data) => {
|
||||||
output += `${data}`;
|
output += `${data}`;
|
||||||
});
|
});
|
||||||
|
@ -74,6 +77,7 @@ export async function run(args, log, options) {
|
||||||
proc.on("error", reject);
|
proc.on("error", reject);
|
||||||
proc.on("close", (code, signal) => {
|
proc.on("close", (code, signal) => {
|
||||||
output = output.trim();
|
output = output.trim();
|
||||||
|
console.log(output)
|
||||||
if (output && !suppressOutput) {
|
if (output && !suppressOutput) {
|
||||||
log(`Output from ${args[0]}:\n` + output);
|
log(`Output from ${args[0]}:\n` + output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ async function main() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("message error: ", e);
|
console.log("message error: ", e);
|
||||||
}
|
}
|
||||||
console.log("message from codeamigo", msg);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function tryConnect() {
|
function tryConnect() {
|
||||||
|
@ -83,6 +82,7 @@ async function main() {
|
||||||
socket.addEventListener("open", () => {
|
socket.addEventListener("open", () => {
|
||||||
console.log("Successfully connected to server");
|
console.log("Successfully connected to server");
|
||||||
});
|
});
|
||||||
|
let testData = [];
|
||||||
socket.addEventListener("message", (event) => {
|
socket.addEventListener("message", (event) => {
|
||||||
let message;
|
let message;
|
||||||
try {
|
try {
|
||||||
|
@ -112,7 +112,15 @@ async function main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
term.write(message.output);
|
term.write(message.output);
|
||||||
|
testData.push(message.output);
|
||||||
return;
|
return;
|
||||||
|
case "stdout end":
|
||||||
|
console.log(testData);
|
||||||
|
console.log(msg.isTest);
|
||||||
|
console.log(msg.expectedOutput);
|
||||||
|
console.log(testData);
|
||||||
|
testData = [];
|
||||||
|
return
|
||||||
case "testTerminalOutput":
|
case "testTerminalOutput":
|
||||||
if (typeof message.output !== "string") {
|
if (typeof message.output !== "string") {
|
||||||
console.error("Unexpected message from server:", message);
|
console.error("Unexpected message from server:", message);
|
||||||
|
@ -120,32 +128,46 @@ async function main() {
|
||||||
}
|
}
|
||||||
term.write(message.output);
|
term.write(message.output);
|
||||||
|
|
||||||
const pass = message.output.replace(/\r\n/g, '') == message.expectedOutput
|
const pass =
|
||||||
|
message.output.replace(/\r\n/g, "") == message.expectedOutput;
|
||||||
|
|
||||||
window.parent.postMessage({
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
event: "total_test_start",
|
event: "total_test_start",
|
||||||
type: "test",
|
type: "test",
|
||||||
}, "*");
|
},
|
||||||
|
"*"
|
||||||
|
);
|
||||||
|
|
||||||
window.parent.postMessage({
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
$id: 0,
|
$id: 0,
|
||||||
codesandbox: true,
|
codesandbox: true,
|
||||||
event: "test_end",
|
event: "test_end",
|
||||||
test: {
|
test: {
|
||||||
blocks: ["Output"],
|
blocks: ["Output"],
|
||||||
duration: 1,
|
duration: 1,
|
||||||
errors: [],
|
errors: [
|
||||||
|
`${message.output.replace(/\r\n/g, "")} did not equal ${
|
||||||
|
message.expectedOutput
|
||||||
|
}`,
|
||||||
|
],
|
||||||
name: `should be ${message.expectedOutput}.`,
|
name: `should be ${message.expectedOutput}.`,
|
||||||
path: "",
|
path: "",
|
||||||
status: pass ? "pass" : "fail",
|
status: pass ? "pass" : "fail",
|
||||||
},
|
},
|
||||||
type: "test",
|
type: "test",
|
||||||
}, "*");
|
},
|
||||||
|
"*"
|
||||||
|
);
|
||||||
|
|
||||||
window.parent.postMessage({
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
event: "total_test_end",
|
event: "total_test_end",
|
||||||
type: "test",
|
type: "test",
|
||||||
}, "*");
|
},
|
||||||
|
"*"
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
case "lspStopped":
|
case "lspStopped":
|
||||||
if (clientDisposable) {
|
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