@@ -11,6 +11,7 @@ use lockfile::Lockfile;
11
11
use log:: info;
12
12
use manifest;
13
13
use std:: path:: PathBuf ;
14
+ use std:: str:: FromStr ;
14
15
use std:: time:: Instant ;
15
16
use structopt:: clap:: AppSettings ;
16
17
use test:: { self , webdriver} ;
@@ -25,10 +26,6 @@ use test::{self, webdriver};
25
26
) ]
26
27
/// Everything required to configure the `wasm-pack test` command.
27
28
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
-
32
29
#[ structopt( long = "node" ) ]
33
30
/// Run the tests in Node.js.
34
31
pub node : bool ,
@@ -82,8 +79,14 @@ pub struct TestOptions {
82
79
/// Build with the release profile.
83
80
pub release : bool ,
84
81
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 > ,
87
90
}
88
91
89
92
/// A configured `wasm-pack test` command.
@@ -111,7 +114,6 @@ impl Test {
111
114
/// Construct a test command from the given options.
112
115
pub fn try_from_opts ( test_opts : TestOptions ) -> Result < Self , Error > {
113
116
let TestOptions {
114
- path,
115
117
node,
116
118
mode,
117
119
headless,
@@ -122,9 +124,23 @@ impl Test {
122
124
geckodriver,
123
125
safari,
124
126
safaridriver,
125
- extra_options ,
127
+ mut path_and_extra_options ,
126
128
} = test_opts;
127
129
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
+
128
144
let crate_path = get_crate_path ( path) ?;
129
145
let crate_data = manifest:: CrateData :: new ( & crate_path, None ) ?;
130
146
let any_browser = chrome || firefox || safari;
0 commit comments