diff --git a/src/printer.js b/src/printer.js index 1a74e1bf..d92c8f91 100644 --- a/src/printer.js +++ b/src/printer.js @@ -636,9 +636,12 @@ function genericPrintNoParens(path, options, print) { if ( // We want to keep require calls as a unit (n.callee.type === "Identifier" && n.callee.name === "require") || - // `it('long name', () => {` should not break + // Keep test declarations on a single line + // e.g. `it('long name', () => {` (n.callee.type === "Identifier" && - (n.callee.name === "it" || n.callee.name === "test") && + (n.callee.name === "it" || + n.callee.name === "test" || + n.callee.name === "describe") && n.arguments.length === 2 && (n.arguments[0].type === "StringLiteral" || n.arguments[0].type === "TemplateLiteral" || diff --git a/tests/it/__snapshots__/jsfmt.spec.js.snap b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap similarity index 81% rename from tests/it/__snapshots__/jsfmt.spec.js.snap rename to tests/test_declarations/__snapshots__/jsfmt.spec.js.snap index 8baf615e..e52cda38 100644 --- a/tests/it/__snapshots__/jsfmt.spec.js.snap +++ b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`it.js 1`] = ` +exports[`test_declarations.js 1`] = ` "// Shouldn't break it(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { @@ -34,6 +34,18 @@ test(\`does something really long and complicated so I have to write a very long console.log(\\"hello!\\"); }); +describe(\\"does something really long and complicated so I have to write a very long name for the describe block\\", () => { + it(\\"an example test\\", (done) => { + console.log(\\"hello!\\"); + }); +}); + +describe(\`does something really long and complicated so I have to write a very long name for the describe block\`, () => { + it(\`an example test\`, (done) => { + console.log(\\"hello!\\"); + }); +}); + // Should break it.only(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { @@ -89,6 +101,18 @@ test(\`does something really long and complicated so I have to write a very long console.log(\\"hello!\\"); }); +describe(\\"does something really long and complicated so I have to write a very long name for the describe block\\", () => { + it(\\"an example test\\", done => { + console.log(\\"hello!\\"); + }); +}); + +describe(\`does something really long and complicated so I have to write a very long name for the describe block\`, () => { + it(\`an example test\`, done => { + console.log(\\"hello!\\"); + }); +}); + // Should break it.only( @@ -129,7 +153,7 @@ it.only.only( " `; -exports[`it.js 2`] = ` +exports[`test_declarations.js 2`] = ` "// Shouldn't break it(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { @@ -163,6 +187,18 @@ test(\`does something really long and complicated so I have to write a very long console.log(\\"hello!\\"); }); +describe(\\"does something really long and complicated so I have to write a very long name for the describe block\\", () => { + it(\\"an example test\\", (done) => { + console.log(\\"hello!\\"); + }); +}); + +describe(\`does something really long and complicated so I have to write a very long name for the describe block\`, () => { + it(\`an example test\`, (done) => { + console.log(\\"hello!\\"); + }); +}); + // Should break it.only(\\"does something really long and complicated so I have to write a very long name for the test\\", () => { @@ -218,6 +254,18 @@ test(\`does something really long and complicated so I have to write a very long console.log(\\"hello!\\"); }); +describe(\\"does something really long and complicated so I have to write a very long name for the describe block\\", () => { + it(\\"an example test\\", done => { + console.log(\\"hello!\\"); + }); +}); + +describe(\`does something really long and complicated so I have to write a very long name for the describe block\`, () => { + it(\`an example test\`, done => { + console.log(\\"hello!\\"); + }); +}); + // Should break it.only( diff --git a/tests/it/jsfmt.spec.js b/tests/test_declarations/jsfmt.spec.js similarity index 100% rename from tests/it/jsfmt.spec.js rename to tests/test_declarations/jsfmt.spec.js diff --git a/tests/it/it.js b/tests/test_declarations/test_declarations.js similarity index 81% rename from tests/it/it.js rename to tests/test_declarations/test_declarations.js index b8421eb0..daf8b00c 100644 --- a/tests/it/it.js +++ b/tests/test_declarations/test_declarations.js @@ -31,6 +31,18 @@ test(`does something really long and complicated so I have to write a very long console.log("hello!"); }); +describe("does something really long and complicated so I have to write a very long name for the describe block", () => { + it("an example test", (done) => { + console.log("hello!"); + }); +}); + +describe(`does something really long and complicated so I have to write a very long name for the describe block`, () => { + it(`an example test`, (done) => { + console.log("hello!"); + }); +}); + // Should break it.only("does something really long and complicated so I have to write a very long name for the test", () => {