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(dependency): Improve test coverage #2759

Merged

Conversation

ts1994tw
Copy link
Contributor

@ts1994tw ts1994tw commented Oct 2, 2024

Summary

This pull request enhances the test suite for Jotai's dependency management, particularly focusing on complex scenarios. The following improvement has been made:

New Test Cases

  1. Complex Dependency Chains
    • Introduced a test case that verifies Jotai's ability to handle and update complex chains of derived atoms, including async derivations.

Coverage Improvements

  • Multi-level Derivations: Verifies that updates properly propagate through multiple levels of derived atoms, including async operations.

Check List

  • pnpm run prettier for formatting code and docs

Appreciated for having me your time on reviewing changes.

Copy link

vercel bot commented Oct 2, 2024

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

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 5:13am

Copy link

codesandbox-ci bot commented Oct 2, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

github-actions bot commented Oct 2, 2024

LiveCodes Preview in LiveCodes

Latest commit: cefd207
Last updated: Oct 3, 2024 5:12am (UTC)

Playground Link
React demo https://livecodes.io?x=id/27KQLS2MD

See documentations for usage instructions.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Thanks for working on this.
Here are some comments.

Comment on lines 278 to 286
it('handles errors in async atoms', async () => {
const errorAtom = atom(async () => {
throw new Error('Test error')
})

const store = createStore()

await expect(store.get(errorAtom)).rejects.toThrow('Test error')
})
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem a dependency test. Maybe move to some other file?

Copy link
Contributor Author

@ts1994tw ts1994tw Oct 3, 2024

Choose a reason for hiding this comment

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

@dai-shi Appreciated for comments.

You're absolutely right, it should be moved out of here. These changes have been removed from this pull request at this moment, after that, this pull request will be goal-focused enough and for dependency test only. Descriptions for this pull request has been updated as well already.

const derived2 = atom((get) => get(derived1) + 1)
const asyncDerived = atom(async (get) => {
const value = get(derived2)
await new Promise((resolve) => setTimeout(resolve, 10))
Copy link
Member

Choose a reason for hiding this comment

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

We don't use timers in the test.
Please do something like this:

await new Promise<void>((r) => (resolve = r))

Copy link
Contributor Author

@ts1994tw ts1994tw Oct 3, 2024

Choose a reason for hiding this comment

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

@dai-shi Appreciated for indication and 6186a57 is adjustment which follows comment here.

const atoms = new Array(1000).fill(null).map((_, i) => atom(i))
const derivedAtom = atom((get) => atoms.reduce((sum, a) => sum + get(a), 0))

const start = performance.now()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't think we do performance tests in our unit tests.
Can you try something with ./benchmarks? It's not a test that runs on CI, but you can try more complex cases and share the result in a discussion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the existing benchmark suite also needs some refinement. I did some resource tracking a while back and memory consumption was not lining up with what I thought the tests are testing for

Copy link
Member

Choose a reason for hiding this comment

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

I think the existing benchmark suite also needs some refinement.

I actually agree. Not just refinement, you can create a brand new benchmark suite. We can even delete existing one, if yours covers it. That would be pretty helpful.

Copy link
Contributor Author

@ts1994tw ts1994tw Oct 3, 2024

Choose a reason for hiding this comment

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

@backbone87 Appreciated for sharing detections you noticed before. @dai-shi I prefer to leave this topic aside and it should be independently handled by another clear and goal-focused pull request. These changes have been removed at this moment. 🙇

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

@dai-shi dai-shi merged commit d5bb477 into pmndrs:main Oct 3, 2024
40 checks passed
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.

3 participants