-
-
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.
Add
testInvalidRuleConfigs
function instead of invalidConfig
sche…
…ma property
- Loading branch information
1 parent
264ebf1
commit 40a332c
Showing
9 changed files
with
146 additions
and
41 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
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,20 @@ | ||
'use strict'; | ||
|
||
const getTestInvalidRuleConfigs = require('../getTestInvalidRuleConfigs.js'); | ||
|
||
const testInvalidRuleConfigs = getTestInvalidRuleConfigs(); | ||
|
||
testInvalidRuleConfigs({ | ||
plugins: [require.resolve('./fixtures/plugin-foo.js')], | ||
ruleName: 'plugin/foo', | ||
|
||
configs: [ | ||
{ | ||
config: 123, | ||
}, | ||
{ | ||
config: [/foo/], | ||
description: 'regex is not allowed', | ||
}, | ||
], | ||
}); |
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,49 @@ | ||
'use strict'; | ||
|
||
const { inspect } = require('util'); | ||
|
||
/** @type {import('.').getTestInvalidRuleConfigs} */ | ||
module.exports = function getTestInvalidRuleConfigs(options = {}) { | ||
return function testInvalidRuleConfigs({ | ||
ruleName, | ||
configs, | ||
only, | ||
skip, | ||
plugins = options.plugins, | ||
}) { | ||
if (configs.length === 0) { | ||
throw new TypeError('The "configs" 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} invalid configs`, () => { | ||
for (const { config, description, only: onlyTest, skip: skipTest } of configs) { | ||
const testFn = onlyTest ? test.only : skipTest ? test.skip : test; | ||
|
||
/* eslint-disable jest/no-standalone-expect */ | ||
testFn(`${description || inspect(config)}`, async () => { | ||
const lintConfig = { | ||
plugins, | ||
rules: { [ruleName]: config }, | ||
}; | ||
const output = await lint({ code: '', config: lintConfig }); | ||
|
||
expect(output.results).toHaveLength(1); | ||
expect(output.results[0].invalidOptionWarnings).toEqual([ | ||
{ text: expect.stringMatching(`"${ruleName}"`) }, | ||
]); | ||
}); | ||
/* eslint-enable jest/no-standalone-expect */ | ||
} | ||
}); | ||
}; | ||
}; |
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
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,5 +1,7 @@ | ||
'use strict'; | ||
|
||
const getTestRule = require('./getTestRule'); | ||
const getTestRule = require('./getTestRule.js'); | ||
const getTestInvalidRuleConfigs = require('./getTestInvalidRuleConfigs.js'); | ||
|
||
global.testRule = getTestRule(); | ||
global.testInvalidRuleConfigs = getTestInvalidRuleConfigs(); |
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