File tree Expand file tree Collapse file tree 5 files changed +107
-0
lines changed Expand file tree Collapse file tree 5 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ static/styles/vendor.css
66static /styles /app.css
77static /styles /fonts.css
88static /styles /noscript.css
9+ src /snapshots
Original file line number Diff line number Diff line change @@ -21,3 +21,6 @@ tera = "=1.20.0"
2121
2222[workspace ]
2323members = [" serve" ]
24+
25+ [dev-dependencies ]
26+ insta = { version = " 1.42.0" , features = [" filters" , " glob" ] }
Original file line number Diff line number Diff line change @@ -54,3 +54,28 @@ author: Blog post author (or on behalf of which team)
5454release: true (to be only used for official posts about Rust releases announcements)
5555---
5656```
57+
58+ ### Snapshot testing
59+
60+ If you're making changes to how the site is generated, you may want to check the impact your changes have on the output.
61+ For this purpose, there is a setup to do snapshot testing over the entire output directory.
62+ It's not run in CI, because the number of snapshots is too large.
63+ But you can run these tests locally as needed.
64+
65+ - Make sure you have [ cargo-insta] ( https://insta.rs/docs/quickstart/ ) installed.
66+
67+ - Generate the good snapshots to compare against, usually based off the master branch:
68+ ``` sh
69+ cargo insta test --accept --include-ignored
70+ ```
71+ Consider making a commit with these snapshots, so you can always check the diff of your changes with git:
72+ ``` sh
73+ git add --force src/snapshots # snapshots are ignored by default
74+ git commit --message " WIP add good snapshots"
75+ ```
76+ Since we can't merge the snapshots to main, don't forget to drop this commit when opening a pull request.
77+
78+ - Compare the output of the branch you're working on with the good snapshots:
79+ ``` sh
80+ cargo insta test --review --include-ignored
81+ ```
Original file line number Diff line number Diff line change @@ -302,3 +302,40 @@ pub fn main() -> eyre::Result<()> {
302302
303303 Ok ( ( ) )
304304}
305+
306+ #[ test]
307+ fn snapshot ( ) {
308+ main ( ) . unwrap ( ) ;
309+ let timestamped_files = [ "releases.json" , "feed.xml" ] ;
310+ let inexplicably_non_deterministic_files = [ "images/2023-08-rust-survey-2022/experiences.png" ] ;
311+ insta:: glob!( ".." , "site/**/*" , |path| {
312+ if path. is_dir( ) {
313+ return ;
314+ }
315+ let path = path. display( ) . to_string( ) ;
316+ if timestamped_files
317+ . into_iter( )
318+ . chain( inexplicably_non_deterministic_files)
319+ . any( |f| path. ends_with( f) )
320+ {
321+ // Skip troublesome files, e.g. they might contain timestamps.
322+ // If possible, they are tested separately below.
323+ return ;
324+ }
325+ let content = fs:: read( path) . unwrap( ) ;
326+ // insta can't deal with non-utf8 strings?
327+ let content = String :: from_utf8_lossy( & content) . into_owned( ) ;
328+ insta:: assert_snapshot!( content) ;
329+ } ) ;
330+
331+ // test files with timestamps filtered
332+ insta:: with_settings!( { filters => vec![
333+ ( r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2}" , "(filtered timestamp)" ) ,
334+ ] } , {
335+ for file in timestamped_files {
336+ let content = fs:: read( format!( "site/{file}" ) ) . unwrap( ) ;
337+ let content = String :: from_utf8_lossy( & content) . into_owned( ) ;
338+ insta:: assert_snapshot!( content) ;
339+ }
340+ } ) ;
341+ }
You can’t perform that action at this time.
0 commit comments