Merge branch 'master' into build

master
ashley williams 7 years ago committed by GitHub
commit 3bccad94ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      README.md
  2. 16
      tests/all/manifest.rs
  3. 14
      tests/all/readme.rs
  4. 86
      tests/all/utils.rs
  5. 13
      tests/all/utils/file.rs
  6. 33
      tests/all/utils/fixture.rs
  7. 34
      tests/all/utils/manifest.rs
  8. 3
      tests/all/utils/mod.rs

@ -9,8 +9,7 @@ This tool seeks to be a one-stop shop for building and working with rust-
generated WebAssembly that you would like to interop with JavaScript, in the
browser or with Node.js. `wasm-pack` helps you build and publish rust-generated
WebAssembly to the npm registry to be used alongside any other javascript
package in workflows that you already use, such as a bundler like
[webpack] or [greenkeeper].
package in workflows that you already use, such as [webpack] or [greenkeeper].
[bundler-support]: https://github.com/rustwasm/team/blob/master/goals/bundler-integration.md#details
[webpack]: https://webpack.js.org/
@ -32,8 +31,8 @@ visiting that repo!
- [`init`](docs/init.md): [**Deprecated**] Initialize an npm wasm pkg from a rustwasm crate
- [`build`](docs/build.md): Generate an npm wasm pkg from a rustwasm crate
- [`pack`](docs/pack.md): Create a tarball of your rustwasm pkg
- [`publish`](docs/publish.md): Publish your rustwasm pkg to a registry
- [`init`](docs/init.md): Generate an npm wasm pkg from a rustwasm crate
- [`pack` and `publish`](docs/pack-and-publish.md): Create a tarball of your rustwasm pkg and/or publish to a registry
## 📝 Logging

@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;
use utils;
use utils::{self, fixture};
use wasm_pack::{self, manifest};
#[test]
@ -53,7 +53,7 @@ fn it_recognizes_a_map_during_depcheck() {
#[test]
fn it_creates_a_package_json_default_path() {
let fixture = utils::fixture(".");
let fixture = fixture::fixture(".");
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
@ -81,7 +81,7 @@ fn it_creates_a_package_json_default_path() {
#[test]
fn it_creates_a_package_json_provided_path() {
let fixture = utils::fixture("tests/fixtures/js-hello-world");
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
@ -102,7 +102,7 @@ fn it_creates_a_package_json_provided_path() {
#[test]
fn it_creates_a_package_json_provided_path_with_scope() {
let fixture = utils::fixture("tests/fixtures/scopes");
let fixture = fixture::fixture("tests/fixtures/scopes");
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(
@ -126,7 +126,7 @@ fn it_creates_a_package_json_provided_path_with_scope() {
#[test]
fn it_creates_a_pkg_json_with_correct_files_on_node() {
let fixture = utils::fixture(".");
let fixture = fixture::fixture(".");
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
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() {
#[test]
fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
let fixture = utils::fixture(".");
let fixture = fixture::fixture(".");
let step = wasm_pack::progressbar::Step::new(1);
wasm_pack::command::utils::create_pkg_dir(&fixture.path, &step).unwrap();
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() {
#[test]
fn it_errors_when_wasm_bindgen_is_not_declared() {
let fixture = utils::fixture("tests/fixtures/bad-cargo-toml");
let fixture = fixture::fixture("tests/fixtures/bad-cargo-toml");
let step = wasm_pack::progressbar::Step::new(1);
assert!(manifest::check_crate_config(&fixture.path, &step).is_err());
}
#[test]
fn it_does_not_error_when_wasm_bindgen_is_declared() {
let fixture = utils::fixture("tests/fixtures/js-hello-world");
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
let step = wasm_pack::progressbar::Step::new(1);
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok());
}

@ -3,12 +3,12 @@ extern crate wasm_pack;
use std::fs;
use utils;
use utils::{self, fixture};
use wasm_pack::readme;
#[test]
fn it_copies_a_readme_default_path() {
let fixture = utils::fixture(".");
let fixture = fixture::fixture(".");
fs::create_dir(fixture.path.join("pkg")).expect("should create pkg directory OK");
let step = wasm_pack::progressbar::Step::new(1);
@ -25,14 +25,14 @@ fn it_copies_a_readme_default_path() {
assert!(fs::metadata(&pkg_readme_path).is_ok());
let crate_readme = utils::readme::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::readme::read_file(&pkg_readme_path).unwrap();
let crate_readme = utils::file::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap();
assert_eq!(crate_readme, pkg_readme);
}
#[test]
fn it_creates_a_package_json_provided_path() {
let fixture = utils::fixture("tests/fixtures/js-hello-world");
let fixture = fixture::fixture("tests/fixtures/js-hello-world");
fs::create_dir(fixture.path.join("pkg")).expect("should create pkg directory OK");
let step = wasm_pack::progressbar::Step::new(1);
@ -47,7 +47,7 @@ fn it_creates_a_package_json_provided_path() {
assert!(fs::metadata(&crate_readme_path).is_ok());
assert!(fs::metadata(&pkg_readme_path).is_ok());
let crate_readme = utils::readme::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::readme::read_file(&pkg_readme_path).unwrap();
let crate_readme = utils::file::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap();
assert_eq!(crate_readme, pkg_readme);
}

@ -1,86 +0,0 @@
use std::path::{Path, PathBuf};
use copy_dir::copy_dir;
use tempfile;
/// Copy the given fixture into a unique temporary directory. This allows the
/// test to mutate the copied fixture without messing up other tests that are
/// also trying to read from or write to that fixture. The given path should be
/// relative from the root of the repository, eg
/// "tests/fixtures/im-from-brooklyn-the-place-where-stars-are-born".
pub fn fixture<P>(fixture: P) -> Fixture
where
P: AsRef<Path>,
{
let fixture = fixture
.as_ref()
.canonicalize()
.expect("should canonicalize fixture path OK");
let dir = tempfile::tempdir().expect("should create temporary directory OK");
let path = dir.path().join("wasm-pack");
println!(
"wasm-pack: copying test fixture '{}' to temporary directory '{}'",
fixture.display(),
path.display()
);
copy_dir(fixture, &path).expect("should copy fixture directory into temporary directory OK");
Fixture { dir, path }
}
pub struct Fixture {
pub dir: tempfile::TempDir,
pub path: PathBuf,
}
pub mod manifest {
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use failure::Error;
use serde_json;
#[derive(Deserialize)]
pub struct NpmPackage {
pub name: String,
pub description: String,
pub version: String,
pub license: String,
pub repository: Repository,
pub files: Vec<String>,
pub main: String,
pub types: Option<String>,
}
#[derive(Deserialize)]
pub struct Repository {
#[serde(rename = "type")]
pub ty: String,
pub url: String,
}
pub fn read_package_json(path: &Path) -> Result<NpmPackage, Error> {
let manifest_path = path.join("pkg").join("package.json");
let mut pkg_file = File::open(manifest_path)?;
let mut pkg_contents = String::new();
pkg_file.read_to_string(&mut pkg_contents)?;
Ok(serde_json::from_str(&pkg_contents)?)
}
}
pub mod readme {
use std::fs::File;
use std::io::Read;
use std::path::Path;
use failure::Error;
pub fn read_file(path: &Path) -> Result<String, Error> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
Ok(contents)
}
}

@ -0,0 +1,13 @@
use std::fs::File;
use std::io::Read;
use std::path::Path;
use failure::Error;
pub fn read_file(path: &Path) -> Result<String, Error> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
Ok(contents)
}

@ -0,0 +1,33 @@
use std::path::{Path, PathBuf};
use copy_dir::copy_dir;
use tempfile;
pub struct Fixture {
pub dir: tempfile::TempDir,
pub path: PathBuf,
}
/// Copy the given fixture into a unique temporary directory. This allows the
/// test to mutate the copied fixture without messing up other tests that are
/// also trying to read from or write to that fixture. The given path should be
/// relative from the root of the repository, eg
/// "tests/fixtures/im-from-brooklyn-the-place-where-stars-are-born".
pub fn fixture<P>(fixture: P) -> Fixture
where
P: AsRef<Path>,
{
let fixture = fixture
.as_ref()
.canonicalize()
.expect("should canonicalize fixture path OK");
let dir = tempfile::tempdir().expect("should create temporary directory OK");
let path = dir.path().join("wasm-pack");
println!(
"wasm-pack: copying test fixture '{}' to temporary directory '{}'",
fixture.display(),
path.display()
);
copy_dir(fixture, &path).expect("should copy fixture directory into temporary directory OK");
Fixture { dir, path }
}

@ -0,0 +1,34 @@
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use failure::Error;
use serde_json;
#[derive(Deserialize)]
pub struct NpmPackage {
pub name: String,
pub description: String,
pub version: String,
pub license: String,
pub repository: Repository,
pub files: Vec<String>,
pub main: String,
pub types: Option<String>,
}
#[derive(Deserialize)]
pub struct Repository {
#[serde(rename = "type")]
pub ty: String,
pub url: String,
}
pub fn read_package_json(path: &Path) -> Result<NpmPackage, Error> {
let manifest_path = path.join("pkg").join("package.json");
let mut pkg_file = File::open(manifest_path)?;
let mut pkg_contents = String::new();
pkg_file.read_to_string(&mut pkg_contents)?;
Ok(serde_json::from_str(&pkg_contents)?)
}

@ -0,0 +1,3 @@
pub mod file;
pub mod fixture;
pub mod manifest;
Loading…
Cancel
Save