Preserve comment order in test calls (#20043)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
0631073e47
commit
891accaaab
4 files changed
+205
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#### Preserve comment order in test calls (#20043 by @lllleolin-max)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
test("x", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000);
|
||||
|
||||
// Prettier stable
|
||||
test("x", () => {
|
||||
run();
|
||||
}, // second // first
|
||||
// third
|
||||
60000);
|
||||
|
||||
// Prettier main
|
||||
test(
|
||||
"x",
|
||||
() => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000,
|
||||
);
|
||||
```
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getCallArguments } from "./call-arguments.js";
|
||||
import { hasComment } from "./comments.js";
|
||||
import { getFunctionParameters } from "./function-parameters.js";
|
||||
import { isNodeMatches } from "./is-node-matches.js";
|
||||
import {
|
||||
@@ -104,6 +105,10 @@ function isTestCall(node, parent) {
|
||||
|
||||
const args = getCallArguments(node);
|
||||
|
||||
if (args.some((arg) => hasComment(arg))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length === 1) {
|
||||
if (isAngularTestWrapper(node) && isTestCall(parent)) {
|
||||
return isFunctionOrArrowExpression(args[0]);
|
||||
|
||||
@@ -534,6 +534,151 @@ function x() {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js - {"arrowParens":"avoid"} format 1`] = `
|
||||
====================================options=====================================
|
||||
arrowParens: "avoid"
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
test("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000);
|
||||
|
||||
it("comments before timeout", function (done) {
|
||||
done();
|
||||
},
|
||||
// first
|
||||
// second
|
||||
60000);
|
||||
|
||||
describe.only("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
60000);
|
||||
|
||||
test("comments before callback", // first
|
||||
// second
|
||||
() => {
|
||||
run();
|
||||
});
|
||||
|
||||
=====================================output=====================================
|
||||
test(
|
||||
"comments after callback",
|
||||
() => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000,
|
||||
);
|
||||
|
||||
it(
|
||||
"comments before timeout",
|
||||
function (done) {
|
||||
done();
|
||||
},
|
||||
// first
|
||||
// second
|
||||
60000,
|
||||
);
|
||||
|
||||
describe.only(
|
||||
"comments after callback",
|
||||
() => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
60000,
|
||||
);
|
||||
|
||||
test(
|
||||
"comments before callback", // first
|
||||
// second
|
||||
() => {
|
||||
run();
|
||||
},
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
test("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000);
|
||||
|
||||
it("comments before timeout", function (done) {
|
||||
done();
|
||||
},
|
||||
// first
|
||||
// second
|
||||
60000);
|
||||
|
||||
describe.only("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
60000);
|
||||
|
||||
test("comments before callback", // first
|
||||
// second
|
||||
() => {
|
||||
run();
|
||||
});
|
||||
|
||||
=====================================output=====================================
|
||||
test(
|
||||
"comments after callback",
|
||||
() => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000,
|
||||
);
|
||||
|
||||
it(
|
||||
"comments before timeout",
|
||||
function (done) {
|
||||
done();
|
||||
},
|
||||
// first
|
||||
// second
|
||||
60000,
|
||||
);
|
||||
|
||||
describe.only(
|
||||
"comments after callback",
|
||||
() => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
60000,
|
||||
);
|
||||
|
||||
test(
|
||||
"comments before callback", // first
|
||||
// second
|
||||
() => {
|
||||
run();
|
||||
},
|
||||
);
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`jest-each.js - {"arrowParens":"avoid"} format 1`] = `
|
||||
====================================options=====================================
|
||||
arrowParens: "avoid"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
test("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
// third
|
||||
60000);
|
||||
|
||||
it("comments before timeout", function (done) {
|
||||
done();
|
||||
},
|
||||
// first
|
||||
// second
|
||||
60000);
|
||||
|
||||
describe.only("comments after callback", () => {
|
||||
run();
|
||||
}, // first
|
||||
// second
|
||||
60000);
|
||||
|
||||
test("comments before callback", // first
|
||||
// second
|
||||
() => {
|
||||
run();
|
||||
});
|
||||
Reference in new issue
Block a user