@@ -47,7 +47,11 @@ enum Task {
4747 /// Installs the tools the project depends on.
4848 InstallTools ,
4949 /// 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+ } ,
5155 /// Tests all included Rust snippets.
5256 RustTests ,
5357 /// Starts a web server with the course.
@@ -76,7 +80,7 @@ fn execute_task() -> Result<()> {
7680 let cli = Cli :: parse ( ) ;
7781 match cli. task {
7882 Task :: InstallTools => install_tools ( ) ?,
79- Task :: WebTests => run_web_tests ( ) ?,
83+ Task :: WebTests { dir } => run_web_tests ( dir ) ?,
8084 Task :: RustTests => run_rust_tests ( ) ?,
8185 Task :: Serve { language, output } => start_web_server ( language, output) ?,
8286 Task :: Build { language, output } => build ( language, output) ?,
@@ -94,7 +98,7 @@ fn install_tools() -> Result<()> {
9498 let install_args = vec ! [
9599 // The --locked flag is important for reproducible builds. It also
96100 // 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 " ] ,
98102 vec![ "mdbook-svgbob" , "--locked" , "--version" , "0.2.2" ] ,
99103 vec![ "mdbook-pandoc" , "--locked" , "--version" , "0.10.4" ] ,
100104 vec![ "mdbook-i18n-helpers" , "--locked" , "--version" , "0.3.6" ] ,
@@ -127,16 +131,41 @@ fn install_tools() -> Result<()> {
127131 Ok ( ( ) )
128132}
129133
130- fn run_web_tests ( ) -> Result < ( ) > {
134+ fn run_web_tests ( dir : Option < PathBuf > ) -> Result < ( ) > {
131135 println ! ( "Running web tests..." ) ;
132136
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+
133160 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" ) ;
134164
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" ) ;
140169
141170 if !status. success ( ) {
142171 let error_message = format ! (
0 commit comments