Fix running node tests

This commit is contained in:
Alex Crichton 2018-03-29 14:49:36 -07:00
parent 646df20d70
commit 80243acc37
2 changed files with 13 additions and 20 deletions

View File

@ -63,6 +63,10 @@ pub fn project() -> Project {
});
"#.to_string()),
("run-node.js".to_string(), r#"
require("./test").test();
"#.to_string()),
("webpack.config.js".to_string(), r#"
const path = require('path');
@ -180,13 +184,6 @@ impl Project {
let idx = IDX.with(|x| *x);
let mut out = target_dir.join(&format!("wasm32-unknown-unknown/debug/test{}.wasm", idx));
if Command::new("wasm-gc").output().is_ok() {
let tmp = out;
out = tmp.with_extension("gc.wasm");
let mut cmd = Command::new("wasm-gc");
cmd.arg(&tmp).arg(&out);
run(&mut cmd, "wasm-gc");
}
let as_a_module = root.join("out.wasm");
fs::copy(&out, &as_a_module).unwrap();
@ -219,7 +216,7 @@ impl Project {
if self.node {
let mut cmd = Command::new("node");
cmd.arg(root.join("out.js"))
cmd.arg(root.join("run-node.js"))
.current_dir(&root);
run(&mut cmd, "node");
} else {

View File

@ -25,7 +25,7 @@ fn works() {
pub struct Foo {
contents: u32,
}
#[wasm_bindgen]
impl Foo {
pub fn new() -> Foo {
@ -57,7 +57,6 @@ fn works() {
"#)
.file("test.js", r#"
const assert = require('assert');
const run = require('./out');
var called = false;
@ -65,32 +64,29 @@ fn works() {
called = true;
};
const { run, Foo, Color, cycle } = require('./out');
module.exports.test = function() {
run();
assert.strictEqual(called, true);
var Foo = run.Foo;
var r = Foo.new();
assert.strictEqual(r.contents, 0);
assert.strictEqual(r.add(0), 0);
assert.strictEqual(r.add(1), 1);
assert.strictEqual(r.add(2), 2);
assert.strictEqual(r.add(2), 3);
r.free();
var r2 = Foo.with_contents(10);
assert.strictEqual(r2.contents, 10);
assert.strictEqual(r2.add(0), 0);
assert.strictEqual(r2.add(1), 1);
assert.strictEqual(r2.add(2), 2);
assert.strictEqual(r2.add(0), 10);
assert.strictEqual(r2.add(1), 11);
assert.strictEqual(r2.add(2), 13);
r2.free();
var Color = run.Color;
assert.strictEqual(Color.Green, 0);
assert.strictEqual(Color.Yellow, 1);
assert.strictEqual(Color.Red, 2);
assert.strictEqual(Object.keys(Color).length, 3);
assert.strictEqual(Color.cycle(Color.Green), Color.Yellow);
assert.strictEqual(cycle(Color.Green), Color.Yellow);
};
"#)