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

test(asyncapi): use a simple rule tester #1650

Merged
merged 5 commits into from
Jun 8, 2021
Merged

Conversation

P0lip
Copy link
Contributor

@P0lip P0lip commented Jun 2, 2021

Related to #1082 and #1618

Checklist

  • Tests added / updated
  • Docs added / updated

Does this PR introduce a breaking change?

  • Yes
  • No

Additional context

This essentially removes all the boilerplate and burden we needed to test a particular rule.
Right now, that logic is hidden in a single file, while each test is actually oriented on the expected output.

I'm planning to apply the same change to the OAS ruleset tests.

Later on, when built-in rulesets have new home, we'll either leave a util in Spectral (I bet this will be super useful for other rulesets too, in a similar fashion to the ESLint offers), or move the util altogether to the new repo.

I feel like it doesn't make sense to review each file - verifying the approach is what we should put more focus on.
Thea idea is that instead of initializing Spectral with a ruleset, and then writing assertions manually, etc., you simply rely on testRule to do all of that.
This way we're totally independent of changes occurring to Spectral.

import { DiagnosticSeverity } from '@stoplight/types';
import testRule from './__helpers__/tester';

testRule('asyncapi-channel-no-empty-parameter', [
  {
    name: 'valid case',
    document: {
      asyncapi: '2.0.0',
      channels: {
        'users/{userId}/signedUp': {},
      },
    },
    errors: [],
  },

  {
    name: 'channels.{channel} contains empty parameter substitution pattern',
    document: {
      asyncapi: '2.0.0',
      channels: {
        'users/{userId}/signedUp': {},
        'users/{}/signedOut': {},
      },
    },
    errors: [
      {
        message: 'Channel path should not have empty parameter substitution pattern.',
        path: ['channels', 'users/{}/signedOut'],
        severity: DiagnosticSeverity.Warning,
      },
    ],
  },
]);

@P0lip P0lip added the chore label Jun 2, 2021
@P0lip P0lip self-assigned this Jun 2, 2021
@P0lip P0lip changed the title test(asyncapi): use a template test(asyncapi): use a simple rule tester Jun 2, 2021
@P0lip P0lip marked this pull request as ready for review June 4, 2021 09:38
@P0lip P0lip requested a review from mnaumanali94 June 4, 2021 09:38
@P0lip P0lip requested a review from domagojk June 7, 2021 13:20
Copy link
Contributor

@domagojk domagojk left a comment

Choose a reason for hiding this comment

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

Much nicer 👌

@P0lip P0lip enabled auto-merge (squash) June 8, 2021 11:03
@P0lip P0lip merged commit 2ad9651 into develop Jun 8, 2021
@P0lip P0lip deleted the test/asyncapi-template branch June 8, 2021 11:10
@P0lip P0lip mentioned this pull request Jun 10, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants