Skip to content

Commit

Permalink
eslint-module-utils: Add test for ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
sompylasar committed Jun 5, 2017
1 parent 3b4cb47 commit 2bc4f7f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
Empty file.
58 changes: 58 additions & 0 deletions tests/src/core/ignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { expect } from 'chai'

import isIgnored, { hasValidExtension } from 'eslint-module-utils/ignore'

import * as utils from '../utils'

describe('ignore', function () {
describe('isIgnored', function () {
it('ignores paths with extensions other than .js', function () {
const testContext = utils.testContext({})

expect(isIgnored('../files/foo.js', testContext)).to.equal(false)

expect(isIgnored('../files/bar.jsx', testContext)).to.equal(true)

expect(isIgnored('../files/typescript.ts', testContext)).to.equal(true)

expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})

it('ignores paths with invalid extensions when configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.js', '.jsx', '.ts' ] })

expect(isIgnored('../files/foo.js', testContext)).to.equal(false)

expect(isIgnored('../files/bar.jsx', testContext)).to.equal(false)

expect(isIgnored('../files/typescript.ts', testContext)).to.equal(false)

expect(isIgnored('../files/ignore.invalid.extension', testContext)).to.equal(true)
})
})

describe('hasValidExtension', function () {
it('assumes only .js as valid by default', function () {
const testContext = utils.testContext({})

expect(hasValidExtension('../files/foo.js', testContext)).to.equal(true)

expect(hasValidExtension('../files/foo.jsx', testContext)).to.equal(false)

expect(hasValidExtension('../files/foo.css', testContext)).to.equal(false)

expect(hasValidExtension('../files/foo.invalid.extension', testContext)).to.equal(false)
})

it('can be configured with import/extensions', function () {
const testContext = utils.testContext({ 'import/extensions': [ '.foo', '.bar' ] })

expect(hasValidExtension('../files/foo.foo', testContext)).to.equal(true)

expect(hasValidExtension('../files/foo.bar', testContext)).to.equal(true)

expect(hasValidExtension('../files/foo.js', testContext)).to.equal(false)
})
})

})
8 changes: 7 additions & 1 deletion tests/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ export const SYNTAX_CASES = [
test({
code: 'import * as a from "./commonjs-namespace/a"; a.b',
}),
]

// ignore invalid extensions
test({
code: 'import { foo } from "./ignore.invalid.extension"',
}),

]

0 comments on commit 2bc4f7f

Please sign in to comment.