Skip to content
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

Add testRuleConfigs function #68

Merged
merged 6 commits into from Aug 10, 2023
Merged

Add testRuleConfigs function #68

merged 6 commits into from Aug 10, 2023

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Aug 9, 2023

Which issue, if any, is this issue related to?

Ref stylelint/stylelint#7124

Is there anything in the PR that needs further explanation?

This change adds a new schema property to test an invalid rule configuration.

Usage:

testRule({
	ruleName,
	config: ['number'],
	invalidConfig: ['foo'],
	accept: [/*...*/],
	reject: [/*...*/],
});

This PR adds a new global function testInvalidRuleConfigs to test invalid rule configs.

Usage:

testInvalidRuleConfigs({
  plugins: ["."],
  ruleName,

  accept: [
    {
      config: "valid"
    }
  ],

  reject: [
    {
      config: "invalid"
    },
    {
      config: [/invalid/],
      description: "regex is not allowed"
    }
  ]
});

Output:

$ npx jest --verbose
 PASS  __tests__/getTestRuleConfigs.test.js
  plugin/foo configs
    accept
      ✓ 'a' (32 ms)
      ✓ string is allowed (1 ms)
    reject
      ✓ 123 (1 ms)
      ✓ regex is not allowed (1 ms)

 PASS  __tests__/getTestRule.test.js
  plugin/foo
    accept
      [ '.a' ]
        '.a {}'
          ✓ no description (19 ms)
          ✓ with description (1 ms)
    reject
      [ '.a' ]
        '#a {}'
          ✓ no description (1 ms)
          ✓ with description (1 ms)

This change adds a new schema property to test an invalid rule configuration.
@ybiquitous ybiquitous marked this pull request as ready for review August 9, 2023 16:20
@jeddy3
Copy link
Member

jeddy3 commented Aug 10, 2023

It feels useful to test invalid configs but a little counterintuitive to do so in testRule.

We created testRule to make it easier to check that a rule was correctly reporting problems against snippets of CSS—the schema properties like config, customSyntax, fix, ruleName, and so on set up a run for the tests in accept and reject.

A invalidConfig schema property feels out of place as it doesn't fit in either of these categories, i.e. it's not setting up a run nor testing against CSS.

I wonder if we can find a better home for it. Perhaps we can add another function to the preset, e.g. testInvalidRuleConfigs which has a simpler schema designed around testing multiple invalid configs:

testInvalidRuleConfigs({
  plugins: ["."],
  ruleName,
  configs: [
    {
      "config": ['foo'],
      "description": "a single string" // optional description if needed
    },
    {
      "config": [21312]
    }
  ]
})

@ybiquitous
Copy link
Member Author

@jeddy3 Thanks for the great feedback! I agree with your suggestion, so I'll rewrite the code to create a new function. 👍🏼

@ybiquitous ybiquitous requested a review from jeddy3 August 10, 2023 09:28
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

It feels more intuitive as a separate function.

I've added one comment.

README.md Outdated Show resolved Hide resolved
@jeddy3 jeddy3 changed the title Add invalidConfig schema property Add testRuleConfigs function Aug 10, 2023
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for making all the changes!

@ybiquitous
Copy link
Member Author

Thanks, too. I appreciate your helpful advice. 😄

I'll release the next version 6.2.0 after merging this PR!

@ybiquitous ybiquitous merged commit d0ee0bc into main Aug 10, 2023
6 checks passed
@ybiquitous ybiquitous deleted the invalidConfig branch August 10, 2023 12:31
@ybiquitous
Copy link
Member Author

https://github.com/stylelint/jest-preset-stylelint/releases/tag/6.2.0 released! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants