Index of every page on this site: llms.txt
All skills
fubits1 avatar

/vitest

@a024d57
by Iljafubits1/svelte-skills11 stars
2
Run it yourself

Vitest test.projects, browser mode with playwright(), optimizeDeps, separate vitest.config from vite.config. Use when editing vitest config, debugging flaky browser tests, upgrading @vitest/*, or splitting node vs browser projects.

Use this Skill: https://skilld.dev/gh/fubits1/svelte-skills/vitest

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈60 tokens for metadata: the name and description. ≈1.7k when used: this file. ≈9.3k more on demand in 7 files.

Description uses 3.0% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈240 characters, or 3.0%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Vitest

Config

  • Docs: if unsure about an API, fetch https://vitest.dev/llms.txt. Do not guess
  • Config file: use vitest.config.{ts,mts,js,mjs} for test / test.projects. Vitest-only-in-vite.config merges badly with multiple projects and Storybook
  • Gate: no vitest.config.* but vite.config has test: (or no Vitest file), ask before adding projects or Storybook whether to introduce vitest.config.ts and move test out of Vite
  • Projects inherit the root (Vitest 5): inline test.projects get the root's plugins, resolve, optimizeDeps, and setupFiles; extends: false opts out. NEVER repeat an inherited root plugin inside a project: a second svelte() compiles components twice. Inheritance rules, sharedViteServer, tags: references/config-projects.md
  • Upgrade: bump all @vitest/* together. Vitest 4 to 5 breaking changes and post-upgrade cleanup: references/vitest-5-upgrade.md
  • browser.provider: import { playwright } from '@vitest/browser-playwright' to provider: playwright() (factory, not a string). Use import { page } from 'vitest/browser': not @vitest/browser/context
  • rune_outside_svelte: a rune "is only available inside .svelte and .svelte.js/ts files"; in browser mode, until the page has loaded Svelte's client runtime (a component, vitest-browser-svelte or an import from svelte itself, e.g. tick), a $state call shows ReferenceError: $state is not defined instead (the form in a node project is not covered here). Cause: the rune sits in a .js/.ts file without the .svelte. infix (foo.svelte.ts and foo.svelte.test.ts have it); rename it, update its imports, and for a test file check which project's include and exclude the new name matches. On Vite 8, a dependency's file must end in .svelte.js/.svelte.ts; report one that does not to the library. More in svelte-5:testing-svelte troubleshooting
  • optimizeDeps.exclude does not fix rune_outside_svelte on Vite 8: the file name decides whether vite-plugin-svelte compiles the runes, pre-bundled or not (pre-bundling uses Rolldown since Vite 8, esbuild before)
  • optimizeDeps.include: deps that trigger mid-test optimization (e.g. minisearch) to reduce flakes; once you list one msw entry point, list every one you import, or narrow frames with frame.protocol (svelte-5:msw). Symptoms, fixes and optimizeDeps.entries: references/flake-hygiene.md
  • Storybook: vitest.config.ts + storybookTest + browser playwright(): svelte-5:storybook-vitest, manual setup
  • Reports and coverage: file-reporter paths go in test.outputFile (reporter options beat the CLI; the HTML reporter takes outputDir); coverage thresholds take flat metric keys, a Jest-style global key enforces nothing: references/config-projects.md

Writing tests

  • Assertions: value, not presence. Presence-only assertions (toBeInTheDocument on a role-only or loose locator, not.toBe(''), toHaveBeenCalled) ship regressions; toBeInTheDocument on an exact-text locator checks a value. Every interaction test must compute an expected value from the action and assert equality. See references/assertions.md for the pattern, callback-payload rules, and how to tell a harness failure from a behavior failure
  • toHaveTextContent is exact (Vitest 5): full-string equality, no RegExp. toHaveTextContent('Error') fails on Error!. Partial or regex matches use toMatchTextContent, a weaker check: prefer the exact computed string when you can build it. In a Storybook play function, expect from storybook/test has jest-dom's toHaveTextContent, which matches substrings and RegExp: svelte-5:storybook-vitest
  • Locators match text exactly (Vitest 5): page.getByText('Hello') does not find Hello, World. Use the full text, a RegExp, or { exact: false }: references/browser-mode.md
  • Queries: accessible first, every escape hatch commented. Use page.getByRole(...), getByLabelText, getByText, getByPlaceholder, getByTitle, getByAltText first. They mirror how screen readers find elements and fail when a11y regresses. data-testid is an a11y smell (tkdodo, 2025): a testid means the element has no accessible name, role, or text for users of AT either. Fix the a11y hole, not the test. Reach for data-testid, a raw querySelector, or a test-id output div in a fixture only as a last resort: charting canvases, decorative content, third-party widgets without roles, an overlay that intercepts clicks on the real control, legacy markup you cannot change. Each use gets a one-line comment explaining why no accessible selector worked
  • vitest-browser-svelte v3: render is async-only (await render(...)); usage in svelte-5:testing-svelte. The main entry cleans up in beforeEach; /pure never cleans up. Don't use it.concurrent for browser component tests: expect.element breaks there: references/browser-mode.md
  • Viewport: the default is 414x896; call page.viewport(width, height) from vitest/browser for desktop layouts
  • Mocking: vi.mock / vi.hoisted at the top level only; reference module-level fakes in a factory via vi.hoisted or a top-level await import(); mock SvelteKit's $app/* in browser tests: references/mocking.md
  • Waiting: await expect.element(locator) for locators, expect.poll(() => value) or vi.waitFor for spies and other state (references/browser-mode.md). Negative assertions need a positive precondition and a settle window (references/flake-hygiene.md)
  • Visual regression: toMatchScreenshot(); baselines are platform-specific, so decide where they are generated before committing any: references/visual-regression.md

Before any green claim

Browser and Storybook suites are flaky on a single run. Kill the test-server port holder, clear node_modules/.vite and node_modules/.cache/storybook, then run three times: counts must match within ±0 tests and setup time within ±30%. If runs diverge, investigate the flake BEFORE claiming any fix works. Full protocol and flake patterns: references/flake-hygiene.md.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides configuration guidelines and best practices for Vitest, focusing on browser mode, Storybook integration, and robust assertion patterns. No security risks or malicious behaviors were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: MEDIUM · 1 issue

Signed by skilld at a024d57. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated last month
user-invocable
true
Other metadata
compatibility
Written for Vitest 5 (Node 22.12+, 24 or 26+; Vite >=6.4; factory browser provider, test.projects)

README badge

README badge for fubits1/svelte-skills/vitest