Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(experimental-utils): add few missing tests (#1449)
- Loading branch information
1 parent
4726605
commit 8dcdfb1
Showing
4 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/experimental-utils/tests/eslint-utils/RuleCreator.test.ts
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,46 @@ | ||
import { ESLintUtils } from '../../src'; | ||
|
||
describe('RuleCreator', () => { | ||
const createRule = ESLintUtils.RuleCreator(name => `test/${name}`); | ||
|
||
it('createRule should be a function', () => { | ||
expect(typeof createRule).toEqual('function'); | ||
}); | ||
|
||
it('should create rule correctly', () => { | ||
const rule = createRule({ | ||
name: 'test', | ||
meta: { | ||
docs: { | ||
description: 'some description', | ||
category: 'Best Practices', | ||
recommended: 'error', | ||
requiresTypeChecking: true, | ||
}, | ||
messages: { | ||
foo: 'some message', | ||
}, | ||
schema: [], | ||
type: 'problem', | ||
}, | ||
defaultOptions: [], | ||
create() { | ||
return {}; | ||
}, | ||
}); | ||
expect(rule.meta).toEqual({ | ||
docs: { | ||
description: 'some description', | ||
category: 'Best Practices', | ||
url: 'test/test', | ||
recommended: 'error', | ||
requiresTypeChecking: true, | ||
}, | ||
messages: { | ||
foo: 'some message', | ||
}, | ||
schema: [], | ||
type: 'problem', | ||
}); | ||
}); | ||
}); |
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
81 changes: 81 additions & 0 deletions
81
packages/experimental-utils/tests/eslint-utils/batchedSingleLineTests.test.ts
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,81 @@ | ||
import { ESLintUtils } from '../../src'; | ||
|
||
describe('batchedSingleLineTests', () => { | ||
const FIXTURES = ` | ||
a | ||
b | ||
c | ||
`; | ||
const errors = [ | ||
{ messageId: 'someMessage1', line: 2 }, | ||
{ messageId: 'someMessage2', line: 3 }, | ||
{ messageId: 'someMessage3', line: 4 }, | ||
]; | ||
const options = [{ optionOne: 'value' }]; | ||
|
||
it('should work without options', () => { | ||
expect( | ||
ESLintUtils.batchedSingleLineTests({ | ||
code: FIXTURES, | ||
}), | ||
).toEqual([ | ||
{ code: 'a', errors: [] }, | ||
{ code: 'b', errors: [] }, | ||
{ code: 'c', errors: [] }, | ||
]); | ||
}); | ||
|
||
it('should work with errors', () => { | ||
expect( | ||
ESLintUtils.batchedSingleLineTests({ | ||
code: FIXTURES, | ||
errors, | ||
}), | ||
).toEqual([ | ||
{ code: 'a', errors: [{ messageId: 'someMessage1', line: 1 }] }, | ||
{ code: 'b', errors: [{ messageId: 'someMessage2', line: 1 }] }, | ||
{ code: 'c', errors: [{ messageId: 'someMessage3', line: 1 }] }, | ||
]); | ||
}); | ||
|
||
it('should work with all fields', () => { | ||
const filename = 'foo.ts'; | ||
const parser = 'some-parser'; | ||
|
||
expect( | ||
ESLintUtils.batchedSingleLineTests({ | ||
code: FIXTURES, | ||
errors, | ||
options, | ||
parser, | ||
output: FIXTURES, | ||
filename, | ||
}), | ||
).toEqual([ | ||
{ | ||
code: 'a', | ||
output: 'a', | ||
errors: [{ messageId: 'someMessage1', line: 1 }], | ||
parser, | ||
filename, | ||
options, | ||
}, | ||
{ | ||
code: 'b', | ||
output: 'b', | ||
errors: [{ messageId: 'someMessage2', line: 1 }], | ||
parser, | ||
filename, | ||
options, | ||
}, | ||
{ | ||
code: 'c', | ||
output: 'c', | ||
errors: [{ messageId: 'someMessage3', line: 1 }], | ||
parser, | ||
filename, | ||
options, | ||
}, | ||
]); | ||
}); | ||
}); |
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