Skip to content

Commit

Permalink
Add snapshot tests for migrate <eslint|prettier> --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
unvalley committed May 19, 2024
1 parent 9b9994b commit 3d18445
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 0 deletions.
53 changes: 53 additions & 0 deletions crates/biome_cli/tests/commands/migrate_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,59 @@ fn migrate_eslintrcjson_write() {
));
}

#[test]
fn migrate_eslintrcjson_fix() {
let biomejson = r#"{ "linter": { "enabled": true } }"#;
let eslintrc = r#"{
"ignorePatterns": [
"**/*.test.js", // trailing comma amd comment
],
"globals": {
"var1": "writable",
"var2": "readonly"
},
"rules": {
"dot-notation": 0,
"default-param-last": "off",
"eqeqeq": "warn",
"getter-return": [2,
// support unknown options
{ "allowImplicit": true }
],
"no-eval": 1,
"no-extra-label": ["error"]
},
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
}
}],
"unknownField": "ignored"
}"#;

let mut fs = MemoryFileSystem::default();
fs.insert(Path::new("biome.json").into(), biomejson.as_bytes());
fs.insert(Path::new(".eslintrc.json").into(), eslintrc.as_bytes());

let mut console = BufferConsole::default();
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["migrate", "eslint", "--fix"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"migrate_eslintrcjson_fix",
fs,
console,
result,
));
}

#[test]
fn migrate_eslintrcjson_override_existing_config() {
let biomejson = r#"{ "linter": { "rules": { "recommended": true, "suspicious": { "noDoubleEquals": "error" } } } }"#;
Expand Down
31 changes: 31 additions & 0 deletions crates/biome_cli/tests/commands/migrate_prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,37 @@ fn prettier_migrate_write() {
));
}

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

let configuration = r#"{ "linter": { "enabled": true } }"#;
let prettier = r#"{ "useTabs": false, "semi": true, "singleQuote": true }"#;

let configuration_path = Path::new("biome.json");
fs.insert(configuration_path.into(), configuration.as_bytes());

let prettier_path = Path::new(".prettierrc");
fs.insert(prettier_path.into(), prettier.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("migrate"), "prettier", "--fix"].as_slice()),
);

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

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"prettier_migrate_fix",
fs,
console,
result,
));
}

#[test]
fn prettierjson_migrate_write() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": { "noUselessLabel": "error", "useLiteralKeys": "off" },
"security": { "noGlobalEval": "warn" },
"style": { "useDefaultParameterLast": "off" },
"suspicious": { "noDoubleEquals": "warn", "useGetterReturn": "error" }
},
"ignore": ["**/*.test.js"]
},
"javascript": { "globals": ["var2", "var1"] },
"overrides": [
{
"ignore": ["*.test.js"],
"include": ["bin/*.js", "lib/*.js"],
"linter": { "rules": { "suspicious": { "noDoubleEquals": "off" } } }
}
]
}
```

## `.eslintrc.json`

```json
{
"ignorePatterns": [
"**/*.test.js", // trailing comma amd comment
],
"globals": {
"var1": "writable",
"var2": "readonly"
},
"rules": {
"dot-notation": 0,
"default-param-last": "off",
"eqeqeq": "warn",
"getter-return": [2,
// support unknown options
{ "allowImplicit": true }
],
"no-eval": 1,
"no-extra-label": ["error"]
},
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
}
}],
"unknownField": "ignored"
}
```

# Emitted Messages

```block
.eslintrc.json has been successfully migrated.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto"
},
"linter": { "enabled": true },
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
}
}
```

## `.prettierrc`

```prettierrc
{ "useTabs": false, "semi": true, "singleQuote": true }
```

# Emitted Messages

```block
.prettierrc has been successfully migrated.
```

0 comments on commit 3d18445

Please sign in to comment.