Skip to content

Commit

Permalink
editorconfig: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed May 16, 2024
1 parent 9162f48 commit 9e52d18
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/biome_cli/tests/cases/editorconfig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::run_cli;
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload};
use biome_console::BufferConsole;
use biome_fs::MemoryFileSystem;
use biome_service::DynRef;
use bpaf::Args;
use std::path::Path;

#[test]
fn should_use_editorconfig() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let editorconfig = Path::new(".editorconfig");
fs.insert(
editorconfig.into(),
r#"
[*]
max_line_length = 300
"#,
);

let test_file = Path::new("test.js");
fs.insert(test_file.into(), r#"console.log("really long string that should cause a break if the line width remains at the default 80 characters"); "#);

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("check"), test_file.as_os_str().to_str().unwrap()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_use_editorconfig",
fs,
console,
result,
));
}
1 change: 1 addition & 0 deletions crates/biome_cli/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod config_extends;
mod config_path;
mod cts_files;
mod diagnostics;
mod editorconfig;
mod handle_astro_files;
mod handle_svelte_files;
mod handle_vue_files;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `.editorconfig`

```editorconfig
[*]
max_line_length = 300
```

## `test.js`

```js
console.log("really long string that should cause a break if the line width remains at the default 80 characters");
```

# Termination Message

```block
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
test.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Formatter would have printed the following content:
1 │ - console.log("really·long·string·that·should·cause·a·break·if·the·line·width·remains·at·the·default·80·characters");·
1 │ + console.log(
2 │ + → "really·long·string·that·should·cause·a·break·if·the·line·width·remains·at·the·default·80·characters",
3 │ + );
4 │ +
```

```block
Checked 1 file in <TIME>. No fixes needed.
Found 1 error.
```

0 comments on commit 9e52d18

Please sign in to comment.