Merge pull request #211 from fitzgen/copy-fixtures-to-temp-dir

Copy fixtures to temp dir
master
ashley williams 7 years ago committed by GitHub
commit 56f18964f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .travis.yml
  2. 108
      Cargo.lock
  3. 4
      Cargo.toml
  4. 11
      src/readme.rs
  5. 11
      tests/all/main.rs
  6. 82
      tests/all/manifest.rs
  7. 53
      tests/all/readme.rs
  8. 86
      tests/all/utils.rs
  9. 34
      tests/manifest/utils.rs
  10. 35
      tests/readme/main.rs
  11. 12
      tests/readme/utils.rs

@ -7,9 +7,7 @@ matrix:
# tests pass
- rust: nightly
script:
# XXX: `--test-threads 1` is a hack until we have a proper fix for
# synchronizing access to the fixtures.
- cargo test --locked -- --test-threads 1
- cargo test --locked
- rustup component add rustfmt-preview
- cargo fmt --all -- --check
env: RUST_BACKTRACE=1

108
Cargo.lock generated

@ -16,7 +16,7 @@ dependencies = [
[[package]]
name = "atty"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
@ -81,7 +81,7 @@ version = "2.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -100,6 +100,14 @@ dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "console"
version = "0.6.1"
@ -115,6 +123,14 @@ dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "copy_dir"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.3"
@ -287,7 +303,7 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "0.4.8"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -300,10 +316,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.6.3"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -316,6 +332,23 @@ dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.40"
@ -377,9 +410,9 @@ name = "serde_derive"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -394,7 +427,7 @@ dependencies = [
[[package]]
name = "slog"
version = "2.2.3"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -402,7 +435,7 @@ name = "slog-async"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -414,7 +447,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"isatty 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -451,9 +484,9 @@ name = "structopt-derive"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -468,11 +501,11 @@ dependencies = [
[[package]]
name = "syn"
version = "0.14.4"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -507,6 +540,18 @@ dependencies = [
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tempfile"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.5.1"
@ -629,11 +674,21 @@ name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "walkdir"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasm-pack"
version = "0.4.2"
dependencies = [
"console 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"copy_dir 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"human-panic 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -642,10 +697,11 @@ dependencies = [
"serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -689,7 +745,7 @@ dependencies = [
[metadata]
"checksum aho-corasick 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c6d463cbe7ed28720b5b489e7c083eeb8f90d08be2a0d6bb9e1ffea9ce1afa"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
@ -699,7 +755,9 @@ dependencies = [
"checksum chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6962c635d530328acc53ac6a955e83093fedc91c5809dfac1fa60fa470830a37"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f84dec9bc083ce2503908cd305af98bd363da6f54bf8d4bf0ac14ee749ad5d1"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum console 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7649ca90478264b9686aac8d269fcb014f14c2bed7c79a7e51b9f6afd4d783eb"
"checksum copy_dir 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0"
"checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd"
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
@ -721,10 +779,12 @@ dependencies = [
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
"checksum parking_lot 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "69376b761943787ebd5cc85a5bc95958651a22609c5c1c2b65de21786baec72b"
"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa"
"checksum proc-macro2 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c65b1ea15bb859d922cade2d1765b4b88beac339cbfad545ef2d2ef8c8215ee6"
"checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
"checksum quote 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b71f9f575d55555aa9c06188be9d4e2bfc83ed02537948ac0d520c24d0419f1a"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum rand 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12397506224b2f93e6664ffc4f664b29be8208e5157d3d90b44f09b5fae470ea"
"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384"
@ -735,7 +795,7 @@ dependencies = [
"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
"checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124"
"checksum serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c6908c7b925cd6c590358a4034de93dbddb20c45e1d021931459fd419bf0e2"
"checksum slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2f7bfce6405155042d42ec0e645efe43eddedd7be280063ce0623b120014e7f9"
"checksum slog 2.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c43bcfcefccea70a0c52528be603b13237e76d7a031e6e1e92fabc344bd0a3aa"
"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f"
"checksum slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5951a808c40f419922ee014c15b6ae1cd34d963538b57d8a4778b9ca3fff1e0b"
"checksum smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "26df3bb03ca5eac2e64192b723d51f56c1b1e0860e7c766281f4598f181acdc8"
@ -744,11 +804,12 @@ dependencies = [
"checksum structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e9ad6a11096cbecdcca0cc6aa403fdfdbaeda2fb3323a39c98e6a166a1e45a"
"checksum structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4cbce8ccdc62166bd594c14396a3242bf94c337a51dbfa9be1076dd74b3db2af"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2beff8ebc3658f07512a413866875adddd20f4fd47b2a4e6c9da65cd281baaea"
"checksum syn 0.14.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4bad7abdf6633f07c7046b90484f1d9dc055eca39f8c991177b1046ce61dba9a"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c4b103c6d08d323b92ff42c8ce62abcd83ca8efa7fd5bf7927efefec75f58c76"
"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561"
"checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
@ -766,6 +827,7 @@ dependencies = [
"checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum walkdir 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"

@ -23,3 +23,7 @@ slog-term = "2.4"
slog-async = "2.3"
structopt = "0.2"
toml = "0.4"
[dev-dependencies]
copy_dir = "0.1.2"
tempfile = "3"

@ -10,6 +10,17 @@ use PBAR;
/// Copy the crate's README into the `pkg` directory.
pub fn copy_from_crate(path: &Path, step: &Step) -> Result<(), Error> {
assert!(
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
"crate directory should exist"
);
assert!(
fs::metadata(path.join("pkg"))
.ok()
.map_or(false, |m| m.is_dir()),
"crate's pkg directory should exist"
);
let msg = format!("{}Copying over your README...", emoji::DANCERS);
PBAR.step(step, &msg);
let crate_readme_path = path.join("README.md");

@ -0,0 +1,11 @@
extern crate copy_dir;
extern crate failure;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate tempfile;
extern crate wasm_pack;
mod manifest;
mod readme;
mod utils;

@ -1,16 +1,9 @@
extern crate failure;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate wasm_pack;
mod utils;
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;
use wasm_pack::manifest;
use utils;
use wasm_pack::{self, manifest};
#[test]
fn it_gets_the_crate_name_default_path() {
@ -60,14 +53,14 @@ fn it_recognizes_a_map_during_depcheck() {
#[test]
fn it_creates_a_package_json_default_path() {
let fixture = utils::fixture(".");
let step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from(".");
wasm_pack::command::init::create_pkg_dir(&path, &step).unwrap();
assert!(manifest::write_package_json(&path, &None, false, "", &step).is_ok());
let package_json_path = &path.join("pkg").join("package.json");
wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap();
assert!(utils::manifest::read_package_json(&fixture.path).is_ok());
let pkg = utils::manifest::read_package_json(&fixture.path).unwrap();
assert_eq!(pkg.name, "wasm-pack");
assert_eq!(pkg.repository.ty, "git");
assert_eq!(
@ -88,14 +81,14 @@ 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 step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from("tests/fixtures/js-hello-world");
wasm_pack::command::init::create_pkg_dir(&path, &step).unwrap();
assert!(manifest::write_package_json(&path, &None, false, "", &step).is_ok());
let package_json_path = &path.join("pkg").join("package.json");
wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, false, "", &step).is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap();
assert!(utils::manifest::read_package_json(&fixture.path).is_ok());
let pkg = utils::manifest::read_package_json(&fixture.path).unwrap();
assert_eq!(pkg.name, "js-hello-world");
assert_eq!(pkg.main, "js_hello_world.js");
@ -109,16 +102,17 @@ 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 step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from("tests/fixtures/scopes");
wasm_pack::command::init::create_pkg_dir(&path, &step).unwrap();
wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(
manifest::write_package_json(&path, &Some("test".to_string()), false, "", &step).is_ok()
manifest::write_package_json(&fixture.path, &Some("test".to_string()), false, "", &step)
.is_ok()
);
let package_json_path = &path.join("pkg").join("package.json");
let package_json_path = &fixture.path.join("pkg").join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap();
assert!(utils::manifest::read_package_json(&fixture.path).is_ok());
let pkg = utils::manifest::read_package_json(&fixture.path).unwrap();
assert_eq!(pkg.name, "@test/scopes-hello-world");
assert_eq!(pkg.main, "scopes_hello_world.js");
@ -132,14 +126,14 @@ 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 step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from(".");
wasm_pack::command::init::create_pkg_dir(&path, &step).unwrap();
assert!(manifest::write_package_json(&path, &None, false, "nodejs", &step).is_ok());
let package_json_path = &path.join("pkg").join("package.json");
wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, false, "nodejs", &step).is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap();
assert!(utils::manifest::read_package_json(&fixture.path).is_ok());
let pkg = utils::manifest::read_package_json(&fixture.path).unwrap();
assert_eq!(pkg.name, "wasm-pack");
assert_eq!(pkg.repository.ty, "git");
assert_eq!(
@ -161,14 +155,14 @@ 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 step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from(".");
wasm_pack::command::init::create_pkg_dir(&path, &step).unwrap();
assert!(manifest::write_package_json(&path, &None, true, "", &step).is_ok());
let package_json_path = &path.join("pkg").join("package.json");
wasm_pack::command::init::create_pkg_dir(&fixture.path, &step).unwrap();
assert!(manifest::write_package_json(&fixture.path, &None, true, "", &step).is_ok());
let package_json_path = &fixture.path.join("pkg").join("package.json");
assert!(fs::metadata(package_json_path).is_ok());
assert!(utils::read_package_json(&path).is_ok());
let pkg = utils::read_package_json(&path).unwrap();
assert!(utils::manifest::read_package_json(&fixture.path).is_ok());
let pkg = utils::manifest::read_package_json(&fixture.path).unwrap();
assert_eq!(pkg.name, "wasm-pack");
assert_eq!(pkg.repository.ty, "git");
assert_eq!(
@ -187,16 +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 step = wasm_pack::progressbar::Step::new(1);
assert!(
manifest::check_crate_config(&PathBuf::from("tests/fixtures/bad-cargo-toml"), &step)
.is_err()
);
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 step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from("tests/fixtures/js-hello-world");
assert!(manifest::check_crate_config(&path, &step).is_ok());
assert!(manifest::check_crate_config(&fixture.path, &step).is_ok());
}

@ -0,0 +1,53 @@
extern crate failure;
extern crate wasm_pack;
use std::fs;
use utils;
use wasm_pack::readme;
#[test]
fn it_copies_a_readme_default_path() {
let fixture = utils::fixture(".");
fs::create_dir(fixture.path.join("pkg")).expect("should create pkg directory OK");
let step = wasm_pack::progressbar::Step::new(1);
assert!(readme::copy_from_crate(&fixture.path, &step).is_ok());
let crate_readme_path = fixture.path.join("README.md");
let pkg_readme_path = fixture.path.join("pkg").join("README.md");
println!(
"wasm-pack: should have copied README.md from '{}' to '{}'",
crate_readme_path.display(),
pkg_readme_path.display()
);
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();
assert_eq!(crate_readme, pkg_readme);
}
#[test]
fn it_creates_a_package_json_provided_path() {
let fixture = utils::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);
assert!(readme::copy_from_crate(&fixture.path, &step).is_ok());
let crate_readme_path = fixture.path.join("README.md");
let pkg_readme_path = fixture.path.join("pkg").join("README.md");
println!(
"wasm-pack: should have copied README.md from '{}' to '{}'",
crate_readme_path.display(),
pkg_readme_path.display()
);
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();
assert_eq!(crate_readme, pkg_readme);
}

@ -0,0 +1,86 @@
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)
}
}

@ -1,34 +0,0 @@
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)?)
}

@ -1,35 +0,0 @@
extern crate failure;
extern crate wasm_pack;
mod utils;
use std::fs;
use std::path::PathBuf;
use wasm_pack::readme;
#[test]
fn it_copies_a_readme_default_path() {
let step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from(".");
assert!(readme::copy_from_crate(&path, &step).is_ok());
let crate_readme_path = &path.join("README.md");
let pkg_readme_path = &path.join("pkg").join("README.md");
assert!(fs::metadata(&pkg_readme_path).is_ok());
let crate_readme = utils::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::read_file(&pkg_readme_path).unwrap();
assert_eq!(crate_readme, pkg_readme);
}
#[test]
fn it_creates_a_package_json_provided_path() {
let step = wasm_pack::progressbar::Step::new(1);
let path = PathBuf::from("tests/fixtures/js-hello-world");
assert!(readme::copy_from_crate(&path, &step).is_ok());
let crate_readme_path = &path.join("README.md");
let pkg_readme_path = &path.join("pkg").join("README.md");
assert!(fs::metadata(&pkg_readme_path).is_ok());
let crate_readme = utils::read_file(&crate_readme_path).unwrap();
let pkg_readme = utils::read_file(&pkg_readme_path).unwrap();
assert_eq!(crate_readme, pkg_readme);
}

@ -1,12 +0,0 @@
use failure::Error;
use std::fs::File;
use std::io::Read;
use std::path::Path;
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)
}
Loading…
Cancel
Save