Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint-module-utils tests #865

Merged
merged 17 commits into from
Jun 22, 2017
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eslint-module-utils: Add test for when resolver version is not specified
sompylasar committed Jun 4, 2017

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
commit 06695c49425fa0029deb69cbc94b0229f2bbe508
15 changes: 15 additions & 0 deletions tests/files/foo-bar-resolver-no-version.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 = []