Merge branch 'master' into binary-install-tests

master
Jesper Håkansson 6 years ago
commit 3fc5df8b7a
  1. 89
      Cargo.lock
  2. 2
      Cargo.toml
  3. 2
      docs/src/commands/build.md
  4. 84
      docs/src/commands/test.md
  5. 4
      docs/src/prerequisites/index.md
  6. 4
      docs/src/tutorial/index.md
  7. 8
      docs/src/tutorial/template-deep-dive/src-utils-rs.md
  8. 5
      src/build.rs
  9. 14
      src/cache.rs
  10. 15
      src/command/build.rs
  11. 2
      src/command/mod.rs
  12. 17
      src/command/test.rs
  13. 1
      src/lib.rs
  14. 13
      src/license.rs
  15. 76
      src/manifest/mod.rs
  16. 2
      src/manifest/npm/commonjs.rs
  17. 2
      src/manifest/npm/esmodules.rs
  18. 2
      src/manifest/npm/nomodules.rs
  19. 7
      src/progressbar.rs
  20. 18
      src/test/mod.rs
  21. 8
      src/test/webdriver.rs
  22. 123
      tests/all/build.rs
  23. 29
      tests/all/license.rs
  24. 2
      tests/all/main.rs
  25. 161
      tests/all/manifest.rs
  26. 266
      tests/all/test.rs
  27. 75
      tests/all/utils/fixture.rs
  28. 1
      tests/all/utils/manifest.rs
  29. 3
      tests/all/webdriver.rs

89
Cargo.lock generated

@ -36,6 +36,17 @@ dependencies = [
"nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "assert_cmd"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.11" version = "0.2.11"
@ -289,6 +300,11 @@ dependencies = [
"tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "difference"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "dirs" name = "dirs"
version = "1.0.4" version = "1.0.4"
@ -323,6 +339,15 @@ dependencies = [
"backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "escargot"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "failure" name = "failure"
version = "0.1.5" version = "0.1.5"
@ -364,6 +389,14 @@ dependencies = [
"miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "float-cmp"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "foreign-types" name = "foreign-types"
version = "0.3.2" version = "0.3.2"
@ -562,6 +595,16 @@ name = "nodrop"
version = "0.1.13" version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "normalize-line-endings"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "num-traits"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.16" version = "0.10.16"
@ -668,6 +711,32 @@ name = "podio"
version = "0.1.6" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "predicates"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "predicates-core"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "predicates-tree"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "0.4.24" version = "0.4.24"
@ -951,6 +1020,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "serde" name = "serde"
version = "1.0.84" version = "1.0.84"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
@ -1173,6 +1245,11 @@ dependencies = [
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "treeline"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "ucd-util" name = "ucd-util"
version = "0.1.3" version = "0.1.3"
@ -1249,6 +1326,7 @@ dependencies = [
name = "wasm-pack" name = "wasm-pack"
version = "0.6.0" version = "0.6.0"
dependencies = [ dependencies = [
"assert_cmd 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"binary-install 0.0.1", "binary-install 0.0.1",
"cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1265,6 +1343,7 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1367,6 +1446,7 @@ dependencies = [
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" "checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
"checksum assert_cmd 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ac5c260f75e4e4ba87b7342be6edcecbcb3eb6741a0507fda7ad115845cc65"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727" "checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727"
"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" "checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5"
@ -1392,14 +1472,17 @@ dependencies = [
"checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16" "checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16"
"checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502" "checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502"
"checksum dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad1c29a0368928e78c551354dbff79f103a962ad820519724ef0d74f1c62fa9" "checksum dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad1c29a0368928e78c551354dbff79f103a962ad820519724ef0d74f1c62fa9"
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a" "checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a"
"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" "checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd"
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
"checksum escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19db1f7e74438642a5018cdf263bb1325b2e792f02dd0a3ca6d6c0f0d7b1d5a5"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
"checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646"
"checksum flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2291c165c8e703ee54ef3055ad6188e3d51108e2ded18e9f2476e774fc5ad3d4" "checksum flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2291c165c8e703ee54ef3055ad6188e3d51108e2ded18e9f2476e774fc5ad3d4"
"checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
@ -1425,6 +1508,8 @@ dependencies = [
"checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c"
"checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e"
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
"checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9" "checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7" "checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7"
@ -1437,6 +1522,9 @@ dependencies = [
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd"
"checksum predicates 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa984b7cd021a0bf5315bcce4c4ae61d2a535db2a8d288fc7578638690a7b7c3"
"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178"
"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124"
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" "checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
@ -1496,6 +1584,7 @@ dependencies = [
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" "checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"

@ -38,6 +38,8 @@ binary-install = { version = "0.0.1", path = "./binary-install" }
walkdir = "2" walkdir = "2"
[dev-dependencies] [dev-dependencies]
assert_cmd = "0.10.2"
predicates = "1.0.0"
tempfile = "3" tempfile = "3"
[features] [features]

@ -59,7 +59,7 @@ wasm-pack build --target nodejs
| Option | Description | | Option | Description |
|-----------|-----------------------------------------------------------------------------------------------------------------| |-----------|-----------------------------------------------------------------------------------------------------------------|
| `nodejs` | Outputs JS that uses CommonJS modules, for use with a `require` statement. `main` key in `package.json`. | | `nodejs` | Outputs JS that uses CommonJS modules, for use with a `require` statement. `main` key in `package.json`. |
| `nomodules` | Outputs JS that use no modules. `browser` key in `package.json`. | | `no-modules` | Outputs JS that use no modules. `browser` key in `package.json`. |
| `browser` | Outputs JS that uses ES6 modules, primarily for use with `import` statements and/or bundlers such as `webpack`. `module` key in `package.json`. `sideEffects: false` by default. | | `browser` | Outputs JS that uses ES6 modules, primarily for use with `import` statements and/or bundlers such as `webpack`. `module` key in `package.json`. `sideEffects: false` by default. |
## Scope ## Scope

@ -0,0 +1,84 @@
# wasm-pack test
The `wasm-pack test` command wraps the [wasm-bindgen-test-runner](https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/index.html)
CLI allowing you to run wasm tests in different browsers without needing to install the different
webdrivers yourself.
```
wasm-pack test --help
```
## Path
The `wasm-pack test` command can be given an optional path argument.
This path should point to a directory that contains a `Cargo.toml` file. If no
path is given, the `test` command will run in the current directory.
```
# Run tests for the current directory's crate
wasm-pack test
# Run tests for a specified crate
wasm-pack test crates/crate-in-my-workspace
```
## Profile
The `test` command accepts an optional profile argument: `--release`.
If none is supplied, then a debug test build will be used.
## Test environment
Choose where to run your tests by passing in any combination of testing environment flags.
`--headless` is useful for running browser tests in a headless browser as part of a CI process.
```
wasm-pack test --node --firefox --chrome --safari --headless
```
## Extra options
The `test` command can pass extra options straight to `cargo test` even if they are not
supported in wasm-pack.
To use them you should add standalone `--` argument at the very
end of your command, and all the arguments you want to pass to cargo should go after.
`cargo test -h` for a list of all options that you can pass through.
## Running only some tests
When debugging a specific issue, you may find yourself wanting to run a subset of tests, instead of your entire suite of tests.
Here are a few examples of how to run a subset of your tests:
```
# Example directory structure
$ tree crates/foo
├── Cargo.toml
├── README.md
├── src
   ├── diff
     ├── diff_test_case.rs
     └── mod.rs
   ├── lib.rs
└── tests
├── diff_patch.rs
```
```
# Run all tests in tests/diff_patch.rs
wasm-pack test crates/foo --firefox --headless -- --tests diff_patch
# Run all tests in tests/diff_patch.rs that contain the word "replace"
wasm-pack test crates/foo --firefox --headless -- --tests diff_patch replace
# Run all tests inside of a `tests` module inside of src/lib/diff.rs
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests
# Same as the above, but only if they contain the word replace
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests::replace
```

@ -2,8 +2,8 @@
To run `wasm-pack` you'll need to have both Rust and npm installed and configured. To run `wasm-pack` you'll need to have both Rust and npm installed and configured.
- [Rust](./rust.html) - [Rust](/wasm-pack/book/prerequisites/rust.html)
- [npm](./npm.html) - [npm](/wasm-pack/book/prerequisites/npm.html)
In the future, we intend to rewrite the npm registry client bits so that the need In the future, we intend to rewrite the npm registry client bits so that the need
for a Node runtime is eliminated. If you're excited about that work- you should for a Node runtime is eliminated. If you're excited about that work- you should

@ -10,8 +10,8 @@ Be sure to have done the following before starting:
1. [Install `wasm-pack`](../../installer) 1. [Install `wasm-pack`](../../installer)
1. Read and install the [Prerequisites](../prerequisites/index.html). 1. Read and install the [Prerequisites](../prerequisites/index.html).
- You'll need [Rust], version 1.30 or higher. (Currently either `beta` or `nightly` channels). [Learn more](../project-setup/rust.html). - You'll need [Rust], version 1.30 or higher. (Currently either `beta` or `nightly` channels). [Learn more](../prerequisites/rust.html).
- You'll need [Node.js] and [npm] installed. You'll also need an npm Account. [Learn more](../project-setup/npm.html). - You'll need [Node.js] and [npm] installed. You'll also need an npm Account. [Learn more](../prerequisites/npm.html).
We strongly recommend that you install [Node.js] using a version manager. You can learn more [here](https://npmjs.com/get-npm). We strongly recommend that you install [Node.js] using a version manager. You can learn more [here](https://npmjs.com/get-npm).

@ -13,13 +13,13 @@ We will discuss:
## 1. Defining `set_panic_hook` ## 1. Defining `set_panic_hook`
``` ```rust
use cfg_if::cfg_if; use cfg_if::cfg_if;
``` ```
This allows us to write `cfg_if!` instead of `cfg_if::cfg_if!`, identically to the line in `src/lib.rs`. This allows us to write `cfg_if!` instead of `cfg_if::cfg_if!`, identically to the line in `src/lib.rs`.
``` ```rust
cfg_if! { cfg_if! {
if #[cfg(feature = "console_error_panic_hook")] { if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook; extern crate console_error_panic_hook;
@ -35,14 +35,14 @@ As described in the preceding section, the macro `cfg_if!` evaluates the `if` st
The entire macro block will either be replaced with the statements in the `if` block or with those in the `else` block. These two cases are now described in turn: The entire macro block will either be replaced with the statements in the `if` block or with those in the `else` block. These two cases are now described in turn:
``` ```rust
extern crate console_error_panic_hook; extern crate console_error_panic_hook;
pub use self::console_error_panic_hook::set_once as set_panic_hook; pub use self::console_error_panic_hook::set_once as set_panic_hook;
``` ```
Due to the `use` statement, the function `self::console_error_panic_hook::set_once` can now be accessed more conveniently as `set_panic_hook`. Due to `pub`, this function will be publicly accessible outside of the `utils` module as `utils::set_panic_hook`. Due to the `use` statement, the function `self::console_error_panic_hook::set_once` can now be accessed more conveniently as `set_panic_hook`. Due to `pub`, this function will be publicly accessible outside of the `utils` module as `utils::set_panic_hook`.
``` ```rust
#[inline] #[inline]
pub fn set_panic_hook() {} pub fn set_panic_hook() {}
``` ```

@ -25,7 +25,7 @@ pub fn check_rustc_version(step: &Step) -> Result<String, Error> {
} else { } else {
Ok(mv.to_string()) Ok(mv.to_string())
} }
}, }
None => bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher."), None => bail!("We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher."),
} }
} }
@ -95,6 +95,9 @@ pub fn cargo_build_wasm(
} }
/// Run `cargo build --tests` targetting `wasm32-unknown-unknown`. /// Run `cargo build --tests` targetting `wasm32-unknown-unknown`.
///
/// This generates the `Cargo.lock` file that we use in order to know which version of
/// wasm-bindgen-cli to use when running tests.
pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> { pub fn cargo_build_wasm_tests(path: &Path, debug: bool) -> Result<(), Error> {
let mut cmd = Command::new("cargo"); let mut cmd = Command::new("cargo");
cmd.current_dir(path).arg("build").arg("--tests"); cmd.current_dir(path).arg("build").arg("--tests");

@ -0,0 +1,14 @@
//! Getting and configuring wasm-pack's binary cache.
use binary_install::Cache;
use std::env;
use std::path::Path;
/// Get wasm-pack's binary cache.
pub fn get_wasm_pack_cache() -> Result<Cache, failure::Error> {
if let Ok(path) = env::var("WASM_PACK_CACHE") {
Ok(Cache::at(Path::new(&path)))
} else {
Cache::new("wasm-pack")
}
}

@ -3,6 +3,7 @@
use binary_install::{Cache, Download}; use binary_install::{Cache, Download};
use bindgen; use bindgen;
use build; use build;
use cache;
use command::utils::{create_pkg_dir, set_crate_path}; use command::utils::{create_pkg_dir, set_crate_path};
use emoji; use emoji;
use failure::Error; use failure::Error;
@ -18,7 +19,7 @@ use std::str::FromStr;
use std::time::Instant; use std::time::Instant;
use PBAR; use PBAR;
/// Everything required to configure and run the `wasm-pack init` command. /// Everything required to configure and run the `wasm-pack build` command.
#[allow(missing_docs)] #[allow(missing_docs)]
pub struct Build { pub struct Build {
pub crate_path: PathBuf, pub crate_path: PathBuf,
@ -180,7 +181,7 @@ impl Build {
mode: build_opts.mode, mode: build_opts.mode,
out_dir, out_dir,
bindgen: None, bindgen: None,
cache: Cache::new("wasm_pack")?, cache: cache::get_wasm_pack_cache()?,
extra_options: build_opts.extra_options, extra_options: build_opts.extra_options,
}) })
} }
@ -238,29 +239,29 @@ impl Build {
step_add_wasm_target, step_add_wasm_target,
step_build_wasm, step_build_wasm,
step_create_dir, step_create_dir,
step_create_json,
step_copy_readme, step_copy_readme,
step_copy_license, step_copy_license,
step_install_wasm_bindgen, step_install_wasm_bindgen,
step_run_wasm_bindgen, step_run_wasm_bindgen,
step_create_json,
], ],
BuildMode::Noinstall => steps![ BuildMode::Noinstall => steps![
step_check_rustc_version, step_check_rustc_version,
step_check_crate_config, step_check_crate_config,
step_build_wasm, step_build_wasm,
step_create_dir, step_create_dir,
step_create_json,
step_copy_readme, step_copy_readme,
step_copy_license, step_copy_license,
step_run_wasm_bindgen step_run_wasm_bindgen,
step_create_json,
], ],
BuildMode::Force => steps![ BuildMode::Force => steps![
step_build_wasm, step_build_wasm,
step_create_dir, step_create_dir,
step_create_json,
step_copy_readme, step_copy_readme,
step_copy_license, step_copy_license,
step_run_wasm_bindgen step_run_wasm_bindgen,
step_create_json,
], ],
} }
} }

@ -50,7 +50,7 @@ pub enum Command {
}, },
#[structopt(name = "login", alias = "adduser", alias = "add-user")] #[structopt(name = "login", alias = "adduser", alias = "add-user")]
/// 👤 Add a registry user account! (aliases: adduser, add-user) /// 👤 Add an npm registry user account! (aliases: adduser, add-user)
Login { Login {
#[structopt(long = "registry", short = "r")] #[structopt(long = "registry", short = "r")]
/// Default: 'https://registry.npmjs.org/'. /// Default: 'https://registry.npmjs.org/'.

@ -4,6 +4,7 @@ use super::build::BuildMode;
use binary_install::Cache; use binary_install::Cache;
use bindgen; use bindgen;
use build; use build;
use cache;
use command::utils::set_crate_path; use command::utils::set_crate_path;
use console::style; use console::style;
use emoji; use emoji;
@ -77,6 +78,10 @@ pub struct TestOptions {
#[structopt(long = "release", short = "r")] #[structopt(long = "release", short = "r")]
/// Build with the release profile. /// Build with the release profile.
pub release: bool, pub release: bool,
#[structopt(last = true)]
/// List of extra options to pass to `cargo test`
pub extra_options: Vec<String>,
} }
/// A configured `wasm-pack test` command. /// A configured `wasm-pack test` command.
@ -95,6 +100,7 @@ pub struct Test {
headless: bool, headless: bool,
release: bool, release: bool,
test_runner_path: Option<PathBuf>, test_runner_path: Option<PathBuf>,
extra_options: Vec<String>,
} }
type TestStep = fn(&mut Test, &Step) -> Result<(), Error>; type TestStep = fn(&mut Test, &Step) -> Result<(), Error>;
@ -114,6 +120,7 @@ impl Test {
geckodriver, geckodriver,
safari, safari,
safaridriver, safaridriver,
extra_options,
} = test_opts; } = test_opts;
let crate_path = set_crate_path(path)?; let crate_path = set_crate_path(path)?;
@ -132,7 +139,7 @@ impl Test {
} }
Ok(Test { Ok(Test {
cache: Cache::new("wasm_pack")?, cache: cache::get_wasm_pack_cache()?,
crate_path, crate_path,
crate_data, crate_data,
node, node,
@ -146,6 +153,7 @@ impl Test {
headless, headless,
release, release,
test_runner_path: None, test_runner_path: None,
extra_options,
}) })
} }
@ -305,6 +313,7 @@ impl Test {
"CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER", "CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER",
&self.test_runner_path.as_ref().unwrap(), &self.test_runner_path.as_ref().unwrap(),
)), )),
&self.extra_options,
)?; )?;
info!("Finished running tests in node."); info!("Finished running tests in node.");
Ok(()) Ok(())
@ -348,7 +357,7 @@ impl Test {
envs.push(("NO_HEADLESS", "1")); envs.push(("NO_HEADLESS", "1"));
} }
test::cargo_test_wasm(&self.crate_path, self.release, envs)?; test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(()) Ok(())
} }
@ -390,7 +399,7 @@ impl Test {
envs.push(("NO_HEADLESS", "1")); envs.push(("NO_HEADLESS", "1"));
} }
test::cargo_test_wasm(&self.crate_path, self.release, envs)?; test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(()) Ok(())
} }
@ -429,7 +438,7 @@ impl Test {
envs.push(("NO_HEADLESS", "1")); envs.push(("NO_HEADLESS", "1"));
} }
test::cargo_test_wasm(&self.crate_path, self.release, envs)?; test::cargo_test_wasm(&self.crate_path, self.release, envs, &self.extra_options)?;
Ok(()) Ok(())
} }
} }

@ -28,6 +28,7 @@ extern crate walkdir;
pub mod bindgen; pub mod bindgen;
pub mod build; pub mod build;
pub mod cache;
pub mod child; pub mod child;
pub mod command; pub mod command;
pub mod emoji; pub mod emoji;

@ -57,8 +57,8 @@ pub fn copy_from_crate(
"crate's pkg directory should exist" "crate's pkg directory should exist"
); );
match crate_data.crate_license() { match (crate_data.crate_license(), crate_data.crate_license_file()) {
Some(_) => { (Some(_), _) => {
let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS); let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS);
PBAR.step(step, &msg); PBAR.step(step, &msg);
let license_files = glob_license_files(path); let license_files = glob_license_files(path);
@ -80,7 +80,14 @@ pub fn copy_from_crate(
Err(_) => PBAR.info("origin crate has no LICENSE"), Err(_) => PBAR.info("origin crate has no LICENSE"),
} }
} }
None => { (None, Some(license_file)) => {
let crate_license_path = path.join(&license_file);
let new_license_path = out_dir.join(&license_file);
if fs::copy(&crate_license_path, &new_license_path).is_err() {
PBAR.info("origin crate has no LICENSE");
}
}
(None, None) => {
PBAR.step(step, "No LICENSE found in Cargo.toml, skipping..."); PBAR.step(step, "No LICENSE found in Cargo.toml, skipping...");
} }
}; };

@ -40,7 +40,10 @@ struct CargoPackage {
name: String, name: String,
description: Option<String>, description: Option<String>,
license: Option<String>, license: Option<String>,
#[serde(rename = "license-file")]
license_file: Option<String>,
repository: Option<String>, repository: Option<String>,
homepage: Option<String>,
#[serde(default)] #[serde(default)]
metadata: CargoMetadata, metadata: CargoMetadata,
@ -199,6 +202,7 @@ struct NpmData {
files: Vec<String>, files: Vec<String>,
dts_file: Option<String>, dts_file: Option<String>,
main: String, main: String,
homepage: Option<String>, // https://docs.npmjs.com/files/package.json#homepage
} }
#[doc(hidden)] #[doc(hidden)]
@ -290,7 +294,7 @@ impl CrateData {
pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) { pub fn warn_for_unused_keys(manifest_and_keys: &ManifestAndUnsedKeys) {
manifest_and_keys.unused_keys.iter().for_each(|path| { manifest_and_keys.unused_keys.iter().for_each(|path| {
PBAR.warn(&format!( PBAR.warn(&format!(
"\"{}\" is a unknown key and will be ignored. Please check your Cargo.toml.", "\"{}\" is an unknown key and will be ignored. Please check your Cargo.toml.",
path path
)); ));
}); });
@ -349,6 +353,11 @@ impl CrateData {
&self.manifest.package.license &self.manifest.package.license
} }
/// Get the license file path for the crate at the given path.
pub fn crate_license_file(&self) -> &Option<String> {
&self.manifest.package.license_file
}
/// Returns the path to this project's target directory where artifacts are /// Returns the path to this project's target directory where artifacts are
/// located after a cargo build. /// located after a cargo build.
pub fn target_directory(&self) -> &Path { pub fn target_directory(&self) -> &Path {
@ -374,11 +383,11 @@ impl CrateData {
PBAR.step(step, &msg); PBAR.step(step, &msg);
let pkg_file_path = out_dir.join("package.json"); let pkg_file_path = out_dir.join("package.json");
let npm_data = if target == "nodejs" { let npm_data = if target == "nodejs" {
self.to_commonjs(scope, disable_dts) self.to_commonjs(scope, disable_dts, out_dir)
} else if target == "no-modules" { } else if target == "no-modules" {
self.to_nomodules(scope, disable_dts) self.to_nomodules(scope, disable_dts, out_dir)
} else { } else {
self.to_esmodules(scope, disable_dts) self.to_esmodules(scope, disable_dts, out_dir)
}; };
let npm_json = serde_json::to_string_pretty(&npm_data)?; let npm_json = serde_json::to_string_pretty(&npm_data)?;
@ -392,6 +401,7 @@ impl CrateData {
scope: &Option<String>, scope: &Option<String>,
include_commonjs_shim: bool, include_commonjs_shim: bool,
disable_dts: bool, disable_dts: bool,
out_dir: &Path,
) -> NpmData { ) -> NpmData {
let crate_name = self.crate_name(); let crate_name = self.crate_name();
let wasm_file = format!("{}_bg.wasm", crate_name); let wasm_file = format!("{}_bg.wasm", crate_name);
@ -417,16 +427,43 @@ impl CrateData {
} else { } else {
None None
}; };
let readme_file = out_dir.join("README.md");
if readme_file.is_file() {
files.push("README.md".to_string());
}
if let Ok(entries) = fs::read_dir(out_dir) {
let file_names = entries
.filter_map(|e| e.ok())
.filter(|e| e.metadata().map(|m| m.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok())
.filter(|f| f.starts_with("LICENSE"));
for file_name in file_names {
files.push(file_name);
}
}
NpmData { NpmData {
name: npm_name, name: npm_name,
dts_file, dts_file,
files, files,
main: js_file, main: js_file,
homepage: self.manifest.package.homepage.clone(),
} }
} }
fn to_commonjs(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage { fn license(&self) -> Option<String> {
let data = self.npm_data(scope, true, disable_dts); self.manifest.package.license.clone().or_else(|| {
self.manifest.package.license_file.clone().map(|file| {
// When license is written in file: https://docs.npmjs.com/files/package.json#license
format!("SEE LICENSE IN {}", file)
})
})
}
fn to_commonjs(&self, scope: &Option<String>, disable_dts: bool, out_dir: &Path) -> NpmPackage {
let data = self.npm_data(scope, true, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx]; let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields(); self.check_optional_fields();
@ -436,7 +473,7 @@ impl CrateData {
collaborators: pkg.authors.clone(), collaborators: pkg.authors.clone(),
description: self.manifest.package.description.clone(), description: self.manifest.package.description.clone(),
version: pkg.version.clone(), version: pkg.version.clone(),
license: self.manifest.package.license.clone(), license: self.license(),
repository: self repository: self
.manifest .manifest
.package .package
@ -448,12 +485,18 @@ impl CrateData {
}), }),
files: data.files, files: data.files,
main: data.main, main: data.main,
homepage: data.homepage,
types: data.dts_file, types: data.dts_file,
}) })
} }
fn to_esmodules(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage { fn to_esmodules(
let data = self.npm_data(scope, false, disable_dts); &self,
scope: &Option<String>,
disable_dts: bool,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx]; let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields(); self.check_optional_fields();
@ -463,7 +506,7 @@ impl CrateData {
collaborators: pkg.authors.clone(), collaborators: pkg.authors.clone(),
description: self.manifest.package.description.clone(), description: self.manifest.package.description.clone(),
version: pkg.version.clone(), version: pkg.version.clone(),
license: self.manifest.package.license.clone(), license: self.license(),
repository: self repository: self
.manifest .manifest
.package .package
@ -475,13 +518,19 @@ impl CrateData {
}), }),
files: data.files, files: data.files,
module: data.main, module: data.main,
homepage: data.homepage,
types: data.dts_file, types: data.dts_file,
side_effects: "false".to_string(), side_effects: "false".to_string(),
}) })
} }
fn to_nomodules(&self, scope: &Option<String>, disable_dts: bool) -> NpmPackage { fn to_nomodules(
let data = self.npm_data(scope, false, disable_dts); &self,
scope: &Option<String>,
disable_dts: bool,
out_dir: &Path,
) -> NpmPackage {
let data = self.npm_data(scope, false, disable_dts, out_dir);
let pkg = &self.data.packages[self.current_idx]; let pkg = &self.data.packages[self.current_idx];
self.check_optional_fields(); self.check_optional_fields();
@ -491,7 +540,7 @@ impl CrateData {
collaborators: pkg.authors.clone(), collaborators: pkg.authors.clone(),
description: self.manifest.package.description.clone(), description: self.manifest.package.description.clone(),
version: pkg.version.clone(), version: pkg.version.clone(),
license: self.manifest.package.license.clone(), license: self.license(),
repository: self repository: self
.manifest .manifest
.package .package
@ -503,6 +552,7 @@ impl CrateData {
}), }),
files: data.files, files: data.files,
browser: data.main, browser: data.main,
homepage: data.homepage,
types: data.dts_file, types: data.dts_file,
}) })
} }

@ -16,5 +16,7 @@ pub struct CommonJSPackage {
pub files: Vec<String>, pub files: Vec<String>,
pub main: String, pub main: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>, pub types: Option<String>,
} }

@ -16,6 +16,8 @@ pub struct ESModulesPackage {
pub files: Vec<String>, pub files: Vec<String>,
pub module: String, pub module: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>, pub types: Option<String>,
#[serde(rename = "sideEffects")] #[serde(rename = "sideEffects")]
pub side_effects: String, pub side_effects: String,

@ -16,5 +16,7 @@ pub struct NoModulesPackage {
pub files: Vec<String>, pub files: Vec<String>,
pub browser: String, pub browser: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>, pub types: Option<String>,
} }

@ -43,6 +43,13 @@ impl ProgressOutput {
let mut spinner = self.spinner.write(); let mut spinner = self.spinner.write();
*spinner = Self::progressbar(message); *spinner = Self::progressbar(message);
if !atty::is(atty::Stream::Stderr) {
// `indicatif` won't print any output if `stderr` is not a tty, so
// to ensure that our output is still emitted, we print it manually
// here.
eprintln!("{}", message)
}
} }
fn add_message(&self, msg: &str) { fn add_message(&self, msg: &str) {

@ -4,20 +4,23 @@ pub mod webdriver;
use child; use child;
use failure::{self, ResultExt}; use failure::{self, ResultExt};
use log::info;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
/// Run `cargo test` with the `nightly` toolchain and targeting /// Run `cargo test` with the `nightly` toolchain and targeting
/// `wasm32-unknown-unknown`. /// `wasm32-unknown-unknown`.
pub fn cargo_test_wasm<I, K, V>(path: &Path, release: bool, envs: I) -> Result<(), failure::Error> pub fn cargo_test_wasm<I, K, V>(
path: &Path,
release: bool,
envs: I,
extra_options: &[String],
) -> Result<(), failure::Error>
where where
I: IntoIterator<Item = (K, V)>, I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>, K: AsRef<OsStr>,
V: AsRef<OsStr>, V: AsRef<OsStr>,
{ {
let output = {
let mut cmd = Command::new("cargo"); let mut cmd = Command::new("cargo");
cmd.envs(envs); cmd.envs(envs);
cmd.current_dir(path).arg("test"); cmd.current_dir(path).arg("test");
@ -25,12 +28,9 @@ where
cmd.arg("--release"); cmd.arg("--release");
} }
cmd.arg("--target").arg("wasm32-unknown-unknown"); cmd.arg("--target").arg("wasm32-unknown-unknown");
child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")? cmd.args(extra_options);
}; child::run(cmd, "cargo test").context("Running Wasm tests with wasm-bindgen-test failed")?;
for line in output.lines() { // NB: `child::run` took care of ensuring that test output gets printed.
info!("test output: {}", line);
println!("{}", line);
}
Ok(()) Ok(())
} }

@ -31,14 +31,14 @@ pub fn install_chromedriver(
"linux64" "linux64"
} else if target::MACOS && target::x86_64 { } else if target::MACOS && target::x86_64 {
"mac64" "mac64"
} else if target::WINDOWS && target::x86 { } else if target::WINDOWS {
"win32" "win32"
} else { } else {
bail!("geckodriver binaries are unavailable for this target") bail!("chromedriver binaries are unavailable for this target")
}; };
let url = format!( let url = format!(
"https://chromedriver.storage.googleapis.com/2.41/chromedriver_{}.zip", "https://chromedriver.storage.googleapis.com/2.46/chromedriver_{}.zip",
target target
); );
match cache.download( match cache.download(
@ -92,7 +92,7 @@ pub fn install_geckodriver(
}; };
let url = format!( let url = format!(
"https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-{}.{}", "https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-{}.{}",
target, target,
ext, ext,
); );

@ -1,40 +1,24 @@
use assert_cmd::prelude::*;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use structopt::StructOpt;
use utils; use utils;
use wasm_pack::Cli;
#[test] #[test]
fn build_in_non_crate_directory_doesnt_panic() { fn build_in_non_crate_directory_doesnt_panic() {
let fixture = utils::fixture::not_a_crate(); let fixture = utils::fixture::not_a_crate();
let cli = Cli::from_iter_safe(vec![ fixture
"wasm-pack", .wasm_pack()
"build", .arg("build")
&fixture.path.display().to_string(), .assert()
]) .failure()
.unwrap(); .stderr(predicates::str::contains("missing a `Cargo.toml`"));
let result = fixture.run(cli.cmd);
assert!(
result.is_err(),
"running wasm-pack in a non-crate directory should fail, but it should not panic"
);
let err = result.unwrap_err();
assert!(err
.iter_chain()
.any(|e| e.to_string().contains("missing a `Cargo.toml`")));
} }
#[test] #[test]
fn it_should_build_js_hello_world_example() { fn it_should_build_js_hello_world_example() {
let fixture = utils::fixture::js_hello_world(); let fixture = utils::fixture::js_hello_world();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![ fixture.wasm_pack().arg("build").assert().success();
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
} }
#[test] #[test]
@ -75,15 +59,14 @@ fn it_should_build_crates_in_a_workspace() {
#[wasm_bindgen] #[wasm_bindgen]
pub fn hello() -> u32 { 42 } pub fn hello() -> u32 { 42 }
"#, "#,
); )
fixture.install_local_wasm_bindgen(); .install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![ fixture
"wasm-pack", .wasm_pack()
"build", .current_dir(&fixture.path.join("blah"))
&fixture.path.join("blah").display().to_string(), .arg("build")
]) .assert()
.unwrap(); .success();
fixture.run(cli.cmd).unwrap();
} }
#[test] #[test]
@ -116,28 +99,21 @@ fn renamed_crate_name_works() {
#[wasm_bindgen] #[wasm_bindgen]
pub fn one() -> u32 { 1 } pub fn one() -> u32 { 1 }
"#, "#,
); )
fixture.install_local_wasm_bindgen(); .install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![ fixture.wasm_pack().arg("build").assert().success();
"wasm-pack",
"build",
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap();
} }
#[test] #[test]
fn it_should_build_nested_project_with_transitive_dependencies() { fn it_should_build_nested_project_with_transitive_dependencies() {
let fixture = utils::fixture::transitive_dependencies(); let fixture = utils::fixture::transitive_dependencies();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![ fixture
"wasm-pack", .wasm_pack()
"build", .current_dir(fixture.path.join("main"))
&fixture.path.join("main").display().to_string(), .arg("build")
]) .assert()
.unwrap(); .success();
fixture.run(cli.cmd).unwrap();
} }
#[test] #[test]
@ -149,14 +125,12 @@ fn build_different_profiles() {
.iter() .iter()
.cloned() .cloned()
{ {
let cli = Cli::from_iter_safe(vec![ fixture
"wasm-pack", .wasm_pack()
"build", .arg("build")
profile, .arg(profile)
&fixture.path.display().to_string(), .assert()
]) .success();
.unwrap();
fixture.run(cli.cmd).unwrap();
} }
} }
@ -208,17 +182,15 @@ fn build_with_and_without_wasm_bindgen_debug() {
pub fn take(self) {} pub fn take(self) {}
} }
"#, "#,
); )
.install_local_wasm_bindgen();
let cli = Cli::from_iter_safe(vec![
"wasm-pack",
"build",
"--dev",
&fixture.path.display().to_string(),
])
.unwrap();
fixture.run(cli.cmd).unwrap(); fixture
.wasm_pack()
.arg("build")
.arg("--dev")
.assert()
.success();
let contents = fs::read_to_string(fixture.path.join("pkg/whatever.js")).unwrap(); let contents = fs::read_to_string(fixture.path.join("pkg/whatever.js")).unwrap();
assert_eq!( assert_eq!(
@ -233,14 +205,11 @@ fn build_with_and_without_wasm_bindgen_debug() {
fn build_with_arbitrary_cargo_options() { fn build_with_arbitrary_cargo_options() {
let fixture = utils::fixture::js_hello_world(); let fixture = utils::fixture::js_hello_world();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
fixture
let cli = Cli::from_iter_safe(vec![ .wasm_pack()
"wasm-pack", .arg("build")
"build", .arg("--")
&fixture.path.display().to_string(), .arg("--no-default-features")
"--", .assert()
"--no-default-features", .success();
])
.unwrap();
fixture.run(cli.cmd).unwrap();
} }

@ -34,7 +34,7 @@ fn it_copies_a_license_default_path() {
} }
#[test] #[test]
fn it_copies_a_license_provied_path() { fn it_copies_a_license_provided_path() {
let fixture = fixture::single_license(); let fixture = fixture::single_license();
let out_dir = fixture.path.join("pkg"); let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK"); fs::create_dir(&out_dir).expect("should create pkg directory OK");
@ -128,3 +128,30 @@ fn it_copies_all_licenses_provided_path() {
let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap(); let pkg_license_2 = utils::file::read_file(&pkg_license_path_2).unwrap();
assert_eq!(crate_license_2, pkg_license_2); assert_eq!(crate_license_2, pkg_license_2);
} }
#[test]
fn it_copies_a_non_standard_license_provided_path() {
let license_file = "NON-STANDARD-LICENSE";
let fixture = fixture::non_standard_license(license_file);
let out_dir = fixture.path.join("pkg");
fs::create_dir(&out_dir).expect("should create pkg directory OK");
let crate_data = CrateData::new(&fixture.path);
let step = wasm_pack::progressbar::Step::new(1);
assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok());
let crate_license_path = fixture.path.join(license_file);
let pkg_license_path = out_dir.join(license_file);
println!(
"wasm-pack: should have copied LICENSE from '{}' to '{}'",
crate_license_path.display(),
pkg_license_path.display()
);
assert!(fs::metadata(&crate_license_path).is_ok());
assert!(fs::metadata(&pkg_license_path).is_ok());
let crate_license = utils::file::read_file(&crate_license_path).unwrap();
let pkg_license = utils::file::read_file(&pkg_license_path).unwrap();
assert_eq!(crate_license, pkg_license);
}

@ -1,4 +1,6 @@
extern crate assert_cmd;
extern crate failure; extern crate failure;
extern crate predicates;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]

@ -1,11 +1,9 @@
use assert_cmd::prelude::*;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
use utils::{self, fixture}; use utils::{self, fixture};
use wasm_pack::{self, manifest, Cli}; use wasm_pack::{self, license, manifest, readme};
#[test] #[test]
fn it_gets_the_crate_name_default_path() { fn it_gets_the_crate_name_default_path() {
@ -279,6 +277,63 @@ fn it_errors_when_wasm_bindgen_is_not_declared() {
assert!(crate_data.check_crate_config(&step).is_err()); assert!(crate_data.check_crate_config(&step).is_err());
} }
#[test]
fn it_sets_homepage_field_if_available_in_cargo_toml() {
// When 'homepage' is available
let fixture = utils::fixture::Fixture::new();
fixture.hello_world_src_lib().file(
"Cargo.toml",
r#"
[package]
authors = ["The wasm-pack developers"]
description = "so awesome rust+wasm package"
license = "WTFPL"
name = "homepage-field-test"
repository = "https://github.com/rustwasm/wasm-pack.git"
version = "0.1.0"
homepage = "https://rustwasm.github.io/wasm-pack/"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "=0.2"
[dev-dependencies]
wasm-bindgen-test = "=0.2"
"#,
);
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert_eq!(
pkg.homepage,
Some("https://rustwasm.github.io/wasm-pack/".to_string()),
);
// When 'homepage' is unavailable
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert_eq!(pkg.homepage, None);
}
#[test] #[test]
fn it_does_not_error_when_wasm_bindgen_is_declared() { fn it_does_not_error_when_wasm_bindgen_is_declared() {
let fixture = fixture::js_hello_world(); let fixture = fixture::js_hello_world();
@ -313,22 +368,15 @@ fn configure_wasm_bindgen_debug_incorrectly_is_error() {
debug-js-glue = "not a boolean" debug-js-glue = "not a boolean"
"#, "#,
); );
fixture
let cli = Cli::from_iter_safe(vec![ .wasm_pack()
"wasm-pack", .arg("build")
"build", .arg("--dev")
"--dev", .assert()
&fixture.path.display().to_string(), .failure()
]) .stderr(predicates::str::contains(
.unwrap(); "package.metadata.wasm-pack.profile.dev.wasm-bindgen.debug",
));
let result = fixture.run(cli.cmd);
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.iter_chain().any(|c| c
.to_string()
.contains("package.metadata.wasm-pack.profile.dev.wasm-bindgen.debug")));
} }
#[test] #[test]
@ -358,13 +406,76 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() {
debug-js-glue = true debug-js-glue = true
"#, "#,
) )
.hello_world_src_lib(); .hello_world_src_lib()
.install_local_wasm_bindgen();
fixture
.wasm_pack()
.arg("build")
.assert()
.success()
.stdout(predicates::str::contains(
"[WARN]: \"package.metadata.wasm-pack.profile.production\" is an unknown key and will \
be ignored. Please check your Cargo.toml.",
));
}
let result = manifest::CrateData::parse_crate_data(&fixture.path.join("Cargo.toml")); #[test]
fn it_lists_license_files_in_files_field_of_package_json() {
let fixture = fixture::dual_license();
let out_dir = fixture.path.join("pkg");
assert!(result.is_ok()); let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let manifest::ManifestAndUnsedKeys { unused_keys, .. } = result.unwrap(); let step = wasm_pack::progressbar::Step::new(3);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
license::copy_from_crate(&crate_data, &fixture.path, &out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.unwrap();
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert!(unused_keys.contains("package.metadata.wasm-pack.profile.production")); assert!(
pkg.files.contains(&"LICENSE-WTFPL".to_string()),
"LICENSE-WTFPL is not in files: {:?}",
pkg.files,
);
assert!(
pkg.files.contains(&"LICENSE-MIT".to_string()),
"LICENSE-MIT is not in files: {:?}",
pkg.files,
);
}
#[test]
fn it_lists_readme_in_files_field_of_package_json() {
let fixture = utils::fixture::Fixture::new();
fixture
.readme()
.hello_world_src_lib()
.cargo_toml("readme-test-for-package-json");
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();
let step = wasm_pack::progressbar::Step::new(3);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
readme::copy_from_crate(&fixture.path, &out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, false, "", &step)
.unwrap();
let package_json_path = &fixture.path.join("pkg").join("package.json");
fs::metadata(package_json_path).unwrap();
let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert!(
pkg.files.contains(&"README.md".to_string()),
"README.md is not in files: {:?}",
pkg.files,
);
} }

@ -1,41 +1,32 @@
use failure::Error; use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::env; use std::env;
use utils::fixture; use utils::fixture;
use wasm_pack::command::{build, test, Command};
fn assert_err<T>(result: Result<T, Error>, msg: &str) -> Error {
let error = result.err().expect("should have failed");
for e in error.iter_chain() {
println!("err: {}", e);
}
assert!(error.iter_chain().any(|e| e.to_string().contains(msg)));
error
}
#[test] #[test]
fn it_can_run_node_tests() { fn it_can_run_node_tests() {
let fixture = fixture::wbg_test_node(); let fixture = fixture::wbg_test_node();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let cmd = Command::Test(test::TestOptions { let _lock = fixture.lock();
path: Some(fixture.path.clone()), fixture
node: true, .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
..Default::default() .arg("--node")
}); .assert()
fixture.run(cmd).unwrap(); .success();
} }
#[test] #[test]
fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() {
let fixture = fixture::wbg_test_diff_versions(); let fixture = fixture::wbg_test_diff_versions();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let cmd = Command::Test(test::TestOptions { let _lock = fixture.lock();
path: Some(fixture.path.clone()), fixture
node: true, .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
..Default::default() .arg("--node")
}); .assert()
fixture.run(cmd).unwrap(); .success();
} }
#[test] #[test]
@ -75,33 +66,37 @@ fn it_can_run_browser_tests() {
return; return;
} }
let cmd = Command::Test(test::TestOptions { let mut cmd = fixture.wasm_pack();
path: Some(fixture.path.clone()), cmd.arg("test").arg("--headless");
firefox,
chrome, if firefox {
safari, cmd.arg("--firefox");
headless: true, }
mode: build::BuildMode::Noinstall, if chrome {
..Default::default() cmd.arg("--chrome");
}); }
if safari {
fixture.run(cmd).unwrap(); cmd.arg("--safari");
}
let _lock = fixture.lock();
cmd.assert().success();
} }
#[test] #[test]
fn it_can_run_failing_tests() { fn it_can_run_failing_tests() {
let fixture = fixture::wbg_test_fail(); let fixture = fixture::wbg_test_fail();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let cmd = Command::Test(test::TestOptions { let _lock = fixture.lock();
path: Some(fixture.path.clone()), fixture
node: true, .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
..Default::default() .arg("--node")
}); .assert()
assert_err( .failure()
fixture.run(cmd), .stderr(predicates::str::contains(
"Running Wasm tests with wasm-bindgen-test failed", "Running Wasm tests with wasm-bindgen-test failed",
); ));
} }
#[test] #[test]
@ -113,8 +108,6 @@ fn it_can_run_failing_tests() {
all(target_os = "windows", target_arch = "x86_64") all(target_os = "windows", target_arch = "x86_64")
))] ))]
fn it_can_find_a_webdriver_on_path() { fn it_can_find_a_webdriver_on_path() {
use std::process::Command;
let fixture = fixture::wbg_test_browser(); let fixture = fixture::wbg_test_browser();
let local_geckodriver = fixture.install_local_geckodriver(); let local_geckodriver = fixture.install_local_geckodriver();
let local_wasm_bindgen = fixture.install_local_wasm_bindgen(); let local_wasm_bindgen = fixture.install_local_wasm_bindgen();
@ -125,54 +118,44 @@ fn it_can_find_a_webdriver_on_path() {
let path = env::join_paths(paths).unwrap(); let path = env::join_paths(paths).unwrap();
let _lock = fixture.lock(); let _lock = fixture.lock();
fixture
let mut me = env::current_exe().unwrap(); .wasm_pack()
me.pop(); .env("PATH", &path)
me.pop();
me.push("wasm-pack");
let output = Command::new(&me)
.arg("test") .arg("test")
.arg("--firefox") .arg("--firefox")
.arg("--headless") .arg("--headless")
.arg("--mode") .arg("--mode")
.arg("no-install") .arg("no-install")
.env("PATH", &path) .assert()
.arg(&fixture.path) .success();
.output()
.unwrap();
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
println!("status: {}", output.status);
assert!(output.status.success());
} }
#[test] #[test]
fn it_requires_node_or_a_browser() { fn it_requires_node_or_a_browser() {
let fixture = fixture::wbg_test_node(); let fixture = fixture::wbg_test_node();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let _lock = fixture.lock();
let cmd = Command::Test(test::TestOptions { fixture
path: Some(fixture.path.clone()), .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
// Note: not setting node or any browser to true here. .assert()
..Default::default() .failure()
}); .stderr(predicates::str::contains("Must specify at least one of"));
assert_err(fixture.run(cmd), "Must specify at least one of");
} }
#[test] #[test]
fn the_headless_flag_requires_a_browser() { fn the_headless_flag_requires_a_browser() {
let fixture = fixture::wbg_test_node(); let fixture = fixture::wbg_test_node();
fixture.install_local_wasm_bindgen(); fixture.install_local_wasm_bindgen();
let _lock = fixture.lock();
let cmd = Command::Test(test::TestOptions { fixture
path: Some(fixture.path.clone()), .wasm_pack()
node: true, .arg("test")
mode: build::BuildMode::Noinstall, .arg("--node")
headless: true, .arg("--headless")
..Default::default() .assert()
}); .failure()
assert_err(fixture.run(cmd), "only applies to browser tests"); .stderr(predicates::str::contains("only applies to browser tests"));
} }
#[test] #[test]
@ -203,44 +186,18 @@ fn complains_about_missing_wasm_bindgen_test_dependency() {
) )
.hello_world_src_lib() .hello_world_src_lib()
.install_local_wasm_bindgen(); .install_local_wasm_bindgen();
let _lock = fixture.lock();
let cmd = Command::Test(test::TestOptions { fixture
path: Some(fixture.path.clone()), .wasm_pack()
node: true, .arg("test")
mode: build::BuildMode::Noinstall, .arg("--node")
..Default::default() .assert()
}); .failure()
let error = assert_err(fixture.run(cmd), "Ensure that you have"); .stderr(predicates::str::contains(
"Ensure that you have \"wasm-bindgen-test\" as a dependency in your Cargo.toml file",
// Test that the error message has two occurrences of "wasm-bindgen-test" in ))
// it. I am surprised to learn there is no `str` method to count .stderr(predicates::str::contains("[dev-dependencies]"))
// occurrences, so we find the first and the last and assert that they .stderr(predicates::str::contains("wasm-bindgen-test = \"0.2\""));
// aren't the same occurrence.
//
// This should protect against regresstions where we said:
//
// Ensure that you have "wasm-bindgen" as a dependency in your Cargo.toml file:
// [dev-dependencies]
// wasm-bindgen-test = "0.2"
//
// instead of
//
// Ensure that you have "wasm-bindgen-test" as a dependency in your Cargo.toml file:
// [dev-dependencies]
// wasm-bindgen-test = "0.2"
//
// Note that the whole reason we are doing this string manipulation instead
// of just doing `assert_eq!` is because the first occurrence of the
// dependency name is bolded with terminal escape codes and if I try to pipe
// the output to a text file, then the escape codes go away, so I can't
// figure out which exact escape codes are even used here.
let err_msg = error.to_string();
let first = err_msg.find("wasm-bindgen-test");
assert!(first.is_some());
let second = err_msg.rfind("wasm-bindgen-test");
assert!(second.is_some());
assert_ne!(first, second, "should have found two occurrences");
} }
#[test] #[test]
@ -276,15 +233,15 @@ fn renamed_crate_name_works() {
#[wasm_bindgen] #[wasm_bindgen]
pub fn one() -> u32 { 1 } pub fn one() -> u32 { 1 }
"#, "#,
); )
fixture.install_local_wasm_bindgen(); .install_local_wasm_bindgen();
let cmd = Command::Test(test::TestOptions { let _lock = fixture.lock();
path: Some(fixture.path.clone()), fixture
node: true, .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
..Default::default() .arg("--node")
}); .assert()
fixture.run(cmd).unwrap(); .success();
} }
#[test] #[test]
@ -324,13 +281,54 @@ fn cdylib_not_required() {
foo::foo(); foo::foo();
} }
"#, "#,
); )
fixture.install_local_wasm_bindgen(); .install_local_wasm_bindgen();
let cmd = Command::Test(test::TestOptions { let _lock = fixture.lock();
path: Some(fixture.path.clone()), fixture
node: true, .wasm_pack()
mode: build::BuildMode::Noinstall, .arg("test")
..Default::default() .arg("--node")
}); .assert()
fixture.run(cmd).unwrap(); .success();
}
#[test]
fn test_output_is_printed_once() {
let fixture = fixture::Fixture::new();
fixture
.readme()
.cargo_toml("test-output-printed-once")
.hello_world_src_lib()
.file(
"tests/node.rs",
r#"
extern crate wasm_bindgen;
extern crate wasm_bindgen_test;
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen_test]
fn yabba() {
log("YABBA DABBA DOO");
assert_eq!(1, 2);
}
"#,
)
.install_local_wasm_bindgen();
let _lock = fixture.lock();
fixture
.wasm_pack()
.arg("test")
.arg("--node")
.assert()
.failure()
.stderr(predicate::function(|err: &str| {
err.matches("YABBA DABBA DOO").count() == 1
}));
} }

@ -137,6 +137,39 @@ impl Fixture {
) )
} }
/// Add a `Cargo.toml` with a correctly configured `wasm-bindgen`
/// dependency, `wasm-bindgen-test` dev-dependency, and `crate-type =
/// ["cdylib"]`.
///
/// `name` is the crate's name.
/// `license_file` is license file path
pub fn cargo_toml_with_license_file(&self, name: &str, license_file: &str) -> &Self {
self.file(
"Cargo.toml",
&format!(
r#"
[package]
authors = ["The wasm-pack developers"]
description = "so awesome rust+wasm package"
name = "{}"
license-file = "{}"
repository = "https://github.com/rustwasm/wasm-pack.git"
version = "0.1.0"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "=0.2.21"
[dev-dependencies]
wasm-bindgen-test = "=0.2.21"
"#,
name, license_file
),
)
}
/// Add a `src/lib.rs` file that contains a "hello world" program. /// Add a `src/lib.rs` file that contains a "hello world" program.
pub fn hello_world_src_lib(&self) -> &Self { pub fn hello_world_src_lib(&self) -> &Self {
self.file( self.file(
@ -218,9 +251,14 @@ impl Fixture {
wasm_pack::test::webdriver::install_chromedriver(&cache, true).unwrap() wasm_pack::test::webdriver::install_chromedriver(&cache, true).unwrap()
} }
pub fn cache_dir(&self) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target")
.join("test_cache")
}
pub fn cache(&self) -> Cache { pub fn cache(&self) -> Cache {
let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target"); Cache::at(&self.cache_dir())
Cache::at(&target_dir.join("test_cache"))
} }
/// The `step_install_wasm_bindgen` and `step_run_wasm_bindgen` steps only /// The `step_install_wasm_bindgen` and `step_run_wasm_bindgen` steps only
@ -240,21 +278,14 @@ impl Fixture {
self self
} }
pub fn run(&self, cmd: wasm_pack::command::Command) -> Result<(), failure::Error> { /// Get a `wasm-pack` command configured to run in this fixure's temp
match cmd { /// directory and using the test cache.
wasm_pack::command::Command::Test(cmd) => { pub fn wasm_pack(&self) -> Command {
let _lock = self.lock(); use assert_cmd::prelude::*;
let mut test = wasm_pack::command::test::Test::try_from_opts(cmd)?; let mut cmd = Command::main_binary().unwrap();
test.set_cache(self.cache()); cmd.current_dir(&self.path);
test.run() cmd.env("WASM_PACK_CACHE", self.cache_dir());
} cmd
wasm_pack::command::Command::Build(cmd) => {
let mut build = wasm_pack::command::build::Build::try_from_opts(cmd)?;
build.set_cache(self.cache());
build.run()
}
_ => unreachable!(),
}
} }
pub fn lock(&self) -> MutexGuard<'static, ()> { pub fn lock(&self) -> MutexGuard<'static, ()> {
@ -646,3 +677,13 @@ pub fn dual_license() -> Fixture {
.hello_world_src_lib(); .hello_world_src_lib();
fixture fixture
} }
pub fn non_standard_license(license_file: &str) -> Fixture {
let fixture = Fixture::new();
fixture
.readme()
.cargo_toml_with_license_file("dual_license", license_file)
.file(license_file, "license file for test")
.hello_world_src_lib();
fixture
}

@ -23,6 +23,7 @@ pub struct NpmPackage {
pub types: String, pub types: String,
#[serde(default = "default_none", rename = "sideEffects")] #[serde(default = "default_none", rename = "sideEffects")]
pub side_effects: String, pub side_effects: String,
pub homepage: Option<String>,
} }
fn default_none() -> String { fn default_none() -> String {

@ -6,7 +6,8 @@ use wasm_pack::test::webdriver;
#[cfg(any( #[cfg(any(
all(target_os = "linux", target_arch = "x86_64"), all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "macos", target_arch = "x86_64"), all(target_os = "macos", target_arch = "x86_64"),
all(target_os = "windows", target_arch = "x86") all(target_os = "windows", target_arch = "x86"),
all(target_os = "windows", target_arch = "x86_64")
))] ))]
fn can_install_chromedriver() { fn can_install_chromedriver() {
let fixture = fixture::js_hello_world(); let fixture = fixture::js_hello_world();

Loading…
Cancel
Save