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

[FEATURE] Vitest support #295

Closed
adaliszk opened this issue Sep 13, 2022 · 8 comments · Fixed by #300
Closed

[FEATURE] Vitest support #295

adaliszk opened this issue Sep 13, 2022 · 8 comments · Fixed by #300
Assignees

Comments

@adaliszk
Copy link

I've been using Testdeck for a few years to simplify my test cases with classes using Jest, and I am pleased with the quality and massive KUDOs for that! However, recently within our team, we started to look into Vitest as a potential alternative for our testing framework, and I would like to keep my trusty companion 😉

Would it be possible to add first-class Vitest support?

For now, I am looking into using Vitest with Jest, and that way, use Testdeck. Nothing super urgent or anything like that, but I thought we could start a discussion about it at least.

@silkentrance silkentrance self-assigned this Sep 14, 2022
@silkentrance
Copy link
Member

silkentrance commented Sep 14, 2022

While working on this, I noticed that we do not support Promises, which are required by vitest@latest.

Our existing code just checks for a first parameter , see

function isAsync(method: Function): boolean {

to determine whether a given test function/method is async or not.

And vitest deprecated the done callback in favour of promises.

This will require additional work.

@silkentrance
Copy link
Member

silkentrance commented Sep 14, 2022

@adaliszk thanks for the feature request. I am currently looking into it.

But why would you use vitest and in addition jest? Does vitest not already provide for the same mechanisms and behaviours?

As for testdeck, we cannot support both at the same time, as some test frameworks register their describe etc. as globals while some may not, e.g. vitest.

That being said, you might run into issues when using both @testdeck/jest and a future @testdeck/vitest at the same time while migrating your existing tests.

And, please, let us know about these issues.

@silkentrance silkentrance linked a pull request Sep 14, 2022 that will close this issue
@adaliszk
Copy link
Author

adaliszk commented Sep 15, 2022

Hey @silkentrance, thank you for looking into it and making quick progress!

But why would you use vitest and in addition jest?

My situation is the reverse there. I already have a project using vite and vitest that gave us some excellent tools like their visual reporter and fast iteration cycle. With jest, I often needed to set up transpilation steps to make something work, and vitest was a breeze to not worry about that part.

If you mean for the workaround solution, the idea was to write tests with testdeck using jest and let vitest run that as it does have support for it. It is just an extra dependency - and compilation step - that would be nice to drop.

That being said, you might run into issues when using both @testdeck/jest and a future @testdeck/vitest at the same time while migrating your existing tests.

This should be fine on my end; I do not plan to have both of them loaded simultaneously. Luckily in my case, we split our codebase nicely with monorepo packages so we can progress package by package in small increments.

@panayot-cankov
Copy link

Hey @silkentrance

The isAsync only checks if the method isDoneCallbackAsync. I think you can rename isAsync to isDoneCallbackAsync or something among those lines, then make it a protected virtual method on the ClassTestUI and in the vitest implement it with isDoneCallbackAsync(method) { return false; } if done callbacks are deprecated.

The usage for the isAsync is to check if the class method has done argument, and if it does - to create a test function for the test runner that would return whatever the test method returns. In case of async class test methods, they will return a promise, that will be passed back to the test runner.

We currently support things like:

@suite class Hello {
  @test async world(): Promise<void> {
    await fetch(...):
  }
}

Thank you,

P.S.
I am a huge fan of moving from done callback to promises everywhere. If all test utilities now also start to utilize AbortController for test timouts and failures we will get good things like proper callstacks with test timeouts when working with selenium...

@silkentrance
Copy link
Member

As for the dropped done based async callback scheme: I have refactored the existing tests to just async and it seems to work just fine.

silkentrance added a commit that referenced this issue Sep 24, 2022
- bump version to v0.3.0
silkentrance added a commit that referenced this issue Sep 26, 2022
- bump version to v0.3.0
@silkentrance silkentrance mentioned this issue Oct 28, 2022
12 tasks
@silkentrance
Copy link
Member

@adaliszk released v0.3.0

@silkentrance
Copy link
Member

@adaliszk feel free to try it out an tell us your experiences in #321

@adaliszk
Copy link
Author

Thank you very much @silkentrance! I will be using it shortly in a few projects to gather feedback 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants