-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
benmosher
merged 17 commits into
import-js:master
from
sompylasar:eslint-module-utils_tests
Jun 22, 2017
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b4d75c8
eslint-module-utils: filePath in parserOptions
sompylasar 3544c0f
eslint-module-utils: Add tests for parserOptions
sompylasar 7712ce1
eslint-module-utils: Reverted manual version bumps.
sompylasar d4246fb
Merge branch 'benmosher/master' into patch-2
sompylasar d0007f2
Add sinon, replace eslint-module-utils test spy with sinon.spy
sompylasar 7ac5e8f
Fix CHANGELOG merge error
sompylasar d397b9b
eslint-module-utils: Add more tests for parse (coverage 100%)
sompylasar 5732742
eslint-module-utils: In tests move require stub parser to the top.
sompylasar 60b524b
Merge commit '3c46d308ccb462a52554257c49c374045d1a6cf7' into file_pat…
sompylasar 17d2ee9
eslint-module-utils: Add tests for hash utils
sompylasar a0012f8
eslint-module-utils: Add tests for resolver versions
sompylasar f65c263
eslint-module-utils: Unified test specs names to not use 'should' word
sompylasar 06695c4
eslint-module-utils: Add test for when resolver version is not specified
sompylasar 3b4cb47
eslint-module-utils: Add test for import/resolver config checks
sompylasar 2bc4f7f
eslint-module-utils: Add test for ignore
sompylasar 314ead8
eslint-module-utils: Fix test coding style
sompylasar 117717f
eslint-module-utils: Fix resolver tests for Windows paths
sompylasar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 | ||
} | ||
} | ||
|
||
exports.interfaceVersion = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var path = require('path') | ||
|
||
exports.resolve = function (modulePath, sourceFile, config) { | ||
var fooPathSuffix = '/files/foo.js' | ||
var exceptionPathSuffix = '/files/exception.js' | ||
if (sourceFile.indexOf(fooPathSuffix) === sourceFile.length - fooPathSuffix.length) { | ||
return { found: true, path: path.join(__dirname, 'bar.jsx') } | ||
} | ||
else if (sourceFile.indexOf(exceptionPathSuffix) === sourceFile.length - exceptionPathSuffix.length) { | ||
throw new Error('foo-bar-resolver-v2 resolve test exception') | ||
} | ||
else { | ||
return { found: false } | ||
} | ||
} | ||
|
||
exports.interfaceVersion = 2 |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { expect } from 'chai' | ||
|
||
import hashify, { hashArray, hashObject } from 'eslint-module-utils/hash' | ||
|
||
const createHash = require('crypto').createHash | ||
|
||
function expectHash(actualHash, expectedString) { | ||
const expectedHash = createHash('sha256') | ||
expectedHash.update(expectedString) | ||
expect(actualHash.digest('hex'), 'to be a hex digest of sha256 hash of string <' + expectedString + '>').to.equal(expectedHash.digest('hex')) | ||
} | ||
|
||
describe('hash', function () { | ||
describe('hashify', function () { | ||
it('handles null', function () { | ||
expectHash(hashify(null), 'null') | ||
}) | ||
|
||
it('handles undefined', function () { | ||
expectHash(hashify(undefined), 'undefined') | ||
}) | ||
|
||
it('handles numbers', function () { | ||
expectHash(hashify(123.456), '123.456') | ||
}) | ||
|
||
it('handles strings', function () { | ||
expectHash(hashify('a string'), '"a string"') | ||
}) | ||
|
||
it('handles Array instances', function () { | ||
expectHash(hashify([ 'a string' ]), '["a string",]') | ||
}) | ||
|
||
it('handles empty Array instances', function () { | ||
expectHash(hashify([]), '[]') | ||
}) | ||
|
||
it('handles Object instances', function () { | ||
expectHash(hashify({ foo: 123.456, 'a key': 'a value' }), '{"a key":"a value","foo":123.456,}') | ||
}) | ||
|
||
it('handles nested Object instances', function () { | ||
expectHash(hashify({ foo: 123.456, 'a key': 'a value', obj: { abc: { def: 'ghi' } } }), '{"a key":"a value","foo":123.456,"obj":{"abc":{"def":"ghi",},},}') | ||
}) | ||
|
||
it('handles nested Object and Array instances', function () { | ||
expectHash(hashify({ foo: 123.456, 'a key': 'a value', obj: { arr: [ { def: 'ghi' } ] } }), '{"a key":"a value","foo":123.456,"obj":{"arr":[{"def":"ghi",},],},}') | ||
}) | ||
}) | ||
|
||
describe('hashArray', function () { | ||
it('handles Array instances', function () { | ||
expectHash(hashArray([ 'a string' ]), '["a string",]') | ||
}) | ||
|
||
it('handles empty Array instances', function () { | ||
expectHash(hashArray([]), '[]') | ||
}) | ||
}) | ||
|
||
describe('hashObject', function () { | ||
it('handles Object instances', function () { | ||
expectHash(hashObject({ foo: 123.456, 'a key': 'a value' }), '{"a key":"a value","foo":123.456,}') | ||
}) | ||
|
||
it('handles nested Object instances', function () { | ||
expectHash(hashObject({ foo: 123.456, 'a key': 'a value', obj: { abc: { def: 'ghi' } } }), '{"a key":"a value","foo":123.456,"obj":{"abc":{"def":"ghi",},},}') | ||
}) | ||
|
||
it('handles nested Object and Array instances', function () { | ||
expectHash(hashObject({ foo: 123.456, 'a key': 'a value', obj: { arr: [ { def: 'ghi' } ] } }), '{"a key":"a value","foo":123.456,"obj":{"arr":[{"def":"ghi",},],},}') | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use "unpublished" here; "yanked" is an idiom and needlessly casual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb I don't mind, but that's @benmosher's, I just fixed the typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realize it was an existing pattern. Nvm then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw, I thought
YANKED
was a bit weird also, but I used it because it was explicitly defined on http://keepachangelog.com/ when I started it. I'm fine to move toUNPUBLISHED
if that's generally well-understood