Skip to content

Commit

Permalink
update named tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vikr01 committed Nov 2, 2018
1 parent 81dade6 commit 0fc26db
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/files/module-exports-direct.js
@@ -0,0 +1,5 @@
exports = {
a: 0,
1: 1,
'c': 2,
}
1 change: 1 addition & 0 deletions tests/files/module-exports-number.js
@@ -0,0 +1 @@
module.exports = 5
15 changes: 15 additions & 0 deletions tests/files/named-exports-es5.js
@@ -0,0 +1,15 @@
Object.defineProperty(exports, '__esModule', {value: true})

exports.destructuredProp = {}

module.exports.arrayKeyProp = null

exports.deepSparseElement = []

exports.a = 1
exports.b = 2

const c = 3
module.exports.d = c

exports.ExportedClass = class {}
8 changes: 8 additions & 0 deletions tests/files/re-export-names-es5.js
@@ -0,0 +1,8 @@
const namedExports = require('./named-exports-es5')

module.exports = {
__esModule: true,
foo: namedExports.a,
bar: namedExports.b,
baz: 'will it blend?',
}
61 changes: 60 additions & 1 deletion tests/src/rules/named.js
Expand Up @@ -33,6 +33,14 @@ ruleTester.run('named', rule, {
'// eslint-disable-line named' }),

test({ code: 'import { foo, bar } from "./re-export-names"' }),
test({
code: 'import { foo, bar } from "./re-export-names-es5"',
options: [{ commonjs: { exports: true }}],
}),
test({
code: 'import { foo, bar } from "./re-export-names-es5"',
options: [{ commonjs: true }],
}),

test({ code: 'import { foo, bar } from "./common"'
, settings: { 'import/ignore': ['common'] } }),
Expand Down Expand Up @@ -65,6 +73,11 @@ ruleTester.run('named', rule, {
test({ code: 'import { destructuredProp } from "./named-exports"' }),
test({ code: 'import { arrayKeyProp } from "./named-exports"' }),
test({ code: 'import { deepProp } from "./named-exports"' }),
test({ code: 'import { deepProp, deepSparseElement } from "./named-exports-es5"' }),
test({
code: 'import { deepProp, deepSparseElement } from "./named-exports-es5"',
options: [{ commonjs: { exports: true } }],
}),
test({ code: 'import { deepSparseElement } from "./named-exports"' }),

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

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

// direct module exports cases
test({
code: 'import { a, c } from "./module-exports-direct"',
options: [{ commonjs: true }],
}),

test({
code: 'import { default as n } from "./module-exports-number"',
options: [{ commonjs: true }],
}),

...SYNTAX_CASES,
],

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

test({
code: 'import { a } from "./re-export-names"',
options: [2, 'es6-only'],
options: [{ commonjs: true }],
errors: [error('a', './re-export-names')],
}),

test({
code: 'import { a } from "./re-export-names-es5"',
options: [{ commonjs: true }],
errors: [error('a', './re-export-names-es5')],
}),

// export tests
test({
code: 'export { bar } from "./bar"',
Expand Down Expand Up @@ -282,11 +316,23 @@ ruleTester.run('named', rule, {
settings: { 'import/ignore': [] },
errors: ["createSnorlax not found in 'redux'"],
}),
test({
code: 'import { createSnorlax } from "redux/lib/index"',
settings: { 'import/ignore': [] },
options: [{ commonjs: true }],
errors: ["createSnorlax not found in 'redux/lib/index'"],
}),
// should work without ignore
test({
code: '/*jsnext*/ import { createSnorlax } from "redux"',
errors: ["createSnorlax not found in 'redux'"],
}),
test({
code: 'import { createSnorlax } from "redux/lib/index"',
options: [{ commonjs: { exports: true } }],
errors: ["createSnorlax not found in 'redux/lib/index'"],
}),


// ignore is ignored if exports are found
test({
Expand All @@ -306,6 +352,19 @@ ruleTester.run('named', rule, {
code: 'import { default as barDefault } from "./re-export"',
errors: [`default not found in './re-export'`],
}),

// direct module.exports assignment
test({
code: 'import { b } from "./module-exports-direct"',
options: [{ commonjs: true }],
errors: [ error('b', './module-exports-direct') ],
}),

test({
code: 'import { noExports } from "./module-exports-number"',
options: [{ commonjs: true }],
errors: [ error('noExports', './module-exports-number') ],
}),
],
})

Expand Down

0 comments on commit 0fc26db

Please sign in to comment.