Skip to content

Commit 3977c42

Browse files
committed
[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

Lines changed: 74 additions & 69 deletions
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

Lines changed: 5 additions & 8 deletions
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
});

0 commit comments

Comments
 (0)