Skip to content

Commit 6ef16a1

Browse files
authored
chore: use dedent for most tests (#735)
1 parent 5b8fbff commit 6ef16a1

9 files changed

+628
-615
lines changed

src/rules/__tests__/no-commented-out-tests.test.ts

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TSESLint } from '@typescript-eslint/experimental-utils';
2+
import dedent from 'dedent';
23
import resolveFrom from 'resolve-from';
34
import rule from '../no-commented-out-tests';
45

@@ -30,35 +31,35 @@ ruleTester.run('no-commented-out-tests', rule, {
3031
'// latest(dates)',
3132
'// TODO: unify with Git implementation from Shipit (?)',
3233
'#!/usr/bin/env node',
33-
[
34-
'import { pending } from "actions"',
35-
'',
36-
'test("foo", () => {',
37-
' expect(pending()).toEqual({})',
38-
'})',
39-
].join('\n'),
40-
[
41-
'const { pending } = require("actions")',
42-
'',
43-
'test("foo", () => {',
44-
' expect(pending()).toEqual({})',
45-
'})',
46-
].join('\n'),
47-
[
48-
'test("foo", () => {',
49-
' const pending = getPending()',
50-
' expect(pending()).toEqual({})',
51-
'})',
52-
].join('\n'),
53-
[
54-
'test("foo", () => {',
55-
' expect(pending()).toEqual({})',
56-
'})',
57-
'',
58-
'function pending() {',
59-
' return {}',
60-
'}',
61-
].join('\n'),
34+
dedent`
35+
import { pending } from "actions"
36+
37+
test("foo", () => {
38+
expect(pending()).toEqual({})
39+
})
40+
`,
41+
dedent`
42+
const { pending } = require("actions")
43+
44+
test("foo", () => {
45+
expect(pending()).toEqual({})
46+
})
47+
`,
48+
dedent`
49+
test("foo", () => {
50+
const pending = getPending()
51+
expect(pending()).toEqual({})
52+
})
53+
`,
54+
dedent`
55+
test("foo", () => {
56+
expect(pending()).toEqual({})
57+
})
58+
59+
function pending() {
60+
return {}
61+
}
62+
`,
6263
],
6364

6465
invalid: [
@@ -119,17 +120,21 @@ ruleTester.run('no-commented-out-tests', rule, {
119120
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
120121
},
121122
{
122-
code: `// test(
123-
// "foo", function () {}
124-
// )`,
123+
code: dedent`
124+
// test(
125+
// "foo", function () {}
126+
// )
127+
`,
125128
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
126129
},
127130
{
128-
code: `/* test
129-
(
130-
"foo", function () {}
131-
)
132-
*/`,
131+
code: dedent`
132+
/* test
133+
(
134+
"foo", function () {}
135+
)
136+
*/
137+
`,
133138
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
134139
},
135140
{
@@ -153,13 +158,14 @@ ruleTester.run('no-commented-out-tests', rule, {
153158
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
154159
},
155160
{
156-
code: `
157-
foo()
158-
/*
159-
describe("has title but no callback", () => {})
160-
*/
161-
bar()`,
162-
errors: [{ messageId: 'commentedTests', column: 7, line: 3 }],
161+
code: dedent`
162+
foo()
163+
/*
164+
describe("has title but no callback", () => {})
165+
*/
166+
bar()
167+
`,
168+
errors: [{ messageId: 'commentedTests', column: 1, line: 2 }],
163169
},
164170
],
165171
});

src/rules/__tests__/no-disabled-tests.test.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TSESLint } from '@typescript-eslint/experimental-utils';
2+
import dedent from 'dedent';
23
import resolveFrom from 'resolve-from';
34
import rule from '../no-disabled-tests';
45

@@ -28,35 +29,35 @@ ruleTester.run('no-disabled-tests', rule, {
2829
'(a || b).f()',
2930
'itHappensToStartWithIt()',
3031
'testSomething()',
31-
[
32-
'import { pending } from "actions"',
33-
'',
34-
'test("foo", () => {',
35-
' expect(pending()).toEqual({})',
36-
'})',
37-
].join('\n'),
38-
[
39-
'const { pending } = require("actions")',
40-
'',
41-
'test("foo", () => {',
42-
' expect(pending()).toEqual({})',
43-
'})',
44-
].join('\n'),
45-
[
46-
'test("foo", () => {',
47-
' const pending = getPending()',
48-
' expect(pending()).toEqual({})',
49-
'})',
50-
].join('\n'),
51-
[
52-
'test("foo", () => {',
53-
' expect(pending()).toEqual({})',
54-
'})',
55-
'',
56-
'function pending() {',
57-
' return {}',
58-
'}',
59-
].join('\n'),
32+
dedent`
33+
import { pending } from "actions"
34+
35+
test("foo", () => {
36+
expect(pending()).toEqual({})
37+
})
38+
`,
39+
dedent`
40+
const { pending } = require("actions")
41+
42+
test("foo", () => {
43+
expect(pending()).toEqual({})
44+
})
45+
`,
46+
dedent`
47+
test("foo", () => {
48+
const pending = getPending()
49+
expect(pending()).toEqual({})
50+
})
51+
`,
52+
dedent`
53+
test("foo", () => {
54+
expect(pending()).toEqual({})
55+
})
56+
57+
function pending() {
58+
return {}
59+
}
60+
`,
6061
],
6162

6263
invalid: [

0 commit comments

Comments
 (0)