From 06695c49425fa0029deb69cbc94b0229f2bbe508 Mon Sep 17 00:00:00 2001 From: Ivan Babak Date: Sun, 4 Jun 2017 16:57:45 -0700 Subject: [PATCH] eslint-module-utils: Add test for when resolver version is not specified --- tests/files/foo-bar-resolver-no-version.js | 15 +++++++++++++++ tests/src/core/resolve.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/files/foo-bar-resolver-no-version.js diff --git a/tests/files/foo-bar-resolver-no-version.js b/tests/files/foo-bar-resolver-no-version.js new file mode 100644 index 000000000..6676133b0 --- /dev/null +++ b/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 + } +} diff --git a/tests/src/core/resolve.js b/tests/src/core/resolve.js index b585e7218..0ead05db0 100644 --- a/tests/src/core/resolve.js +++ b/tests/src/core/resolve.js @@ -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 = []