Skip to content

Commit

Permalink
Add support for timeouts passed as integers to test functions (#5085)
Browse files Browse the repository at this point in the history
* Add support for timeouts passed as integers to test functions

* ;
  • Loading branch information
j-f1 committed Sep 13, 2018
1 parent f7a6625 commit 5972039
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5814,12 +5814,16 @@ function isTestCall(n, parent) {
if (isUnitTestSetUp(n)) {
return isAngularTestWrapper(n.arguments[0]);
}
} else if (n.arguments.length === 2) {
} else if (n.arguments.length === 2 || n.arguments.length === 3) {
if (
((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) ||
isSkipOrOnlyBlock(n)) &&
(isTemplateLiteral(n.arguments[0]) || isStringLiteral(n.arguments[0]))
) {
// it("name", () => { ... }, 2500)
if (n.arguments[2] && !isNumericLiteral(n.arguments[2])) {
return false;
}
return (
(isFunctionOrArrowExpression(n.arguments[1].type) &&
n.arguments[1].params.length <= 1) ||
Expand Down
52 changes: 52 additions & 0 deletions tests/test_declarations/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,19 @@ it.only.only("does something really long and complicated so I have to write a ve
});
xskip("does something really long and complicated so I have to write a very long name for the test", () => {});
// timeout
it(\`handles
some
newlines
does something really long and complicated so I have to write a very long name for the test\`, () => {
console.log("hello!");
}, 2500)
it("does something quick", () => {
console.log("hello!")
}, 1000000000)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Shouldn't break
Expand Down Expand Up @@ -800,6 +813,19 @@ xskip(
() => {}
);
// timeout
it(\`handles
some
newlines
does something really long and complicated so I have to write a very long name for the test\`, () => {
console.log("hello!");
}, 2500);
it("does something quick", () => {
console.log("hello!");
}, 1000000000);
`;
exports[`test_declarations.js - flow-verify 2`] = `
Expand Down Expand Up @@ -909,6 +935,19 @@ it.only.only("does something really long and complicated so I have to write a ve
});
xskip("does something really long and complicated so I have to write a very long name for the test", () => {});
// timeout
it(\`handles
some
newlines
does something really long and complicated so I have to write a very long name for the test\`, () => {
console.log("hello!");
}, 2500)
it("does something quick", () => {
console.log("hello!")
}, 1000000000)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Shouldn't break
Expand Down Expand Up @@ -1030,4 +1069,17 @@ xskip(
() => {}
);
// timeout
it(\`handles
some
newlines
does something really long and complicated so I have to write a very long name for the test\`, () => {
console.log("hello!");
}, 2500);
it("does something quick", () => {
console.log("hello!");
}, 1000000000);
`;
13 changes: 13 additions & 0 deletions tests/test_declarations/test_declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ it.only.only("does something really long and complicated so I have to write a ve
});

xskip("does something really long and complicated so I have to write a very long name for the test", () => {});

// timeout

it(`handles
some
newlines
does something really long and complicated so I have to write a very long name for the test`, () => {
console.log("hello!");
}, 2500)

it("does something quick", () => {
console.log("hello!")
}, 1000000000)

0 comments on commit 5972039

Please sign in to comment.