Home

Awesome

<p align="center"> <img align="center" alt="Vitest Preview Logo" src="https://user-images.githubusercontent.com/8603085/197406675-dbe5b555-3a71-4c6d-9547-776c18052881.svg" width="120"/> </p> <h1 align="center"> <a href="https://www.vitest-preview.com" target="_blank" >Vitest Preview</a> </h1> <p align="center"> Debug your Vitest tests. Effortlessly. 🧪🖼⚡️ </p> <p align="center"> <img align="center" src="https://user-images.githubusercontent.com/8603085/197373376-f6a3fe33-487b-4c35-8085-8e7e6357ce40.gif" alt="Vitest Preview Demo" /> </p> <p align="center"> <a href="https://stackblitz.com/edit/vitest-preview?file=src%2FApp.test.tsx,README.md" title="Try Vitest Preview Now" target="_blank">Try Vitest Preview Online</a>. No downloads needed! </p> <!-- prettier-ignore-start --> <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END --> <!-- prettier-ignore-end -->

npm version Best of JS PRs Welcome Mentioned in Awesome Jest

Try Vitest Preview now

Why vitest-preview

When writing tests, we usually have to debug by reading the cryptic HTML output on the terminal. Sometimes, they are too complicated to visualize the UI in our heads. vitest-preview previews your Vitest tests right in a browser, then you can see your actual UI visually. You can write tests and watch rendered output changes accordingly. Vitest Preview lets you concentrate on tests in the "real world" rather than deciphering HTML code.

vitest-preview is built on top of Vite, it's blazing fast and easy to use.

vitest-preview is a younger sibling of jest-preview with the same idea and to solve the same problem. If you are writing tests using Jest, give it a try.

Features

Installation

npm install --save-dev vitest-preview
# Or
yarn add -D vitest-preview
pnpm add -D vitest-preview

Configuration

Process CSS

You need to configure vitest to process CSS by:

// vite.config.js
export default defineConfig({
  test: {
+    css: true,
  },
});

You might want to import your CSS global files in setupFiles:

// vite.config.js
export default defineConfig({
  test: {
+    setupFiles: './src/test/setup.ts',
  },
});

// src/test/setup.ts
+import './global.css';
+import '@your-design-system/css/dist/index.min.css';
+import 'bootstrap/dist/css/bootstrap.min.css';

Add script vitest-preview

vitest-preview has a CLI that opens Vitest Preview Dashboard where you can preview your tests' UI. You can update your package.json to add a script for more convenience:

"scripts": {
  "vitest-preview": "vitest-preview"
},

Update .gitignore

Update your .gitignore

// .gitignore
+.vitest-preview

Usage

Put debug() wherever you want to see the UI in your tests.

+import { debug } from 'vitest-preview';

describe('App', () => {
  it('should work as expected', () => {
    render(<App />);
+    debug();
  });
});

Open the Vitest Preview Dashboard by running the CLI command (updated in Configuration):

npm run vitest-preview
# Or
yarn vitest-preview
pnpm vitest-preview

Then execute your tests that contain debug(). You will see the UI of your tests at http://localhost:5006.

Examples

Is there a similar library for Jest

Yes, it is. It's Jest Preview.

Star history

Star History Chart

Contributing

Please see the contribution guide at CONTRIBUTING.md.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://hung.dev"><img src="https://avatars.githubusercontent.com/u/8603085?v=4?s=100" width="100px;" alt="Hung Viet Nguyen"/><br /><sub><b>Hung Viet Nguyen</b></sub></a><br /><a href="https://github.com/nvh95/vitest-preview/commits?author=nvh95" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/KatFishSnake"><img src="https://avatars.githubusercontent.com/u/12003520?v=4?s=100" width="100px;" alt="Andre"/><br /><sub><b>Andre</b></sub></a><br /><a href="#example-KatFishSnake" title="Examples">💡</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/RiverTwilight"><img src="https://avatars.githubusercontent.com/u/52880665?v=4?s=100" width="100px;" alt="René Wang"/><br /><sub><b>René Wang</b></sub></a><br /><a href="#translation-RiverTwilight" title="Translation">🌍</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This is open source software

MIT

Support

If you like the project, please consider supporting it by giving a ⭐️ to encourage the author.

<!-- TODO: Write a GitHub Actions to sync with root readme -->