Skip to content

Commit 3977c42

Browse files
committedAug 18, 2021
[Tests] clean up tests, ensure test() is used properly
1 parent 3ff4d77 commit 3977c42

File tree

5 files changed

+411
-460
lines changed

5 files changed

+411
-460
lines changed
 

‎tests/src/rules/first.js

+74-69
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,71 @@ const rule = require('rules/first');
77

88
ruleTester.run('first', rule, {
99
valid: [
10-
test({ code: "import { x } from './foo'; import { y } from './bar';\
11-
export { x, y }" }),
10+
test({
11+
code: "import { x } from './foo'; import { y } from './bar';\
12+
export { x, y }",
13+
}),
1214
test({ code: "import { x } from 'foo'; import { y } from './bar'" }),
1315
test({ code: "import { x } from './foo'; import { y } from 'bar'" }),
14-
test({ code: "import { x } from './foo'; import { y } from 'bar'",
16+
test({
17+
code: "import { x } from './foo'; import { y } from 'bar'",
1518
options: ['disable-absolute-first'],
1619
}),
17-
test({ code: "'use directive';\
18-
import { x } from 'foo';" }),
20+
test({
21+
code: "'use directive';\
22+
import { x } from 'foo';",
23+
}),
1924
],
2025
invalid: [
21-
test({ code: "import { x } from './foo';\
22-
export { x };\
23-
import { y } from './bar';",
24-
errors: 1,
25-
output: "import { x } from './foo';\
26-
import { y } from './bar';\
27-
export { x };",
26+
test({
27+
code: "import { x } from './foo';\
28+
export { x };\
29+
import { y } from './bar';",
30+
errors: 1,
31+
output: "import { x } from './foo';\
32+
import { y } from './bar';\
33+
export { x };",
2834
}),
29-
test({ code: "import { x } from './foo';\
30-
export { x };\
31-
import { y } from './bar';\
32-
import { z } from './baz';",
33-
errors: 2,
34-
output: "import { x } from './foo';\
35-
import { y } from './bar';\
36-
import { z } from './baz';\
37-
export { x };",
35+
test({
36+
code: "import { x } from './foo';\
37+
export { x };\
38+
import { y } from './bar';\
39+
import { z } from './baz';",
40+
errors: 2,
41+
output: "import { x } from './foo';\
42+
import { y } from './bar';\
43+
import { z } from './baz';\
44+
export { x };",
3845
}),
39-
test({ code: "import { x } from './foo'; import { y } from 'bar'",
46+
test({
47+
code: "import { x } from './foo'; import { y } from 'bar'",
4048
options: ['absolute-first'],
4149
errors: 1,
4250
}),
43-
test({ code: "import { x } from 'foo';\
44-
'use directive';\
45-
import { y } from 'bar';",
46-
errors: 1,
47-
output: "import { x } from 'foo';\
48-
import { y } from 'bar';\
49-
'use directive';",
51+
test({
52+
code: "import { x } from 'foo';\
53+
'use directive';\
54+
import { y } from 'bar';",
55+
errors: 1,
56+
output: "import { x } from 'foo';\
57+
import { y } from 'bar';\
58+
'use directive';",
5059
}),
51-
test({ code: "var a = 1;\
52-
import { y } from './bar';\
53-
if (true) { x() };\
54-
import { x } from './foo';\
55-
import { z } from './baz';",
56-
errors: 3,
57-
output: "import { y } from './bar';\
58-
var a = 1;\
59-
if (true) { x() };\
60-
import { x } from './foo';\
61-
import { z } from './baz';",
60+
test({
61+
code: "var a = 1;\
62+
import { y } from './bar';\
63+
if (true) { x() };\
64+
import { x } from './foo';\
65+
import { z } from './baz';",
66+
errors: 3,
67+
output: "import { y } from './bar';\
68+
var a = 1;\
69+
if (true) { x() };\
70+
import { x } from './foo';\
71+
import { z } from './baz';",
6272
}),
63-
test({ code: "if (true) { console.log(1) }import a from 'b'",
73+
test({
74+
code: "if (true) { console.log(1) }import a from 'b'",
6475
errors: 1,
6576
output: "import a from 'b'\nif (true) { console.log(1) }",
6677
}),
@@ -72,7 +83,7 @@ context('TypeScript', function () {
7283
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
7384
.forEach((parser) => {
7485
const parserConfig = {
75-
parser: parser,
86+
parser,
7687
settings: {
7788
'import/parsers': { [parser]: ['.ts'] },
7889
'import/resolver': { 'eslint-import-resolver-typescript': true },
@@ -81,35 +92,29 @@ context('TypeScript', function () {
8192

8293
ruleTester.run('order', rule, {
8394
valid: [
84-
test(
85-
{
86-
code: `
87-
import y = require('bar');
88-
import { x } from 'foo';
89-
import z = require('baz');
90-
`,
91-
parser,
92-
},
93-
parserConfig,
94-
),
95+
test({
96+
code: `
97+
import y = require('bar');
98+
import { x } from 'foo';
99+
import z = require('baz');
100+
`,
101+
...parserConfig,
102+
}),
95103
],
96104
invalid: [
97-
test(
98-
{
99-
code: `
100-
import { x } from './foo';
101-
import y = require('bar');
102-
`,
103-
options: ['absolute-first'],
104-
parser,
105-
errors: [
106-
{
107-
message: 'Absolute imports should come before relative imports.',
108-
},
109-
],
110-
},
111-
parserConfig,
112-
),
105+
test({
106+
code: `
107+
import { x } from './foo';
108+
import y = require('bar');
109+
`,
110+
options: ['absolute-first'],
111+
...parserConfig,
112+
errors: [
113+
{
114+
message: 'Absolute imports should come before relative imports.',
115+
},
116+
],
117+
}),
113118
],
114119
});
115120
});

‎tests/src/rules/no-duplicates.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ context('TypeScript', function() {
420420
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
421421
.forEach((parser) => {
422422
const parserConfig = {
423-
parser: parser,
423+
parser,
424424
settings: {
425425
'import/parsers': { [parser]: ['.ts'] },
426426
'import/resolver': { 'eslint-import-resolver-typescript': true },
@@ -430,13 +430,10 @@ context('TypeScript', function() {
430430
ruleTester.run('no-duplicates', rule, {
431431
valid: [
432432
// #1667: ignore duplicate if is a typescript type import
433-
test(
434-
{
435-
code: "import type { x } from './foo'; import y from './foo'",
436-
parser,
437-
},
438-
parserConfig,
439-
),
433+
test({
434+
code: "import type { x } from './foo'; import y from './foo'",
435+
...parserConfig,
436+
}),
440437
],
441438
invalid: [],
442439
});

‎tests/src/rules/order.js

+300-336
Large diffs are not rendered by default.

‎tests/src/rules/prefer-default-export.js

+29-47
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ ruleTester.run('prefer-default-export', rule, {
151151
context('TypeScript', function() {
152152
getNonDefaultParsers().forEach((parser) => {
153153
const parserConfig = {
154-
parser: parser,
154+
parser,
155155
settings: {
156156
'import/parsers': { [parser]: ['.ts'] },
157157
'import/resolver': { 'eslint-import-resolver-typescript': true },
@@ -161,52 +161,34 @@ context('TypeScript', function() {
161161
ruleTester.run('prefer-default-export', rule, {
162162
valid: [
163163
// Exporting types
164-
test(
165-
{
166-
code: `
167-
export type foo = string;
168-
export type bar = number;`,
169-
parser,
170-
},
171-
parserConfig,
172-
),
173-
test(
174-
{
175-
code: `
176-
export type foo = string;
177-
export type bar = number;`,
178-
parser,
179-
},
180-
parserConfig,
181-
),
182-
test(
183-
{
184-
code: 'export type foo = string',
185-
parser,
186-
},
187-
parserConfig,
188-
),
189-
test(
190-
{
191-
code: 'export type foo = string',
192-
parser,
193-
},
194-
parserConfig,
195-
),
196-
test(
197-
{
198-
code: 'export interface foo { bar: string; }',
199-
parser,
200-
},
201-
parserConfig,
202-
),
203-
test(
204-
{
205-
code: 'export interface foo { bar: string; }; export function goo() {}',
206-
parser,
207-
},
208-
parserConfig,
209-
),
164+
test({
165+
code: `
166+
export type foo = string;
167+
export type bar = number;`,
168+
...parserConfig,
169+
}),
170+
test({
171+
code: `
172+
export type foo = string;
173+
export type bar = number;`,
174+
...parserConfig,
175+
}),
176+
test({
177+
code: 'export type foo = string',
178+
...parserConfig,
179+
}),
180+
test({
181+
code: 'export type foo = string',
182+
...parserConfig,
183+
}),
184+
test({
185+
code: 'export interface foo { bar: string; }',
186+
...parserConfig,
187+
}),
188+
test({
189+
code: 'export interface foo { bar: string; }; export function goo() {}',
190+
...parserConfig,
191+
}),
210192
],
211193
invalid: [],
212194
});

‎tests/src/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export function testVersion(specifier, t) {
3232
}
3333

3434
export function test(t) {
35+
if (arguments.length !== 1) {
36+
throw new SyntaxError('`test` requires exactly one object argument');
37+
}
3538
return Object.assign({
3639
filename: FILENAME,
3740
}, t, {

0 commit comments

Comments
 (0)
Please sign in to comment.