Skip to content

Commit 0fc26db

Browse files
committed
update named tests
1 parent 81dade6 commit 0fc26db

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

tests/files/module-exports-direct.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exports = {
2+
a: 0,
3+
1: 1,
4+
'c': 2,
5+
}

tests/files/module-exports-number.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 5

tests/files/named-exports-es5.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Object.defineProperty(exports, '__esModule', {value: true})
2+
3+
exports.destructuredProp = {}
4+
5+
module.exports.arrayKeyProp = null
6+
7+
exports.deepSparseElement = []
8+
9+
exports.a = 1
10+
exports.b = 2
11+
12+
const c = 3
13+
module.exports.d = c
14+
15+
exports.ExportedClass = class {}

tests/files/re-export-names-es5.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const namedExports = require('./named-exports-es5')
2+
3+
module.exports = {
4+
__esModule: true,
5+
foo: namedExports.a,
6+
bar: namedExports.b,
7+
baz: 'will it blend?',
8+
}

tests/src/rules/named.js

+60-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ ruleTester.run('named', rule, {
3333
'// eslint-disable-line named' }),
3434

3535
test({ code: 'import { foo, bar } from "./re-export-names"' }),
36+
test({
37+
code: 'import { foo, bar } from "./re-export-names-es5"',
38+
options: [{ commonjs: { exports: true }}],
39+
}),
40+
test({
41+
code: 'import { foo, bar } from "./re-export-names-es5"',
42+
options: [{ commonjs: true }],
43+
}),
3644

3745
test({ code: 'import { foo, bar } from "./common"'
3846
, settings: { 'import/ignore': ['common'] } }),
@@ -65,6 +73,11 @@ ruleTester.run('named', rule, {
6573
test({ code: 'import { destructuredProp } from "./named-exports"' }),
6674
test({ code: 'import { arrayKeyProp } from "./named-exports"' }),
6775
test({ code: 'import { deepProp } from "./named-exports"' }),
76+
test({ code: 'import { deepProp, deepSparseElement } from "./named-exports-es5"' }),
77+
test({
78+
code: 'import { deepProp, deepSparseElement } from "./named-exports-es5"',
79+
options: [{ commonjs: { exports: true } }],
80+
}),
6881
test({ code: 'import { deepSparseElement } from "./named-exports"' }),
6982

7083
// should ignore imported flow types, even if they don’t exist
@@ -154,6 +167,10 @@ ruleTester.run('named', rule, {
154167
test({
155168
code: '/*jsnext*/ import { createStore } from "redux"',
156169
}),
170+
test({
171+
code: 'import { createStore } from "redux/lib/index"',
172+
options: [{ commonjs: true }],
173+
}),
157174

158175
// ignore is ignored if exports are found
159176
test({ code: 'import { foo } from "es6-module"' }),
@@ -178,6 +195,17 @@ ruleTester.run('named', rule, {
178195
code: 'import { common } from "./re-export-default"',
179196
}),
180197

198+
// direct module exports cases
199+
test({
200+
code: 'import { a, c } from "./module-exports-direct"',
201+
options: [{ commonjs: true }],
202+
}),
203+
204+
test({
205+
code: 'import { default as n } from "./module-exports-number"',
206+
options: [{ commonjs: true }],
207+
}),
208+
181209
...SYNTAX_CASES,
182210
],
183211

@@ -207,10 +235,16 @@ ruleTester.run('named', rule, {
207235

208236
test({
209237
code: 'import { a } from "./re-export-names"',
210-
options: [2, 'es6-only'],
238+
options: [{ commonjs: true }],
211239
errors: [error('a', './re-export-names')],
212240
}),
213241

242+
test({
243+
code: 'import { a } from "./re-export-names-es5"',
244+
options: [{ commonjs: true }],
245+
errors: [error('a', './re-export-names-es5')],
246+
}),
247+
214248
// export tests
215249
test({
216250
code: 'export { bar } from "./bar"',
@@ -282,11 +316,23 @@ ruleTester.run('named', rule, {
282316
settings: { 'import/ignore': [] },
283317
errors: ["createSnorlax not found in 'redux'"],
284318
}),
319+
test({
320+
code: 'import { createSnorlax } from "redux/lib/index"',
321+
settings: { 'import/ignore': [] },
322+
options: [{ commonjs: true }],
323+
errors: ["createSnorlax not found in 'redux/lib/index'"],
324+
}),
285325
// should work without ignore
286326
test({
287327
code: '/*jsnext*/ import { createSnorlax } from "redux"',
288328
errors: ["createSnorlax not found in 'redux'"],
289329
}),
330+
test({
331+
code: 'import { createSnorlax } from "redux/lib/index"',
332+
options: [{ commonjs: { exports: true } }],
333+
errors: ["createSnorlax not found in 'redux/lib/index'"],
334+
}),
335+
290336

291337
// ignore is ignored if exports are found
292338
test({
@@ -306,6 +352,19 @@ ruleTester.run('named', rule, {
306352
code: 'import { default as barDefault } from "./re-export"',
307353
errors: [`default not found in './re-export'`],
308354
}),
355+
356+
// direct module.exports assignment
357+
test({
358+
code: 'import { b } from "./module-exports-direct"',
359+
options: [{ commonjs: true }],
360+
errors: [ error('b', './module-exports-direct') ],
361+
}),
362+
363+
test({
364+
code: 'import { noExports } from "./module-exports-number"',
365+
options: [{ commonjs: true }],
366+
errors: [ error('noExports', './module-exports-number') ],
367+
}),
309368
],
310369
})
311370

0 commit comments

Comments
 (0)