Skip to content

Commit

Permalink
eslint-module-utils: Add test for when resolver version is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
sompylasar committed Jun 4, 2017
1 parent f65c263 commit 06695c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/files/foo-bar-resolver-no-version.js
@@ -0,0 +1,15 @@
var path = require('path')

exports.resolveImport = function (modulePath, sourceFile, config) {
var fooPathSuffix = '/files/foo.js'
var exceptionPathSuffix = '/files/exception.js'
if (sourceFile.indexOf(fooPathSuffix) === sourceFile.length - fooPathSuffix.length) {
return path.join(__dirname, 'bar.jsx')
}
else if (sourceFile.indexOf(exceptionPathSuffix) === sourceFile.length - exceptionPathSuffix.length) {
throw new Error('foo-bar-resolver-v1 resolveImport test exception')
}
else {
return undefined
}
}
16 changes: 16 additions & 0 deletions tests/src/core/resolve.js
Expand Up @@ -27,6 +27,22 @@ describe('resolve', function () {
)).to.equal(undefined)
})

it('resolves via a custom resolver with interface version 1 assumed if not specified', function () {
const testContext = utils.testContext({ 'import/resolver': './foo-bar-resolver-no-version'})

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

expect(resolve( '../files/exception'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('exception.js') } })
)).to.equal(undefined)

expect(resolve( '../files/not-found'
, Object.assign({}, testContext, { getFilename: function () { return utils.getFilename('not-found.js') } })
)).to.equal(undefined)
})

it('resolves via a custom resolver with interface version 2', function () {
const testContext = utils.testContext({ 'import/resolver': './foo-bar-resolver-v2'})
const testContextReports = []
Expand Down

0 comments on commit 06695c4

Please sign in to comment.