-
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(format/html): set up test infrastructure (#3798)
- Loading branch information
Showing
15 changed files
with
258 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{env, path::Path}; | ||
|
||
use biome_formatter::{IndentStyle, IndentWidth}; | ||
use biome_formatter_test::test_prettier_snapshot::{PrettierSnapshot, PrettierTestFile}; | ||
use biome_html_formatter::{context::HtmlFormatOptions, HtmlFormatLanguage}; | ||
use biome_html_syntax::HtmlFileSource; | ||
|
||
mod language; | ||
|
||
tests_macros::gen_tests! {"tests/specs/prettier/**/*.html", crate::test_snapshot, "script"} | ||
|
||
#[allow(dead_code)] | ||
fn test_snapshot(input: &'static str, _: &str, _: &str, _: &str) { | ||
countme::enable(true); | ||
|
||
let root_path = Path::new(concat!( | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/tests/specs/prettier/" | ||
)); | ||
|
||
let test_file = PrettierTestFile::new(input, root_path); | ||
let source_type = HtmlFileSource::html(); | ||
|
||
let options = HtmlFormatOptions::new() | ||
.with_indent_style(IndentStyle::Space) | ||
.with_indent_width(IndentWidth::default()); | ||
|
||
let language = language::HtmlTestFormatLanguage::new(source_type); | ||
|
||
let snapshot = PrettierSnapshot::new(test_file, language, HtmlFormatLanguage::new(options)); | ||
|
||
snapshot.test() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use biome_formatter_test::spec::{SpecSnapshot, SpecTestFile}; | ||
use biome_html_formatter::{context::HtmlFormatOptions, HtmlFormatLanguage}; | ||
use biome_html_syntax::HtmlFileSource; | ||
use std::path::Path; | ||
|
||
mod language { | ||
include!("language.rs"); | ||
} | ||
|
||
/// [insta.rs](https://insta.rs/docs) snapshot testing | ||
/// | ||
/// For better development workflow, run | ||
/// `cargo watch -i '*.new' -x 'test -p biome_js_formatter formatter'` | ||
/// | ||
/// To review and commit the snapshots, `cargo install cargo-insta`, and run | ||
/// `cargo insta review` or `cargo insta accept` | ||
/// | ||
/// The input and the expected output are stored as dedicated files in the `tests/specs` directory where | ||
/// the input file name is `{spec_name}.json` and the output file name is `{spec_name}.json.snap`. | ||
/// | ||
/// Specs can be grouped in directories by specifying the directory name in the spec name. Examples: | ||
/// | ||
/// # Examples | ||
/// | ||
/// * `json/null` -> input: `tests/specs/json/null.json`, expected output: `tests/specs/json/null.json.snap` | ||
/// * `null` -> input: `tests/specs/null.json`, expected output: `tests/specs/null.json.snap` | ||
pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _file_type: &str) { | ||
let root_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/specs/")); | ||
|
||
let Some(test_file) = SpecTestFile::try_from_file(spec_input_file, root_path, None) else { | ||
return; | ||
}; | ||
|
||
let source_type: HtmlFileSource = test_file.input_file().as_path().try_into().unwrap(); | ||
|
||
let options = HtmlFormatOptions::new(); | ||
let language = language::HtmlTestFormatLanguage::new(source_type); | ||
|
||
let snapshot = SpecSnapshot::new( | ||
test_file, | ||
test_directory, | ||
language, | ||
HtmlFormatLanguage::new(options), | ||
); | ||
|
||
snapshot.test() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod quick_test; | ||
mod spec_test; | ||
|
||
mod formatter { | ||
|
||
mod html { | ||
tests_macros::gen_tests! {"tests/specs/**/*.html", crate::spec_test::run, "unknown"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!DOCTYPE html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: example.html | ||
--- | ||
# Input | ||
|
||
```html | ||
<!DOCTYPE html> | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
----- | ||
|
||
```html | ||
<!DOCTYPE html> | ||
``` |
12 changes: 12 additions & 0 deletions
12
crates/biome_html_formatter/tests/specs/prettier/prepare_tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const {extractPrettierTests} = require("../../../../biome_formatter_test/src/prettier/prepare_tests"); | ||
|
||
async function main() { | ||
await extractPrettierTests("html", { | ||
parser: "html", | ||
}); | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.