Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
test(rome_js_formatter): Add prettier's JSX tests (#3255)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 20, 2022
1 parent 51f9f0f commit 9a767d6
Show file tree
Hide file tree
Showing 91 changed files with 6,710 additions and 186 deletions.
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/tests/prettier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct TestInfo {

mod check_reformat;

tests_macros::gen_tests! {"tests/specs/prettier/{js,typescript}/**/*.{js,ts,jsx,tsx}", crate::test_snapshot, "script"}
tests_macros::gen_tests! {"tests/specs/prettier/{js,typescript,jsx}/**/*.{js,ts,jsx,tsx}", crate::test_snapshot, "script"}

const PRETTIER_IGNORE: &str = "prettier-ignore";
const ROME_IGNORE: &str = "rome-ignore format: prettier ignore";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export {
// a
foo1,

// b
bar1,
baz1,
Expand All @@ -14,7 +13,6 @@ const baz2 = 1;
export {
// a
foo2,

// b
bar2,
baz2,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,3 @@ if (
) {
a;
}

if (
// comment
1
) {
b;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
info:
test_file: js/if/trailing_comment.js
---

# Input
Expand All @@ -17,13 +19,6 @@ if (
) {
a;
}

if (
// comment
1
) {
b;
}
```


Expand All @@ -42,17 +37,6 @@ if (
}
if (code === 92) {
/* '\' */
@@ -16,3 +15,10 @@
) {
a;
}
+
+if (
+ // comment
+ 1
+) {
+ b;
+}
```

# Output
Expand All @@ -75,13 +59,6 @@ if (
) {
a;
}

if (
// comment
1
) {
b;
}
```


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { foo2 } from "foo.json" assert { type: "json" };
export { default as foo2 } from "foo.json" assert { type: "json" };
export * from "foo.json" assert { type: "json" };
export * as foo3 from "foo.json" assert { type: "json" };
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { foo2 } from "foo.json" assert { type: "json" };
export { default as foo2 } from "foo.json" assert { type: "json" };
export * from "foo.json" assert { type: "json" };
export * as foo3 from "foo.json" assert { type: "json" };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a)
.bar()
.leet();
foo(~a)
.bar()
.leet();
foo(++a)
.bar()
.leet();
foo(--a)
.bar()
.leet();
foo(a++)
.bar()
.leet();
foo(a--)
.bar()
.leet();
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
info:
test_file: js/method-chain/13018.js
---

# Input

```js
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
```


# Prettier differences

```diff
--- Prettier
+++ Rome
@@ -1,20 +1,8 @@
foo(_a).bar().leet();
foo(-a).bar().leet();
-foo(+a)
- .bar()
- .leet();
-foo(~a)
- .bar()
- .leet();
-foo(++a)
- .bar()
- .leet();
-foo(--a)
- .bar()
- .leet();
-foo(a++)
- .bar()
- .leet();
-foo(a--)
- .bar()
- .leet();
+foo(+a).bar().leet();
+foo(~a).bar().leet();
+foo(++a).bar().leet();
+foo(--a).bar().leet();
+foo(a++).bar().leet();
+foo(a--).bar().leet();
```

# Output

```js
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
```



Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let fn =a((x ) => {
<<<PRETTIER_RANGE_START>>> quux (); //<<<PRETTIER_RANGE_END>>>
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let fn = a((x) => {
quux(); //
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
info:
test_file: js/range/function-body.js
---

# Input

```js
let fn =a((x ) => {
quux (); //
});
```


# Prettier differences

```diff
--- Prettier
+++ Rome
@@ -1,3 +1,3 @@
-let fn = a((x) => {
+let fn =a((x ) => {
quux(); //
});
```

# Output

```js
let fn =a((x ) => {
quux(); //
});
```



Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ const taskLater = #{ ...taskNow, status: "DONE" }

// A reminder: The ordering of keys in record literals does not affect equality (and is not retained)
assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 })

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
source: crates/rome_js_formatter/tests/prettier_tests.rs
info:
test_file: js/record/spread.js
---

# Input
Expand All @@ -11,7 +13,6 @@ const taskLater = #{ ...taskNow, status: "DONE" }

// A reminder: The ordering of keys in record literals does not affect equality (and is not retained)
assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 })

```


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://github.com/prettier/prettier/pull/13274

const loremIpsumFooBazBar1 = 'Multiline string\
Multiline string\
'

const loremIpsumFooBazBar2 = 'Multiline string\
Multiline string\
Multiline string'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://github.com/prettier/prettier/pull/13274

const loremIpsumFooBazBar1 = "Multiline string\
Multiline string\
";

const loremIpsumFooBazBar2 =
"Multiline string\
Multiline string\
Multiline string";
Loading

0 comments on commit 9a767d6

Please sign in to comment.