Skip to content

Commit

Permalink
eslint-module-utils: Add test for import/resolver config checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sompylasar committed Jun 5, 2017
1 parent 06695c4 commit 3b4cb47
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/src/core/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,46 @@ describe('resolve', function () {
expect(testContextReports.length).to.equal(0)
})

it('respects import/resolver as array of strings', function () {
const testContext = utils.testContext({ 'import/resolver': [ './foo-bar-resolver-v2', './foo-bar-resolver-v1' ] })

expect(resolve( '../files/foo'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('foo.js') } })
)).to.equal(utils.testFilePath('./bar.jsx'))
})

it('respects import/resolver as object', function () {
const testContext = utils.testContext({ 'import/resolver': { './foo-bar-resolver-v2': {} } })

expect(resolve( '../files/foo'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('foo.js') } })
)).to.equal(utils.testFilePath('./bar.jsx'))
})

it('respects import/resolver as array of objects', function () {
const testContext = utils.testContext({ 'import/resolver': [ { './foo-bar-resolver-v2': {} }, { './foo-bar-resolver-v1': {} } ] })

expect(resolve( '../files/foo'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('foo.js') } })
)).to.equal(utils.testFilePath('./bar.jsx'))
})

it('reports invalid import/resolver config', function () {
const testContext = utils.testContext({ 'import/resolver': 123.456 })
const testContextReports = []
testContext.report = function (reportInfo) {
testContextReports.push(reportInfo)
}

testContextReports.length = 0
expect(resolve( '../files/foo'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('foo.js') } })
)).to.equal(undefined)
expect(testContextReports[0]).to.be.an('object')
expect(testContextReports[0].message).to.equal('Resolve error: invalid resolver config')
expect(testContextReports[0].loc).to.eql({ line: 1, column: 0 })
})

it('respects import/resolve extensions', function () {
const testContext = utils.testContext({ 'import/resolve': { 'extensions': ['.jsx'] }})

Expand Down

0 comments on commit 3b4cb47

Please sign in to comment.