mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 19:11:45 +03:00
Fix running node tests
This commit is contained in:
parent
646df20d70
commit
80243acc37
@ -63,6 +63,10 @@ pub fn project() -> Project {
|
|||||||
});
|
});
|
||||||
"#.to_string()),
|
"#.to_string()),
|
||||||
|
|
||||||
|
("run-node.js".to_string(), r#"
|
||||||
|
require("./test").test();
|
||||||
|
"#.to_string()),
|
||||||
|
|
||||||
("webpack.config.js".to_string(), r#"
|
("webpack.config.js".to_string(), r#"
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
@ -180,13 +184,6 @@ impl Project {
|
|||||||
|
|
||||||
let idx = IDX.with(|x| *x);
|
let idx = IDX.with(|x| *x);
|
||||||
let mut out = target_dir.join(&format!("wasm32-unknown-unknown/debug/test{}.wasm", idx));
|
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");
|
let as_a_module = root.join("out.wasm");
|
||||||
fs::copy(&out, &as_a_module).unwrap();
|
fs::copy(&out, &as_a_module).unwrap();
|
||||||
@ -219,7 +216,7 @@ impl Project {
|
|||||||
|
|
||||||
if self.node {
|
if self.node {
|
||||||
let mut cmd = Command::new("node");
|
let mut cmd = Command::new("node");
|
||||||
cmd.arg(root.join("out.js"))
|
cmd.arg(root.join("run-node.js"))
|
||||||
.current_dir(&root);
|
.current_dir(&root);
|
||||||
run(&mut cmd, "node");
|
run(&mut cmd, "node");
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,7 +25,7 @@ fn works() {
|
|||||||
pub struct Foo {
|
pub struct Foo {
|
||||||
contents: u32,
|
contents: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl Foo {
|
impl Foo {
|
||||||
pub fn new() -> Foo {
|
pub fn new() -> Foo {
|
||||||
@ -57,7 +57,6 @@ fn works() {
|
|||||||
"#)
|
"#)
|
||||||
.file("test.js", r#"
|
.file("test.js", r#"
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const run = require('./out');
|
|
||||||
|
|
||||||
var called = false;
|
var called = false;
|
||||||
|
|
||||||
@ -65,32 +64,29 @@ fn works() {
|
|||||||
called = true;
|
called = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { run, Foo, Color, cycle } = require('./out');
|
||||||
|
|
||||||
module.exports.test = function() {
|
module.exports.test = function() {
|
||||||
run();
|
run();
|
||||||
assert.strictEqual(called, true);
|
assert.strictEqual(called, true);
|
||||||
var Foo = run.Foo;
|
|
||||||
|
|
||||||
var r = Foo.new();
|
var r = Foo.new();
|
||||||
assert.strictEqual(r.contents, 0);
|
|
||||||
assert.strictEqual(r.add(0), 0);
|
assert.strictEqual(r.add(0), 0);
|
||||||
assert.strictEqual(r.add(1), 1);
|
assert.strictEqual(r.add(1), 1);
|
||||||
assert.strictEqual(r.add(2), 2);
|
assert.strictEqual(r.add(2), 3);
|
||||||
r.free();
|
r.free();
|
||||||
|
|
||||||
var r2 = Foo.with_contents(10);
|
var r2 = Foo.with_contents(10);
|
||||||
assert.strictEqual(r2.contents, 10);
|
assert.strictEqual(r2.add(0), 10);
|
||||||
assert.strictEqual(r2.add(0), 0);
|
assert.strictEqual(r2.add(1), 11);
|
||||||
assert.strictEqual(r2.add(1), 1);
|
assert.strictEqual(r2.add(2), 13);
|
||||||
assert.strictEqual(r2.add(2), 2);
|
|
||||||
r2.free();
|
r2.free();
|
||||||
|
|
||||||
var Color = run.Color;
|
|
||||||
|
|
||||||
assert.strictEqual(Color.Green, 0);
|
assert.strictEqual(Color.Green, 0);
|
||||||
assert.strictEqual(Color.Yellow, 1);
|
assert.strictEqual(Color.Yellow, 1);
|
||||||
assert.strictEqual(Color.Red, 2);
|
assert.strictEqual(Color.Red, 2);
|
||||||
assert.strictEqual(Object.keys(Color).length, 3);
|
assert.strictEqual(Object.keys(Color).length, 3);
|
||||||
assert.strictEqual(Color.cycle(Color.Green), Color.Yellow);
|
assert.strictEqual(cycle(Color.Green), Color.Yellow);
|
||||||
};
|
};
|
||||||
|
|
||||||
"#)
|
"#)
|
||||||
|
Loading…
Reference in New Issue
Block a user