Skip to content

Commit

Permalink
added js runtimes test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobgetz committed Feb 8, 2024
1 parent 1537842 commit a1df369
Show file tree
Hide file tree
Showing 7 changed files with 15,109 additions and 14,059 deletions.
13 changes: 9 additions & 4 deletions crates/replay_gen/src/jsgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::{
pub fn generate_replay_javascript(out_path: &Path, code: &Replay) -> std::io::Result<()> {
let mut file = File::create(&out_path)?;
let stream = &mut file;
write(stream, "import fs from 'fs'\n")?;
write(stream, "import path from 'path'\n")?;
// write(stream, "import fs from 'fs'\n")?;
// write(stream, "import path from 'path'\n")?;
write(stream, "let instance\n")?;
write(stream, "let imports = {}\n")?;

Expand Down Expand Up @@ -127,7 +127,12 @@ pub fn generate_replay_javascript(out_path: &Path, code: &Replay) -> std::io::Re
"return WebAssembly.instantiate(wasmBinary, imports)\n",
)?;
write(stream, "}\n")?;
write(stream, "if (process.argv[2] === 'run') {\n")?;
write(stream, "let firstArg\n")?;
write(stream, "if (typeof Deno === 'undefined'){firstArg=process.argv[2]}else{firstArg=Deno.args[0]}\n")?;
write(stream, "if (firstArg === 'run') {\n")?;
write(stream, "let nodeModules;\n")?;
write(stream, "if (typeof Deno === 'undefined') { nodeModules = Promise.all([import('path'),import('fs')])}else{nodeModules=Promise.all([import('node:path'),import('node:fs')])}\n")?;
write(stream, "nodeModules.then(([path,fs])=>{")?;
write(
stream,
"const p = path.join(path.dirname(import.meta.url).replace(/^file:/, ''), 'index.wasm')\n",
Expand All @@ -137,7 +142,7 @@ pub fn generate_replay_javascript(out_path: &Path, code: &Replay) -> std::io::Re
stream,
"instantiate(wasmBinary).then((wasm) => replay(wasm))\n",
)?;
write(stream, "}\n")?;
write(stream, "})}\n")?;
Ok(())
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"build-full": "npm run build-rust && npm run build-wasabi && npm run build",
"test": "npm run build-rust && npm run build && node ./dist/tests/run-tests.cjs",
"clean-tests": "node ./dist/tests/clean-tests.cjs",
"start": "npm run build && node ./dist/src/cli/main.cjs"
"start": "npm run build && node ./dist/src/cli/main.cjs",
"eval-port-js": "npm run build && node ./dist/tests/test-js-runtimes.cjs"
}
}
Loading

0 comments on commit a1df369

Please sign in to comment.