diff --git a/src/printer.js b/src/printer.js index 717886dd0..9be2f5353 100644 --- a/src/printer.js +++ b/src/printer.js @@ -845,6 +845,23 @@ function genericPrintNoParens(path, options, print, args) { case "CallExpression": { const isNew = n.type === "NewExpression"; const unitTestRe = /^(f|x)?(it|describe|test)$/; + const isTestDeclaration = + !isNew && + ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) || + (n.callee.type === "MemberExpression" && + n.callee.object.type === "Identifier" && + n.callee.property.type === "Identifier" && + unitTestRe.test(n.callee.object.name) && + (n.callee.property.name === "only" || + n.callee.property.name === "skip"))) && + n.arguments.length === 2 && + (n.arguments[0].type === "StringLiteral" || + n.arguments[0].type === "TemplateLiteral" || + (n.arguments[0].type === "Literal" && + typeof n.arguments[0].value === "string")) && + (n.arguments[1].type === "FunctionExpression" || + n.arguments[1].type === "ArrowFunctionExpression") && + n.arguments[1].params.length <= 1; const optional = printOptionalToken(path); if ( @@ -858,29 +875,18 @@ function genericPrintNoParens(path, options, print, args) { isTemplateOnItsOwnLine(n.arguments[0], options.originalText)) || // Keep test declarations on a single line // e.g. `it('long name', () => {` - (!isNew && - ((n.callee.type === "Identifier" && unitTestRe.test(n.callee.name)) || - (n.callee.type === "MemberExpression" && - n.callee.object.type === "Identifier" && - n.callee.property.type === "Identifier" && - unitTestRe.test(n.callee.object.name) && - (n.callee.property.name === "only" || - n.callee.property.name === "skip"))) && - n.arguments.length === 2 && - (n.arguments[0].type === "StringLiteral" || - n.arguments[0].type === "TemplateLiteral" || - (n.arguments[0].type === "Literal" && - typeof n.arguments[0].value === "string")) && - (n.arguments[1].type === "FunctionExpression" || - n.arguments[1].type === "ArrowFunctionExpression") && - n.arguments[1].params.length <= 1) + isTestDeclaration ) { + let printedArgs = path.map(print, "arguments"); + if (isTestDeclaration) { + printedArgs = printedArgs.map(docUtils.removeLines); + } return concat([ isNew ? "new " : "", path.call(print, "callee"), optional, path.call(print, "typeParameters"), - concat(["(", join(", ", path.map(print, "arguments")), ")"]) + concat(["(", join(", ", printedArgs), ")"]) ]); } diff --git a/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap index 46df9e4ee..6decf00dc 100644 --- a/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,17 @@ it("does something really long and complicated so I have to write a very long na console.log("hello!"); }); +it("does something really long and complicated so I have to write a very long name for the test", function(done) { + console.log("hello!"); +}); + +it(\`handles + some + newlines + does something really long and complicated so I have to write a very long name for the test\`, function(done) { + console.log("hello!"); +}); + it(\`does something really long and complicated so I have to write a very long name for the test\`, function() { console.log("hello!"); }); @@ -100,6 +111,17 @@ it("does something really long and complicated so I have to write a very long na console.log("hello!"); }); +it("does something really long and complicated so I have to write a very long name for the test", function(done) { + console.log("hello!"); +}); + +it(\`handles + some + newlines + does something really long and complicated so I have to write a very long name for the test\`, function(done) { + console.log("hello!"); +}); + it(\`does something really long and complicated so I have to write a very long name for the test\`, function() { console.log("hello!"); }); diff --git a/tests/test_declarations/test_declarations.js b/tests/test_declarations/test_declarations.js index 165f40453..385469c68 100644 --- a/tests/test_declarations/test_declarations.js +++ b/tests/test_declarations/test_declarations.js @@ -8,6 +8,17 @@ it("does something really long and complicated so I have to write a very long na console.log("hello!"); }); +it("does something really long and complicated so I have to write a very long name for the test", function(done) { + console.log("hello!"); +}); + +it(`handles + some + newlines + does something really long and complicated so I have to write a very long name for the test`, function(done) { + console.log("hello!"); +}); + it(`does something really long and complicated so I have to write a very long name for the test`, function() { console.log("hello!"); });