1
1
import { test as _test , testFilePath } from '../utils' ;
2
2
3
3
import { RuleTester } from 'eslint' ;
4
+ import flatMap from 'array.prototype.flatmap' ;
4
5
5
6
const ruleTester = new RuleTester ( ) ;
6
7
const rule = require ( 'rules/no-cycle' ) ;
@@ -11,9 +12,10 @@ const test = def => _test(Object.assign(def, {
11
12
filename : testFilePath ( './cycles/depth-zero.js' ) ,
12
13
} ) ) ;
13
14
14
- // describe.only("no-cycle", () => {
15
+ const testDialects = [ 'es6' ] ;
16
+
15
17
ruleTester . run ( 'no-cycle' , rule , {
16
- valid : [
18
+ valid : [ ] . concat (
17
19
// this rule doesn't care if the cycle length is 0
18
20
test ( { code : 'import foo from "./foo.js"' } ) ,
19
21
@@ -32,14 +34,6 @@ ruleTester.run('no-cycle', rule, {
32
34
code : 'var bar = require("./bar")' ,
33
35
filename : '<text>' ,
34
36
} ) ,
35
- test ( {
36
- code : 'import { foo } from "./depth-two"' ,
37
- options : [ { maxDepth : 1 } ] ,
38
- } ) ,
39
- test ( {
40
- code : 'import { foo, bar } from "./depth-two"' ,
41
- options : [ { maxDepth : 1 } ] ,
42
- } ) ,
43
37
test ( {
44
38
code : 'import { foo } from "cycles/external/depth-one"' ,
45
39
options : [ { ignoreExternal : true } ] ,
@@ -56,19 +50,31 @@ ruleTester.run('no-cycle', rule, {
56
50
'import/external-module-folders' : [ 'cycles/external' ] ,
57
51
} ,
58
52
} ) ,
59
- test ( {
60
- code : 'import("./depth-two").then(function({ foo }){})' ,
61
- options : [ { maxDepth : 1 } ] ,
62
- parser : require . resolve ( 'babel-eslint' ) ,
63
- } ) ,
64
- test ( {
65
- code : 'import type { FooType } from "./depth-one"' ,
66
- parser : require . resolve ( 'babel-eslint' ) ,
67
- } ) ,
68
- test ( {
69
- code : 'import type { FooType, BarType } from "./depth-one"' ,
70
- parser : require . resolve ( 'babel-eslint' ) ,
71
- } ) ,
53
+
54
+ flatMap ( testDialects , ( testDialect ) => [
55
+ test ( {
56
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
57
+ options : [ { maxDepth : 1 } ] ,
58
+ } ) ,
59
+ test ( {
60
+ code : `import { foo, bar } from "./${ testDialect } /depth-two"` ,
61
+ options : [ { maxDepth : 1 } ] ,
62
+ } ) ,
63
+ test ( {
64
+ code : `import("./${ testDialect } /depth-two").then(function({ foo }){})` ,
65
+ options : [ { maxDepth : 1 } ] ,
66
+ parser : require . resolve ( 'babel-eslint' ) ,
67
+ } ) ,
68
+ test ( {
69
+ code : `import type { FooType } from "./${ testDialect } /depth-one"` ,
70
+ parser : require . resolve ( 'babel-eslint' ) ,
71
+ } ) ,
72
+ test ( {
73
+ code : `import type { FooType, BarType } from "./${ testDialect } /depth-one"` ,
74
+ parser : require . resolve ( 'babel-eslint' ) ,
75
+ } ) ,
76
+ ] ) ,
77
+
72
78
test ( {
73
79
code : 'import { bar } from "./flow-types"' ,
74
80
parser : require . resolve ( 'babel-eslint' ) ,
@@ -81,12 +87,9 @@ ruleTester.run('no-cycle', rule, {
81
87
code : 'import { bar } from "./flow-types-only-importing-multiple-types"' ,
82
88
parser : require . resolve ( 'babel-eslint' ) ,
83
89
} ) ,
84
- ] ,
85
- invalid : [
86
- test ( {
87
- code : 'import { foo } from "./depth-one"' ,
88
- errors : [ error ( `Dependency cycle detected.` ) ] ,
89
- } ) ,
90
+ ) ,
91
+
92
+ invalid : [ ] . concat (
90
93
test ( {
91
94
code : 'import { bar } from "./flow-types-some-type-imports"' ,
92
95
parser : require . resolve ( 'babel-eslint' ) ,
@@ -108,82 +111,89 @@ ruleTester.run('no-cycle', rule, {
108
111
'import/external-module-folders' : [ 'cycles/external' ] ,
109
112
} ,
110
113
} ) ,
111
- test ( {
112
- code : 'import { foo } from "./depth-one"' ,
113
- options : [ { maxDepth : 1 } ] ,
114
- errors : [ error ( `Dependency cycle detected.` ) ] ,
115
- } ) ,
116
- test ( {
117
- code : 'const { foo } = require("./depth-one")' ,
118
- errors : [ error ( `Dependency cycle detected.` ) ] ,
119
- options : [ { commonjs : true } ] ,
120
- } ) ,
121
- test ( {
122
- code : 'require(["./depth-one"], d1 => {})' ,
123
- errors : [ error ( `Dependency cycle detected.` ) ] ,
124
- options : [ { amd : true } ] ,
125
- } ) ,
126
- test ( {
127
- code : 'define(["./depth-one"], d1 => {})' ,
128
- errors : [ error ( `Dependency cycle detected.` ) ] ,
129
- options : [ { amd : true } ] ,
130
- } ) ,
131
- test ( {
132
- code : 'import { foo } from "./depth-two"' ,
133
- errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
134
- } ) ,
135
- test ( {
136
- code : 'import { foo } from "./depth-two"' ,
137
- options : [ { maxDepth : 2 } ] ,
138
- errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
139
- } ) ,
140
- test ( {
141
- code : 'const { foo } = require("./depth-two")' ,
142
- errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
143
- options : [ { commonjs : true } ] ,
144
- } ) ,
145
- test ( {
146
- code : 'import { two } from "./depth-three-star"' ,
147
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
148
- } ) ,
149
- test ( {
150
- code : 'import one, { two, three } from "./depth-three-star"' ,
151
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
152
- } ) ,
153
- test ( {
154
- code : 'import { bar } from "./depth-three-indirect"' ,
155
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
156
- } ) ,
157
- test ( {
158
- code : 'import { bar } from "./depth-three-indirect"' ,
159
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
160
- parser : require . resolve ( 'babel-eslint' ) ,
161
- } ) ,
162
- test ( {
163
- code : 'import("./depth-three-star")' ,
164
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
165
- parser : require . resolve ( 'babel-eslint' ) ,
166
- } ) ,
167
- test ( {
168
- code : 'import("./depth-three-indirect")' ,
169
- errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
170
- parser : require . resolve ( 'babel-eslint' ) ,
171
- } ) ,
114
+
115
+ flatMap ( testDialects , ( testDialect ) => [
116
+ test ( {
117
+ code : `import { foo } from "./${ testDialect } /depth-one"` ,
118
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
119
+ } ) ,
120
+ test ( {
121
+ code : `import { foo } from "./${ testDialect } /depth-one"` ,
122
+ options : [ { maxDepth : 1 } ] ,
123
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
124
+ } ) ,
125
+ test ( {
126
+ code : `const { foo } = require("./${ testDialect } /depth-one")` ,
127
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
128
+ options : [ { commonjs : true } ] ,
129
+ } ) ,
130
+ test ( {
131
+ code : `require(["./${ testDialect } /depth-one"], d1 => {})` ,
132
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
133
+ options : [ { amd : true } ] ,
134
+ } ) ,
135
+ test ( {
136
+ code : `define(["./${ testDialect } /depth-one"], d1 => {})` ,
137
+ errors : [ error ( `Dependency cycle detected.` ) ] ,
138
+ options : [ { amd : true } ] ,
139
+ } ) ,
140
+ test ( {
141
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
142
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
143
+ } ) ,
144
+ test ( {
145
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
146
+ options : [ { maxDepth : 2 } ] ,
147
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
148
+ } ) ,
149
+ test ( {
150
+ code : `const { foo } = require("./${ testDialect } /depth-two")` ,
151
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
152
+ options : [ { commonjs : true } ] ,
153
+ } ) ,
154
+ test ( {
155
+ code : `import { two } from "./${ testDialect } /depth-three-star"` ,
156
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
157
+ } ) ,
158
+ test ( {
159
+ code : `import one, { two, three } from "./${ testDialect } /depth-three-star"` ,
160
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
161
+ } ) ,
162
+ test ( {
163
+ code : `import { bar } from "./${ testDialect } /depth-three-indirect"` ,
164
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
165
+ } ) ,
166
+ test ( {
167
+ code : `import { bar } from "./${ testDialect } /depth-three-indirect"` ,
168
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
169
+ parser : require . resolve ( 'babel-eslint' ) ,
170
+ } ) ,
171
+ test ( {
172
+ code : `import("./${ testDialect } /depth-three-star")` ,
173
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
174
+ parser : require . resolve ( 'babel-eslint' ) ,
175
+ } ) ,
176
+ test ( {
177
+ code : `import("./${ testDialect } /depth-three-indirect")` ,
178
+ errors : [ error ( `Dependency cycle via ./depth-two:1=>./depth-one:1` ) ] ,
179
+ parser : require . resolve ( 'babel-eslint' ) ,
180
+ } ) ,
181
+ test ( {
182
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
183
+ options : [ { maxDepth : Infinity } ] ,
184
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
185
+ } ) ,
186
+ test ( {
187
+ code : `import { foo } from "./${ testDialect } /depth-two"` ,
188
+ options : [ { maxDepth : '∞' } ] ,
189
+ errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
190
+ } ) ,
191
+ ] ) ,
192
+
172
193
test ( {
173
194
code : 'import { bar } from "./flow-types-depth-one"' ,
174
195
parser : require . resolve ( 'babel-eslint' ) ,
175
- errors : [ error ( `Dependency cycle via ./flow-types-depth-two:4=>./depth-one:1` ) ] ,
176
- } ) ,
177
- test ( {
178
- code : 'import { foo } from "./depth-two"' ,
179
- options : [ { maxDepth : Infinity } ] ,
180
- errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
181
- } ) ,
182
- test ( {
183
- code : 'import { foo } from "./depth-two"' ,
184
- options : [ { maxDepth : '∞' } ] ,
185
- errors : [ error ( `Dependency cycle via ./depth-one:1` ) ] ,
196
+ errors : [ error ( `Dependency cycle via ./flow-types-depth-two:4=>./es6/depth-one:1` ) ] ,
186
197
} ) ,
187
- ] ,
198
+ ) ,
188
199
} ) ;
189
- // })
0 commit comments