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

chore: add jest config for ui package, convert Button tests to ts and fix existing assertions #13580

Merged
merged 8 commits into from
May 16, 2023

Conversation

brandongregoryscott
Copy link
Contributor

@brandongregoryscott brandongregoryscott commented Apr 10, 2023

What kind of change does this PR introduce?

Chore - reinstates tests for the ui package.

What is the current behavior?

See #13540 (comment) - it sounds like tests were started at some point (maybe in the https://github.com/supabase/ui repo) but weren't maintained once ported back into the monorepo.

What is the new behavior?

This PR adds a minimal jest config + refactors the Button component tests to pass based on its current code. It also adds a Github Action for running the tests in the packages/ui directory when any file in it changes.

 PASS  src/components/Button/Button.test.tsx
  #Button
    ✓ should render button correctly (37 ms)
    ✓ should render different text (24 ms)
    ✓ should ignore events when disabled (16 ms)
    ✓ should ignore events when loading (20 ms)
    ✓ should have "w-full" class when block is true (68 ms)
    ✓ should have "primary" class from theme (29 ms)
    ✓ should have "default" class from theme (20 ms)
    ✓ should have "secondary" class from theme (9 ms)
    ✓ should have "alternative" class from theme (11 ms)
    ✓ should have "outline" class from theme (13 ms)
    ✓ should have "dashed" class from theme (14 ms)
    ✓ should have "link" class from theme (18 ms)
    ✓ should have "text" class from theme (13 ms)
    ✓ should have "danger" class from theme (5 ms)
    ✓ should have "warning" class from theme (6 ms)
    ✓ should have "tiny" class from theme (15 ms)
    ✓ should have "small" class from theme (8 ms)
    ✓ should have "medium" class from theme (7 ms)
    ✓ should have "large" class from theme (6 ms)
    ✓ should have "xlarge" class from theme (9 ms)

Additional context

In an effort to keep this PR smaller and incrementally reinstate test suites / add new ones, I restricted the testRegex to just *.test.tsx files. I left a comment in the config file on why, but the existing tests are likely going to need some refactoring to pass anyway.

This PR also introduces a change to the way the Button component exposes its ref, since it was causing issues when wrapped with the Next Link component - I added a test for this as well. It's kinda hard to tell where/if the current ref was being used, but I think this should work.

@vercel
Copy link

vercel bot commented Apr 10, 2023

@brandongregoryscott is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Apr 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
studio-self-hosted ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
supabase-studio-prod ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
supabase-studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm
zone-www-dot-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2023 5:04pm

it("shouldn't crash when wrapped with next/link", () => {
expect(() =>
render(
<Link href="https://supabase.com">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was failing before the change to the ref - doesn't seem related to passing a custom element with the as prop as originally theorized in #13540 (comment)

@saltcod
Copy link
Contributor

saltcod commented May 15, 2023

Hey @brandongregoryscott ! had a look at this — your ui tests look good! But studio tests are failing on this branch. Any ideas?

CleanShot 2023-05-15 at 17 01 40@2x

@brandongregoryscott
Copy link
Contributor Author

brandongregoryscott commented May 15, 2023

Hey @saltcod - the studio tests are passing for me locally. Looks like they failed in Github Actions but not for the same reason (JavaScript heap error)

Edit: Alright, seeing the same heap errors on my fork. Might be a resource limitation I'm not seeing on my local machine. Let me take another look at these. I'm seeing it happen on the latest master from my fork too: https://github.com/brandongregoryscott/supabase/actions/runs/4986094913/attempts/1 and https://github.com/brandongregoryscott/supabase/actions/runs/4986094913

Those tests look time based - do we think they're just flaky? Not sure I have permission to retry the tests

@brandongregoryscott brandongregoryscott requested a review from a team as a code owner May 16, 2023 00:13
@brandongregoryscott
Copy link
Contributor Author

brandongregoryscott commented May 16, 2023

Following-up: The heap issue was happening on my fork off of the fresh master, too. Not sure why it's happening all of a sudden, could just be a tipping point. Following the instructions in this comment, this seems to resolve the CI issues: https://github.com/brandongregoryscott/supabase/actions/runs/4986366186/jobs/8927026785

@saltcod saltcod merged commit 195a859 into supabase:master May 16, 2023
14 checks passed
@brandongregoryscott brandongregoryscott deleted the fix-test-suites branch May 18, 2023 13:38
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

3 participants