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

Vitest - Wallaby won't start with vitest.workspace.ts and a defineWorkspace config #3328

Closed
lsanwick opened this issue Feb 1, 2024 · 11 comments

Comments

@lsanwick
Copy link

lsanwick commented Feb 1, 2024

Issue description or question

Vitest: vitest/1.2.1 darwin-arm64 node-v20.9.0
Wallaby: v1.0.1520

I've been working on migrating from Jest to Vitest, but have been struggling to get Wallaby to work consistently after the migration.

I had to add this to my package.json to even get Wallaby to autodetect Vitest, I think because of the lack of a root-level vitest.config.ts:

  "wallaby": {
    "autoDetect": [
      "vitest"
    ]
  }

My project is a monorepo, so it's using Vitest's feature of having vitest.workspace.ts file in the root with defineWorkspace rather than a vitest.config.ts file. Everything is working and passing using yarn vitest at the root of the project, and I can get individual tests to run with Wallaby utilizing Smart Start. If I try to use Start with Wallaby it eventually fails with issues loading urls of files that definitely exist in one of the projects.

I've attached the diagnostics report below, any guidance would be helpful, thanks!

Wallaby diagnostics report

wallaby-diagnostic-report.txt

@smcenlly
Copy link
Member

smcenlly commented Feb 1, 2024

Based on your diagnostics report, it looks like you have a mono-repo clockwise with a number of projects underneath it in the src directory, and it looks like you are starting Wallaby on /clockwise/src/client-web.

For Vite projects, Wallaby needs to be started on the mono-repo root. If my assumption above is accurate, can you please try opening Wallaby on the clockwise root and then see if it starts correctly and runs your tests?

@lsanwick
Copy link
Author

lsanwick commented Feb 2, 2024

Sorry for the confusion, the /clockwise/src directory is just holding all of my repositories, the root of the project is at /client-web I have multiple packages under client-web, like /client-web/packages/webapp, /client-web/packages/gateway, etc.

@smcenlly
Copy link
Member

smcenlly commented Feb 5, 2024

From your diagnostics report, it looks like Vite / Wallaby is somehow not able to find:

  • /src/util/time-zone.ts
  • /src/config/devenv.ts
  • /src/util/ZonedMoment.ts
  • /src/util/time-zone.util.ts
  • /src/constants/help-center.ts

Are those files all part of a specific project? Where do those files live in relation to your project root?

Can you please try limiting which projects are included in your vitest.workspace.ts file to see if you can isolate the problem to a specific project?

I understand this may be difficult, but is it possible for you to create a reproducible sample for us?

@lsanwick
Copy link
Author

lsanwick commented Feb 6, 2024

I think there is actually an issue that has just been fixed in Vitest that might be causing this problem! I'll retest with that change and see if I'm still having issues.

@lsanwick
Copy link
Author

lsanwick commented Feb 6, 2024

Okay, after testing, that has no effect, as it's just isolated to the JUnit reporter. I'll investigate if there's a particular project that's causing the problem.

@lsanwick
Copy link
Author

lsanwick commented Feb 7, 2024

@smcenlly Okay, I've tried to make a reproduction repo for the issue, but I'm not even getting to the missing files part. I can inconsistently get Wallaby to start, but most of the time it's failing with the errors described in the README here: https://github.com/lsanwick/vitest-wallaby-workspace-issue/tree/main

@smcenlly
Copy link
Member

smcenlly commented Feb 7, 2024

Thank you for the sample repo. I'm not sure we would have been able to work out why it was failing without it.

When Wallaby runs your vite project, it has to first spawn a separate process to get your vite configuration before starting to run your tests.

For some reason, for your project this was failing (we could reproduce your problem). We've updated Wallaby to have a more robust mechanism for communicating your configuration from the spawned process.

It should now work for you in Wallaby core v1.0.1524. If you're still having problems, please let us know.

@lsanwick
Copy link
Author

lsanwick commented Feb 7, 2024

Thanks for the help @smcenlly! I've progressed a little further in the investigation.

If I set up my vitest.workspaces.ts to be like so:

import { defineWorkspace } from "vitest/config";

export default defineWorkspace(["packages/client-commons"]);

or like:

import { defineWorkspace } from "vitest/config";

export default defineWorkspace(["packages/web-commons"]);

Wallaby manages to run without issues.

If I include both packages, like so:

import { defineWorkspace } from "vitest/config";

export default defineWorkspace(["packages/client-commons", "packages/web-commons"]);

Then I start getting the missing files errors.

All of the files listed appear to be ones that incorrectly resolved imports for @clockwise/client-commons from @clockwise/web-commons, e.g. import { getTimeZoneGuess } from "@clockwise/client-commons/src/util/time-zone"; results in an error for Error: Failed to load url /src/util/time-zone.ts (resolved id: /src/util/time-zone.ts). Does the file exist?.

This is doubly strange because there are far more imports from client-commons than just those couple files in the error logs in web-commons, but the others don't seem to produce errors, or we aren't reaching them for some reason.

@smcenlly
Copy link
Member

smcenlly commented Feb 8, 2024

@lsanwick - are you able to update your sample repo to break in the same way so that we can try and work out what's going on?

@lsanwick
Copy link
Author

Luke Sanwick - are you able to update your sample repo to break in the same way so that we can try and work out what's going on?

I haven't been able to get it to reproduce the issue there, I will keep working on it this week.

@smcenlly
Copy link
Member

smcenlly commented Mar 3, 2024

I'm going to close this issue for now as we haven't heard back. If/when you reply with a sample repo, we'll re-open.

@smcenlly smcenlly closed this as completed Mar 3, 2024
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

No branches or pull requests

2 participants