How best to snapshot-test HTML snippets? #877
Replies: 1 comment 1 reply
-
|
I'm also looking to test file-to-file transformations and would like the tooling to not impose a custom serialisation format. This way regular tools would still work with the outputs. I'd like my test data to look something like, $CRATE_ROOT
└── data
└── test_fixtures
├── inputs
│ └── simple_test.org # Test data
└── outputs
├── simple_test.org.html # Output from processing ../inputs/simple_test.org
└── simple_test.org.html.snap # Has extra metadata in RON/JSON format.For instance, if I'm targeting HTML outputs I'd like the output files to pass validation with Before just dropping the +1 I gave it a try and got pretty much there with, #[test]
fn simple_insta() {
let path = Path::new("data/test_fixtures/simple_doc.org");
let contents = std::fs::read_to_string(path).unwrap();
let doc = MyDoc::new_from_string(&contents).unwrap();
let html = doc.render_html().unwrap();
let golden_path = path.with_extension("html");
let golden_path = String::from(golden_path.to_str().unwrap());
insta::assert_binary_snapshot!(&golden_path, html.as_bytes().to_vec());
}I don't like the outputs living in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing tests for a not-quite-Markdown parser. It parses to a node tree, which I can test using debug serialization, and the node tree in turn can be rendered to strings containing HTML.
I'm unsure how best to snapshot-test those HTML strings. If the order of classes on an element changes, the browser won't actually care, right? But I don't think there's any good quality HTML parser that produces a serializable DOM tree right now…
Does anyone know of a good approach for this?
Beta Was this translation helpful? Give feedback.
All reactions