Skip to content

Commit 3bccad9

Browse files
Merge branch 'master' into build
2 parents 022b787 + 425aefb commit 3bccad9

File tree

8 files changed

+101
-105
lines changed

8 files changed

+101
-105
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ This tool seeks to be a one-stop shop for building and working with rust-
99
generated WebAssembly that you would like to interop with JavaScript, in the
1010
browser or with Node.js. `wasm-pack` helps you build and publish rust-generated
1111
WebAssembly to the npm registry to be used alongside any other javascript
12-
package in workflows that you already use, such as a bundler like
13-
[webpack] or [greenkeeper].
12+
package in workflows that you already use, such as [webpack] or [greenkeeper].
1413

1514
[bundler-support]: https://github.com/rustwasm/team/blob/master/goals/bundler-integration.md#details
1615
[webpack]: https://webpack.js.org/
@@ -32,8 +31,8 @@ visiting that repo!
3231

3332
- [`init`](docs/init.md): [**Deprecated**] Initialize an npm wasm pkg from a rustwasm crate
3433
- [`build`](docs/build.md): Generate an npm wasm pkg from a rustwasm crate
35-
- [`pack`](docs/pack.md): Create a tarball of your rustwasm pkg
36-
- [`publish`](docs/publish.md): Publish your rustwasm pkg to a registry
34+
- [`init`](docs/init.md): Generate an npm wasm pkg from a rustwasm crate
35+
- [`pack` and `publish`](docs/pack-and-publish.md): Create a tarball of your rustwasm pkg and/or publish to a registry
3736

3837
## 📝 Logging
3938

tests/all/manifest.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashSet;
22
use std::fs;
33
use std::path::PathBuf;
44

5-
use utils;
5+
use utils::{self, fixture};
66
use wasm_pack::{self, manifest};
77

88
#[test]
@@ -53,7 +53,7 @@ fn it_recognizes_a_map_during_depcheck() {
5353

5454
#[test]
5555
fn it_creates_a_package_json_default_path() {
56-
let fixture = utils::fixture(".");
56+
let fixture = fixture::fixture(".");
5757
let step = wasm_pack::progressbar::Step::new(1);
5858
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
5959
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
@@ -81,7 +81,7 @@ fn it_creates_a_package_json_default_path() {
8181

8282
#[test]
8383
fn it_creates_a_package_json_provided_path() {
84-
let fixture = utils::fixture("tests/fixtures/js-hello-world");
84+
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
8585
let step = wasm_pack::progressbar::Step::new(1);
8686
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
8787
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
@@ -102,7 +102,7 @@ fn it_creates_a_package_json_provided_path() {
102102

103103
#[test]
104104
fn it_creates_a_package_json_provided_path_with_scope() {
105-
let fixture = utils::fixture("tests/fixtures/scopes");
105+
let fixture = fixture::fixture("tests/fixtures/scopes");
106106
let step = wasm_pack::progressbar::Step::new(1);
107107
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
108108
assert!(
@@ -126,7 +126,7 @@ fn it_creates_a_package_json_provided_path_with_scope() {
126126

127127
#[test]
128128
fn it_creates_a_pkg_json_with_correct_files_on_node() {
129-
let fixture = utils::fixture(".");
129+
let fixture = fixture::fixture(".");
130130
let step = wasm_pack::progressbar::Step::new(1);
131131
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
132132
assert!(manifest::write_package_json(&fixture.path, &None, false, "nodejs", &step).is_ok());
@@ -155,7 +155,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
155155

156156
#[test]
157157
fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
158-
let fixture = utils::fixture(".");
158+
let fixture = fixture::fixture(".");
159159
let step = wasm_pack::progressbar::Step::new(1);
160160
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
161161
assert!(manifest::write_package_json(&fixture.path, &None, true, "", &step).is_ok());
@@ -181,14 +181,14 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
181181

182182
#[test]
183183
fn it_errors_when_wasm_bindgen_is_not_declared() {
184-
let fixture = utils::fixture("tests/fixtures/bad-cargo-toml");
184+
let fixture = fixture::fixture("tests/fixtures/bad-cargo-toml");
185185
let step = wasm_pack::progressbar::Step::new(1);
186186
assert!(manifest::check_crate_config(&fixture.path, &step).is_err());
187187
}
188188

189189
#[test]
190190
fn it_does_not_error_when_wasm_bindgen_is_declared() {
191-
let fixture = utils::fixture("tests/fixtures/js-hello-world");
191+
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
192192
let step = wasm_pack::progressbar::Step::new(1);
193193
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok());
194194
}

tests/all/readme.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ extern crate wasm_pack;
33

44
use std::fs;
55

6-
use utils;
6+
use utils::{self, fixture};
77
use wasm_pack::readme;
88

99
#[test]
1010
fn it_copies_a_readme_default_path() {
11-
let fixture = utils::fixture(".");
11+
let fixture = fixture::fixture(".");
1212
fs::create_dir(fixture.path.join("pkg")).expect("should create pkg directory OK");
1313

1414
let step = wasm_pack::progressbar::Step::new(1);
@@ -25,14 +25,14 @@ fn it_copies_a_readme_default_path() {
2525

2626
assert!(fs::metadata(&pkg_readme_path).is_ok());
2727

28-
let crate_readme = utils::readme::read_file(&crate_readme_path).unwrap();
29-
let pkg_readme = utils::readme::read_file(&pkg_readme_path).unwrap();
28+
let crate_readme = utils::file::read_file(&crate_readme_path).unwrap();
29+
let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap();
3030
assert_eq!(crate_readme, pkg_readme);
3131
}
3232

3333
#[test]
3434
fn it_creates_a_package_json_provided_path() {
35-
let fixture = utils::fixture("tests/fixtures/js-hello-world");
35+
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
3636
fs::create_dir(fixture.path.join("pkg")).expect("should create pkg directory OK");
3737

3838
let step = wasm_pack::progressbar::Step::new(1);
@@ -47,7 +47,7 @@ fn it_creates_a_package_json_provided_path() {
4747
assert!(fs::metadata(&crate_readme_path).is_ok());
4848
assert!(fs::metadata(&pkg_readme_path).is_ok());
4949

50-
let crate_readme = utils::readme::read_file(&crate_readme_path).unwrap();
51-
let pkg_readme = utils::readme::read_file(&pkg_readme_path).unwrap();
50+
let crate_readme = utils::file::read_file(&crate_readme_path).unwrap();
51+
let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap();
5252
assert_eq!(crate_readme, pkg_readme);
5353
}

tests/all/utils.rs

Lines changed: 0 additions & 86 deletions
This file was deleted.

tests/all/utils/file.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::fs::File;
2+
use std::io::Read;
3+
use std::path::Path;
4+
5+
use failure::Error;
6+
7+
pub fn read_file(path: &Path) -> Result<String, Error> {
8+
let mut file = File::open(path)?;
9+
let mut contents = String::new();
10+
file.read_to_string(&mut contents)?;
11+
12+
Ok(contents)
13+
}

tests/all/utils/fixture.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use copy_dir::copy_dir;
4+
use tempfile;
5+
6+
pub struct Fixture {
7+
pub dir: tempfile::TempDir,
8+
pub path: PathBuf,
9+
}
10+
11+
/// Copy the given fixture into a unique temporary directory. This allows the
12+
/// test to mutate the copied fixture without messing up other tests that are
13+
/// also trying to read from or write to that fixture. The given path should be
14+
/// relative from the root of the repository, eg
15+
/// "tests/fixtures/im-from-brooklyn-the-place-where-stars-are-born".
16+
pub fn fixture<P>(fixture: P) -> Fixture
17+
where
18+
P: AsRef<Path>,
19+
{
20+
let fixture = fixture
21+
.as_ref()
22+
.canonicalize()
23+
.expect("should canonicalize fixture path OK");
24+
let dir = tempfile::tempdir().expect("should create temporary directory OK");
25+
let path = dir.path().join("wasm-pack");
26+
println!(
27+
"wasm-pack: copying test fixture '{}' to temporary directory '{}'",
28+
fixture.display(),
29+
path.display()
30+
);
31+
copy_dir(fixture, &path).expect("should copy fixture directory into temporary directory OK");
32+
Fixture { dir, path }
33+
}

tests/all/utils/manifest.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use std::fs::File;
2+
use std::io::prelude::*;
3+
use std::path::Path;
4+
5+
use failure::Error;
6+
use serde_json;
7+
8+
#[derive(Deserialize)]
9+
pub struct NpmPackage {
10+
pub name: String,
11+
pub description: String,
12+
pub version: String,
13+
pub license: String,
14+
pub repository: Repository,
15+
pub files: Vec<String>,
16+
pub main: String,
17+
pub types: Option<String>,
18+
}
19+
20+
#[derive(Deserialize)]
21+
pub struct Repository {
22+
#[serde(rename = "type")]
23+
pub ty: String,
24+
pub url: String,
25+
}
26+
27+
pub fn read_package_json(path: &Path) -> Result<NpmPackage, Error> {
28+
let manifest_path = path.join("pkg").join("package.json");
29+
let mut pkg_file = File::open(manifest_path)?;
30+
let mut pkg_contents = String::new();
31+
pkg_file.read_to_string(&mut pkg_contents)?;
32+
33+
Ok(serde_json::from_str(&pkg_contents)?)
34+
}

tests/all/utils/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod file;
2+
pub mod fixture;
3+
pub mod manifest;

0 commit comments

Comments
 (0)