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: implement additional test cases for the node test reporter #5669

Merged
merged 11 commits into from
Aug 29, 2024

Conversation

galargh
Copy link
Member

@galargh galargh commented Aug 23, 2024

  • Because this PR includes a bug fix, relevant tests have been included.
  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
  • I didn't do anything of this.

This PR is part of the initiative to enhance our custom reporter - #5437

This PR modifies the reporter's test runner in the following ways:

  • adds a --test-only flag (e.g. running pnpm test:integration --test-only example-project would only run the tests for the example-project fixture)
  • adds flag parsing (only --show-output, --test-only, --color, --no-color are accepted)
  • ensures the tests are executed relatively to the reporter's root (this is relevant for some traces)
  • ensures all ms timing signatures are replaced with Xs
  • ensures all node line:column references are replaces with X:Xs

This PR also adds the following test cases:

  • hooks (i.e. before, beforeEach, after, afterEach, describe)
    • throw an error from within a hook
  • multiple files
    • import a function which fails when executed inside a test case
    • import a function which passes when executed inside a test case
  • nested describes (3 levels)
    • fail a test case
    • pass a test case
    • throw an error with cause inside a test case
  • test.only
  • fail a test case
  • slow test
    • pass a slow test case
    • fail a slow test case
  • test.todo
    • fail a test case
  • top level test (without a describe)
    • fail a test case
    • pass a test case
    • throw an error with cause inside a test case

Follow-up Questions

  1. Should we continue to include colour codes in the expected/actual outputs?
    • My thinking is that diffs are easier to parse for humans without them, but it comes at a price of not checking the right colouring.
  2. Should we expect test.only tests to be executed by default?
  3. Do we want any special markings for TODO tests?
  4. Should we have any inline indication if a test throws in the after (3))/describe (11)) block?

Copy link

vercel bot commented Aug 23, 2024

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

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 1:28pm

Copy link

changeset-bot bot commented Aug 23, 2024

⚠️ No Changeset found

Latest commit: 9fcd531

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@galargh galargh force-pushed the galargh/test-reporter-tests branch from 9d758de to 4cee340 Compare August 26, 2024 12:39
@galargh galargh changed the base branch from galargh/test-integration to v-next August 26, 2024 12:39
@galargh galargh closed this Aug 26, 2024
@galargh galargh reopened this Aug 26, 2024
@galargh galargh changed the title [WIP] chore: implement additional test cases for the node test reporter chore: implement additional test cases for the node test reporter Aug 26, 2024
@galargh
Copy link
Member Author

galargh commented Aug 26, 2024

I scheduled sync time with @alcuadrado this week to discuss the follow-up questions that came to me during the course of preparation of this PR. I don't believe any of them should be blocking for this PR through.

@galargh galargh marked this pull request as ready for review August 26, 2024 14:20
@alcuadrado
Copy link
Member

Should we continue to include colour codes in the expected/actual outputs?

  • My thinking is that diffs are easier to parse for humans without them, but it comes at a price of not checking the right colouring.

I think, ideally, we include them, but also in some rendered format. I've tried a few solutions and this seems to be the best option:

sudo apt install aha wkhtmltoimage
cat result.txt | aha --black  > result.html
wkhtmltoimage --format svg result.html result.svg

There are some node.js solutions, but they pull puppeteer, which don't seem to work on devcontainer on apple silicon.

@alcuadrado
Copy link
Member

Great work, @galargh!

I have some comments/questions related the tests and the behavior that we want to achieve in the reporter:

  • hooks-tests: Can we report that a failure was in an afterEach hook?
  • hooks-tests: I think the after and before errors look well.
  • hooks-tests: The tests cancelled due to a before error could probably be improved, now that we know that after, afterEach, and beforeEach don't cancel the test.
  • hooks-tests: Same for the ones cancelled due to a describe error.
  • hooks-tests: Can we distinguish what cancelled each test?
  • multi-test: can we avoid showing the empty file paths? This behavior is also present when you use --test-only.
  • nested-test: we are missing the case of tests nested inside tests, which IMO is a very unfortunate feature. We should test that path though. Note that a nested it whithin an it needs to be awaited.
  • only-test: we should probably add another file to that test, with a an ignored describe and it.
  • onlyt-test: we should probably test it with and without --test-only, so that we can see the two behaviors.
  • todo-test: we can also add a it.todo withot a callback, as that's the actual todo behavior. It's unexpected that node:test runs the test if you do provide a callback, so our current test is asserting a failure.

Follow-up Questions

  1. See my PR into this PR, I think it's a good trade-off.

  2. Unfortunately, node:test imposes that behavior. I think it's to avoid the typical situation where you push a .only accidentally and your CI magically passes in 10ms. I disagree with that product decision, but it's out of our control.

See the note about the test, though.

Also, we may need a way to customize the message that tells the user to run with --test-only, as Hardhat's CLI is different. Ideally we just pass it as an argument.

  1. I think the test is not treated as a "todo test" because it has a callback. If you remove it, it is shown differently. We should probably test both cases.

  2. Great points. I also covered them in my notes.

Copy link
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

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

Looking good. Let's dicuss it in our call tomorrow.

Copy link
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

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

As we discussed in our call, let's merge this and implement any improvements to the reporter in follow-up PRs.

re the missing test cases: if you want to add them here that's also fine, but may a follow up PR would be easier to review.

@galargh
Copy link
Member Author

galargh commented Aug 29, 2024

As we discussed in our call, let's merge this and implement any improvements to the reporter in follow-up PRs.

re the missing test cases: if you want to add them here that's also fine, but may a follow up PR would be easier to review.

That makes sense, thank you for the approve. I'm going to merge it as-is and propose the other work items we discussed in follow-up PRs.

@galargh galargh added this pull request to the merge queue Aug 29, 2024
Merged via the queue into v-next with commit 2b7fbb4 Aug 29, 2024
64 checks passed
@galargh galargh deleted the galargh/test-reporter-tests branch August 29, 2024 10:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants