-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename
testInvalidRuleConfigs
to testRuleConfigs
- Loading branch information
1 parent
36a1bc5
commit b77ecc8
Showing
9 changed files
with
128 additions
and
93 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
## Head | ||
|
||
- Added: `testInvalidRuleConfigs` function. | ||
- Added: `testRuleConfigs` function. | ||
|
||
## 6.1.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
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
'use strict'; | ||
|
||
const getTestRuleConfigs = require('../getTestRuleConfigs.js'); | ||
|
||
const testRuleConfigs = getTestRuleConfigs(); | ||
|
||
testRuleConfigs({ | ||
plugins: [require.resolve('./fixtures/plugin-foo.js')], | ||
ruleName: 'plugin/foo', | ||
|
||
accept: [ | ||
{ | ||
config: 'a', | ||
}, | ||
{ | ||
config: ['b'], | ||
description: 'string is allowed', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
config: 123, | ||
}, | ||
{ | ||
config: [/foo/], | ||
description: 'regex is not allowed', | ||
}, | ||
], | ||
}); |
This file was deleted.
Oops, something went wrong.
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,68 @@ | ||
'use strict'; | ||
|
||
const { inspect } = require('util'); | ||
|
||
/** @type {import('.').getTestRuleConfigs} */ | ||
module.exports = function getTestRuleConfigs(options = {}) { | ||
return function testRuleConfigs({ | ||
ruleName, | ||
accept = [], | ||
reject = [], | ||
only = false, | ||
skip = false, | ||
plugins = options.plugins, | ||
}) { | ||
if (accept.length === 0 && reject.length === 0) { | ||
throw new TypeError('The either "accept" or "reject" property must not be empty'); | ||
} | ||
|
||
/** @type {import('stylelint').lint} */ | ||
let lint; | ||
|
||
beforeAll(() => { | ||
// eslint-disable-next-line n/no-unpublished-require | ||
lint = require('stylelint').lint; | ||
}); | ||
|
||
const testGroup = only ? describe.only : skip ? describe.skip : describe; | ||
|
||
testGroup(`${ruleName} configs`, () => { | ||
/** | ||
* @param {import('.').ConfigCase} case | ||
* @param {(warnings: unknown[]) => void} comparison | ||
*/ | ||
function testConfig({ config, description, only: onlyTest, skip: skipTest }, comparison) { | ||
const testFn = onlyTest ? test.only : skipTest ? test.skip : test; | ||
|
||
testFn(`${description || inspect(config)}`, async () => { | ||
const lintConfig = { | ||
plugins, | ||
rules: { [ruleName]: config }, | ||
}; | ||
const { results } = await lint({ code: '', config: lintConfig }); | ||
|
||
expect(results).toHaveLength(1); | ||
comparison(results[0].invalidOptionWarnings); | ||
}); | ||
} | ||
|
||
describe('accept', () => { | ||
accept.forEach((c) => { | ||
testConfig(c, (warnings) => { | ||
// eslint-disable-next-line jest/no-standalone-expect | ||
expect(warnings).toEqual([]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('reject', () => { | ||
reject.forEach((c) => { | ||
testConfig(c, (warnings) => { | ||
// eslint-disable-next-line jest/no-standalone-expect | ||
expect(warnings).toEqual([{ text: expect.stringMatching(`"${ruleName}"`) }]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
'use strict'; | ||
|
||
const getTestRule = require('./getTestRule.js'); | ||
const getTestInvalidRuleConfigs = require('./getTestInvalidRuleConfigs.js'); | ||
const getTestRuleConfigs = require('./getTestRuleConfigs.js'); | ||
|
||
global.testRule = getTestRule(); | ||
global.testInvalidRuleConfigs = getTestInvalidRuleConfigs(); | ||
global.testRuleConfigs = getTestRuleConfigs(); |
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