From 80243acc3757121e649609226aa4edae85a7c5a2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 29 Mar 2018 14:49:36 -0700 Subject: [PATCH] Fix running node tests --- crates/test-support/src/lib.rs | 13 +++++-------- tests/node.rs | 20 ++++++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/crates/test-support/src/lib.rs b/crates/test-support/src/lib.rs index ca20e94ef..4330411b3 100644 --- a/crates/test-support/src/lib.rs +++ b/crates/test-support/src/lib.rs @@ -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 { diff --git a/tests/node.rs b/tests/node.rs index 71945434a..bb828863f 100644 --- a/tests/node.rs +++ b/tests/node.rs @@ -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); }; "#)