@@ -47,7 +47,11 @@ enum Task {
47
47
/// Installs the tools the project depends on.
48
48
InstallTools ,
49
49
/// Runs the web driver tests in the tests directory.
50
- WebTests ,
50
+ WebTests {
51
+ /// Optional 'book html' directory - if set, will also refresh the list of slides used by slide size test.
52
+ #[ arg( short, long) ]
53
+ dir : Option < PathBuf > ,
54
+ } ,
51
55
/// Tests all included Rust snippets.
52
56
RustTests ,
53
57
/// Starts a web server with the course.
@@ -76,7 +80,7 @@ fn execute_task() -> Result<()> {
76
80
let cli = Cli :: parse ( ) ;
77
81
match cli. task {
78
82
Task :: InstallTools => install_tools ( ) ?,
79
- Task :: WebTests => run_web_tests ( ) ?,
83
+ Task :: WebTests { dir } => run_web_tests ( dir ) ?,
80
84
Task :: RustTests => run_rust_tests ( ) ?,
81
85
Task :: Serve { language, output } => start_web_server ( language, output) ?,
82
86
Task :: Build { language, output } => build ( language, output) ?,
@@ -94,7 +98,7 @@ fn install_tools() -> Result<()> {
94
98
let install_args = vec ! [
95
99
// The --locked flag is important for reproducible builds. It also
96
100
// avoids breakage due to skews between mdbook and mdbook-svgbob.
97
- vec![ "mdbook" , "--locked" , "--version" , "0.4.48 " ] ,
101
+ vec![ "mdbook" , "--locked" , "--version" , "0.4.51 " ] ,
98
102
vec![ "mdbook-svgbob" , "--locked" , "--version" , "0.2.2" ] ,
99
103
vec![ "mdbook-pandoc" , "--locked" , "--version" , "0.10.4" ] ,
100
104
vec![ "mdbook-i18n-helpers" , "--locked" , "--version" , "0.3.6" ] ,
@@ -127,16 +131,41 @@ fn install_tools() -> Result<()> {
127
131
Ok ( ( ) )
128
132
}
129
133
130
- fn run_web_tests ( ) -> Result < ( ) > {
134
+ fn run_web_tests ( dir : Option < PathBuf > ) -> Result < ( ) > {
131
135
println ! ( "Running web tests..." ) ;
132
136
137
+ let absolute_dir = dir. map ( |d| d. canonicalize ( ) ) . transpose ( ) ?;
138
+
139
+ if let Some ( d) = & absolute_dir {
140
+ println ! ( "Refreshing slide lists..." ) ;
141
+ let path_to_refresh_slides_script = Path :: new ( "tests" )
142
+ . join ( "src" )
143
+ . join ( "slides" )
144
+ . join ( "create-slide.list.sh" ) ;
145
+ let status = Command :: new ( path_to_refresh_slides_script)
146
+ . current_dir ( Path :: new ( env ! ( "CARGO_WORKSPACE_DIR" ) ) )
147
+ . arg ( d)
148
+ . status ( )
149
+ . expect ( "Failed to execute create-slide.list.sh" ) ;
150
+
151
+ if !status. success ( ) {
152
+ let error_message = format ! (
153
+ "Command 'cargo xtask web-tests' exited with status code: {}" ,
154
+ status. code( ) . unwrap( )
155
+ ) ;
156
+ return Err ( anyhow ! ( error_message) ) ;
157
+ }
158
+ }
159
+
133
160
let path_to_tests_dir = Path :: new ( env ! ( "CARGO_WORKSPACE_DIR" ) ) . join ( "tests" ) ;
161
+ let mut command = Command :: new ( "npm" ) ;
162
+ command. current_dir ( path_to_tests_dir. to_str ( ) . unwrap ( ) ) ;
163
+ command. arg ( "test" ) ;
134
164
135
- let status = Command :: new ( "npm" )
136
- . current_dir ( path_to_tests_dir. to_str ( ) . unwrap ( ) )
137
- . arg ( "test" )
138
- . status ( )
139
- . expect ( "Failed to execute npm test" ) ;
165
+ if let Some ( d) = absolute_dir {
166
+ command. env ( "TEST_BOOK_DIR" , d) ;
167
+ }
168
+ let status = command. status ( ) . expect ( "Failed to execute npm test" ) ;
140
169
141
170
if !status. success ( ) {
142
171
let error_message = format ! (
0 commit comments