fix(javascript): do not apply test call formatting to arrow without body (#5366)

master
Ika 2018-11-08 14:00:42 +08:00 committed by GitHub
parent 4b51907b87
commit fd8ec95e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 2 deletions

View File

@ -6204,8 +6204,10 @@ function isTestCall(n, parent) {
return false;
}
return (
(isFunctionOrArrowExpression(n.arguments[1]) &&
n.arguments[1].params.length <= 1) ||
(n.arguments.length === 2
? isFunctionOrArrowExpression(n.arguments[1])
: isFunctionOrArrowExpressionWithBody(n.arguments[1]) &&
n.arguments[1].params.length <= 1) ||
isAngularTestWrapper(n.arguments[1])
);
}
@ -6249,6 +6251,14 @@ function isFunctionOrArrowExpression(node) {
);
}
function isFunctionOrArrowExpressionWithBody(node) {
return (
node.type === "FunctionExpression" ||
(node.type === "ArrowFunctionExpression" &&
node.body.type === "BlockStatement")
);
}
function isUnitTestSetUp(n) {
const unitTestSetUpRe = /^(before|after)(Each|All)$/;
return (

View File

@ -167,6 +167,8 @@ it("does something really long and complicated so I have to write a very long na
// code
}));
it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS));
/*
* isTestCall(parent) should only be called when parent exists
* and parent.type is CallExpression. This test makes sure that
@ -190,6 +192,9 @@ it("does something really long and complicated so I have to write a very long na
// code
}));
it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() =>
new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS()));
/*
* isTestCall(parent) should only be called when parent exists
* and parent.type is CallExpression. This test makes sure that
@ -218,6 +223,8 @@ it("does something really long and complicated so I have to write a very long na
// code
}));
it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS));
/*
* isTestCall(parent) should only be called when parent exists
* and parent.type is CallExpression. This test makes sure that
@ -241,6 +248,9 @@ it("does something really long and complicated so I have to write a very long na
// code
}));
it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() =>
new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS()));
/*
* isTestCall(parent) should only be called when parent exists
* and parent.type is CallExpression. This test makes sure that
@ -692,6 +702,17 @@ it(\`handles
it("does something quick", () => {
console.log("hello!")
}, 1000000000)
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10))
);
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10)),
250
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Shouldn't break
@ -826,6 +847,15 @@ it("does something quick", () => {
console.log("hello!");
}, 1000000000);
it("succeeds if the test finishes in time", () =>
new Promise(resolve => setTimeout(resolve, 10)));
it(
"succeeds if the test finishes in time",
() => new Promise(resolve => setTimeout(resolve, 10)),
250
);
`;
exports[`test_declarations.js - flow-verify 2`] = `
@ -948,6 +978,17 @@ it(\`handles
it("does something quick", () => {
console.log("hello!")
}, 1000000000)
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10))
);
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10)),
250
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Shouldn't break
@ -1082,4 +1123,13 @@ it("does something quick", () => {
console.log("hello!");
}, 1000000000);
it("succeeds if the test finishes in time", () =>
new Promise((resolve) => setTimeout(resolve, 10)));
it(
"succeeds if the test finishes in time",
() => new Promise((resolve) => setTimeout(resolve, 10)),
250
);
`;

View File

@ -14,6 +14,8 @@ it("does something really long and complicated so I have to write a very long na
// code
}));
it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS));
/*
* isTestCall(parent) should only be called when parent exists
* and parent.type is CallExpression. This test makes sure that

View File

@ -117,3 +117,14 @@ it(`handles
it("does something quick", () => {
console.log("hello!")
}, 1000000000)
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10))
);
it(
'succeeds if the test finishes in time',
() => new Promise(resolve => setTimeout(resolve, 10)),
250
);