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

feat: switching test framework to vitest #655

Closed
wants to merge 1 commit into from

Conversation

blurfx
Copy link
Member

@blurfx blurfx commented Sep 23, 2023

What this PR does / why we need it?

Switching test framework to vitest from karma.

karma is deprecated and no longer maintained and It's hard to configure and slower than other modern test frameworks. vitest is one of the fastest modern testing frameworks and can be used with a near-zero configuration, that is why I chose it.

for this pull request, I did the following things:

  • karma, mocha, and chai are removed and replaced with vitest
  • Changed to use vi.fn() instead of sinon.spy()
  • Changed to use vi.fn().mockImplementation instead of sinon.stub().callsFake()
  • Changed to use task.name instead of this.test!.title (to get the title of current test)
  • Changed to inject the yorkie rpc address for testing as an environment variable

and I used happy-dom for vitest test environment, because:

  • XMLHttpRequest (which relies on protobuf) was not available in the node environment, and global injection was not possible.
  • In the jsdom environment, there was a problem parsing Uint8Array in protobuf because jsdom overrides some classes with its own implementation.
    • validation will always fail because its validated like (jsdom.Uint8Array) instanceof (v8.Uint8Array).

Any background context you want to provide?

What are the relevant tickets?

Fixes #654

Checklist

  • Added relevant tests or not required
  • Didn't break anything

@blurfx blurfx self-assigned this Sep 23, 2023
@blurfx blurfx force-pushed the feat/vitest branch 3 times, most recently from 34ad02f to d8769dc Compare September 23, 2023 19:38
@blurfx blurfx marked this pull request as draft September 27, 2023 07:00
@hackerwins hackerwins mentioned this pull request Oct 12, 2023
2 tasks
@hackerwins hackerwins closed this Oct 12, 2023
hackerwins added a commit that referenced this pull request Oct 13, 2023
karma is deprecated and no longer maintained and It's hard to
configure and slower than other modern test frameworks. vitest is one
of the fastest modern testing frameworks and can be used with a
near-zero configuration, that is why we chose it.

For this PR, we did the following things:

- Changes from #655
  - karma, mocha, sinon and chai are removed and replaced with vitest
  - Use vi.fn() instead of sinon.spy()
  - Use vi.fn().mockImplementation instead of sinon.stub().callsFake()
  - Use task.name instead of this.test!.title to get the title of test
  - Inject yorkie RPC address for testing as an environment variable
- Fix XMLHttpRequest mock. not using sinon anymore
- Use a customized jsdom vitest environment to prevent the
  implementation of the Uint8Array from being overwritten via jsdom

---------

Co-authored-by: blurfx <[email protected]>
@blurfx blurfx deleted the feat/vitest branch December 20, 2023 15:34
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.

Suggestion: migrate karma to a another test framework
2 participants