Do not break long `describe` calls (#953)

This ensures that `describe` calls in test suites are whitelisted in the same way as `it` and `test` and never break across lines.
master
Karl O'Keeffe 2017-03-08 21:24:28 +00:00 committed by Christopher Chedeau
parent 72456bf06f
commit 68a39454af
4 changed files with 67 additions and 4 deletions

View File

@ -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" ||

View File

@ -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(

View File

@ -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", () => {