Skip to content

Conversation

@six-shopify
Copy link
Contributor

@six-shopify six-shopify commented Feb 13, 2025

What are you adding in this PR?

Another small one from me. Currently the check() test helper (which wraps the main check() export) will happily run a broken rule and report no issues. That is, given a check like this:

export const SomeWonkyCheck: LiquidCheckDefinition = {
  // metadata block excluded...
  create(context) {
    return {
      async LiquidRawTag(node) {
        throw new Error("I tried to do something weird!")
      },
    };
  },
};

a test like this will be green:

it('does not report an error, even if the rule implementation is busted', async () => {
  const theme = {
    'sections/example.liquid': toLiquid(someConfigThatTriggersAnEdgeCase),
  };

  const offenses = await check(theme, [SomeWonkyCheck]);

  expect(offenses).toHaveLength(0);
});

This PR overrides the default no-op onError so that we properly rethrow errors when running tests, rather than silently squelching all error output. Fortunately, this doesn't seem to unmask any broken test cases. I can't really think of any reason this shouldn't be the default — callers of the check() test helper can wrap it in try...catch if they genuinely have some reason to expect a check to throw, though my intuition is that checks should never be doing that on purpose.

export async function check(
themeDesc: MockTheme,
checks: CheckDefinition<SourceCodeType>[] = recommended,
checks: CheckDefinition[] = recommended,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SourceCodeType is already the default for this generic param (our shared ESLint config reports this but it's not set up for this repo yet, see #781)

Copy link
Contributor

@charlespwd charlespwd left a comment

Choose a reason for hiding this comment

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

LGTM! Doesn't need a changeset since this doesn't change any public API

Also wow TIL.

@six-shopify six-shopify merged commit aa5bd7c into main Feb 13, 2025
6 checks passed
@six-shopify six-shopify deleted the test-helper-should-throw branch February 13, 2025 18:51
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.

2 participants