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

Tests not found when using in-source testing and browser mode #6430

Closed
6 tasks done
jtmthf opened this issue Aug 31, 2024 · 0 comments · Fixed by #6440
Closed
6 tasks done

Tests not found when using in-source testing and browser mode #6430

jtmthf opened this issue Aug 31, 2024 · 0 comments · Fixed by #6440
Labels
feat: browser Issues and PRs related to the browser runner p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@jtmthf
Copy link

jtmthf commented Aug 31, 2024

Describe the bug

When using in-source testing and browser mode together, tests fail with the error of "No test suite found in file". With an external file, the tests are found and succeed. When browser mode is disabled, the tests are found but fail due to relying on browser features. Below is the test source.

if (import.meta.vitest) {
  const { test, expect } = import.meta.vitest;

  test("button click updates count", async () => {
    const { act, render, screen } = await import("@testing-library/react");
    const { userEvent } = await import("@vitest/browser/context");

    render(<App />);

    const button = screen.getByRole("button");

    await act(async () => {
      await userEvent.click(button);
    });

    expect(button).toHaveTextContent("count is 1");
  });
}

Reproduction

https://github.com/jtmthf/vitest-in-source-browser

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M2
    Memory: 80.78 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.local/state/fnm_multishells/98308_1725115559526/bin/node
    Yarn: 1.22.19 - ~/.local/state/fnm_multishells/98308_1725115559526/bin/yarn
    npm: 10.2.3 - ~/.local/state/fnm_multishells/98308_1725115559526/bin/npm
    pnpm: 9.4.0 - ~/.local/state/fnm_multishells/98308_1725115559526/bin/pnpm
  Browsers:
    Chrome: 128.0.6613.86
    Chrome Canary: 106.0.5249.3
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1 
    @vitest/browser: ^2.0.5 => 2.0.5 
    vite: ^5.4.1 => 5.4.2 
    vitest: ^2.0.5 => 2.0.5

Used Package Manager

pnpm

Validations

@sheremet-va sheremet-va added feat: browser Issues and PRs related to the browser runner p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels Sep 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p4-important Violate documented behavior or significantly improves performance (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants