testing-library / svelte-testing-library

:chipmunk: Simple and complete Svelte DOM testing utilities that encourage good testing practices
https://testing-library.com/docs/svelte-testing-library/intro
MIT License
608 stars 34 forks source link

Feature proposal: Vite plugin #359

Closed mcous closed 2 months ago

mcous commented 2 months ago

Overview

This library requires three bits of setup to work correctly with Vitest

  1. Browser bundle resolution
  2. Testing library cleanup
  3. jest-dom matchers (optional, but pretty much everyone wants it)

Setting these up is a bit fiddly and results in inbound issues in this repository

Proposal

The most effective method at resolving (1) appears to be setting up a simple Vite plugin. A Vite plugin would also be capable of configuring (2) and maybe even (3). I think we should add a Vite plugin as an export to this library.

Usage (e.g. with SvelteKit)

// vite.config.ts
import { defineConfig } from 'vite'
import { svelteTesting } from '@testing-library/svelte/vite-plugin'
import { svelteKit } from '@sveltejs/kit/vite'

export default defineConfig({
  plugins: [svelteKit(), svelteTesting()],
})
// @testing-library/svelte/vite-plugin
export const svelteTesting = ({
  resolveBrowser = true,
  autoCleanup = true,
  extendExpect = true,
}) => ...

Related issues

github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 5.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: