Skip to content

Commit 7a7abf9

Browse files
committed
Parse path and extra options together, then split them after.
This allows `wasm-pack` to have the same command line interface as `cargo` to pass through options such as `--no-default-features`.
1 parent f4f6588 commit 7a7abf9

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/command/test.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use lockfile::Lockfile;
1111
use log::info;
1212
use manifest;
1313
use std::path::PathBuf;
14+
use std::str::FromStr;
1415
use std::time::Instant;
1516
use structopt::clap::AppSettings;
1617
use test::{self, webdriver};
@@ -25,10 +26,6 @@ use test::{self, webdriver};
2526
)]
2627
/// Everything required to configure the `wasm-pack test` command.
2728
pub struct TestOptions {
28-
#[structopt(parse(from_os_str), long = "manifest-path")]
29-
/// The path to the Rust crate. If not set, searches up the path from the current dirctory.
30-
pub path: Option<PathBuf>,
31-
3229
#[structopt(long = "node")]
3330
/// Run the tests in Node.js.
3431
pub node: bool,
@@ -82,8 +79,14 @@ pub struct TestOptions {
8279
/// Build with the release profile.
8380
pub release: bool,
8481

85-
/// List of extra options to pass to `cargo test`
86-
pub extra_options: Vec<String>,
82+
/// Path to the Rust crate, and extra options to pass to `cargo test`.
83+
///
84+
/// If the path is not provided, this command searches up the path from the current dirctory
85+
///
86+
/// This is a workaround to allow wasm pack to provide the same command line interface as `cargo`.
87+
/// See <https://github.com/rustwasm/wasm-pack/pull/851> for more information.
88+
#[structopt(allow_hyphen_values = true)]
89+
pub path_and_extra_options: Vec<String>,
8790
}
8891

8992
/// A configured `wasm-pack test` command.
@@ -111,7 +114,6 @@ impl Test {
111114
/// Construct a test command from the given options.
112115
pub fn try_from_opts(test_opts: TestOptions) -> Result<Self, Error> {
113116
let TestOptions {
114-
path,
115117
node,
116118
mode,
117119
headless,
@@ -122,9 +124,23 @@ impl Test {
122124
geckodriver,
123125
safari,
124126
safaridriver,
125-
extra_options,
127+
mut path_and_extra_options,
126128
} = test_opts;
127129

130+
let first_arg_is_path = path_and_extra_options
131+
.get(0)
132+
.map(|first_arg| !first_arg.starts_with("-"))
133+
.unwrap_or(false);
134+
135+
let (path, extra_options) = if first_arg_is_path {
136+
let path = PathBuf::from_str(&path_and_extra_options.remove(0))?;
137+
let extra_options = path_and_extra_options;
138+
139+
(Some(path), extra_options)
140+
} else {
141+
(None, path_and_extra_options)
142+
};
143+
128144
let crate_path = get_crate_path(path)?;
129145
let crate_data = manifest::CrateData::new(&crate_path, None)?;
130146
let any_browser = chrome || firefox || safari;

0 commit comments

Comments
 (0)