Skip to content

Commit d407f36

Browse files
author
Rebecca Stevens
committed
test(no-restricted-paths): add tests for allowedImportKinds
re #1899
1 parent fef718c commit d407f36

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/src/rules/no-restricted-paths.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ ruleTester.run('no-restricted-paths', rule, {
6767

6868
// builtin (ignore)
6969
test({ code: 'require("os")' }),
70+
71+
// type imports
72+
test({
73+
code: 'import type a from "../client/a.js"',
74+
parser: require.resolve('babel-eslint'),
75+
filename: testFilePath('./restricted-paths/server/b.js'),
76+
options: [ {
77+
allowedImportKinds: ['type'],
78+
zones: [ { target: './tests/files/restricted-paths/server', from: './tests/files/restricted-paths/client' } ],
79+
} ],
80+
}),
7081
],
7182

7283
invalid: [
@@ -179,5 +190,62 @@ ruleTester.run('no-restricted-paths', rule, {
179190
column: 15,
180191
} ],
181192
}),
193+
194+
// type imports
195+
test({
196+
code: 'import type T from "../server/b.js";',
197+
parser: require.resolve('babel-eslint'),
198+
filename: testFilePath('./restricted-paths/client/a.js'),
199+
options: [ {
200+
zones: [ { target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/server' } ],
201+
} ],
202+
errors: [ {
203+
message: 'Unexpected path "../server/b.js" imported in restricted zone.',
204+
line: 1,
205+
column: 20,
206+
} ],
207+
}),
208+
test({
209+
code: `
210+
import type { T } from "../server/b.js";
211+
import b from "../server/b.js";
212+
`,
213+
parser: require.resolve('babel-eslint'),
214+
filename: testFilePath('./restricted-paths/client/a.js'),
215+
options: [ {
216+
allowedImportKinds: ['type'],
217+
zones: [ { target: './tests/files/restricted-paths/client', from: './tests/files/restricted-paths/server' } ],
218+
} ],
219+
errors: [ {
220+
message: 'Unexpected path "../server/b.js" imported in restricted zone.',
221+
line: 3,
222+
column: 23,
223+
} ],
224+
}),
225+
test({
226+
code: `
227+
import type { T } from "../server/b.js";
228+
import b from "../server/b.js";
229+
`,
230+
parser: require.resolve('babel-eslint'),
231+
filename: testFilePath('./restricted-paths/client/a.js'),
232+
options: [ {
233+
allowedImportKinds: ['type'],
234+
zones: [ {
235+
target: './tests/files/restricted-paths/client',
236+
from: './tests/files/restricted-paths/server',
237+
allowedImportKinds: [],
238+
} ],
239+
} ],
240+
errors: [ {
241+
message: 'Unexpected path "../server/b.js" imported in restricted zone.',
242+
line: 2,
243+
column: 32,
244+
}, {
245+
message: 'Unexpected path "../server/b.js" imported in restricted zone.',
246+
line: 3,
247+
column: 23,
248+
} ],
249+
}),
182250
],
183251
})

0 commit comments

Comments
 (0)