• Stars
    star
    308
  • Rank 131,216 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Debug your Vitest tests. Effortlessly. ๐Ÿงช๐Ÿ–ผโšก๏ธ

Vitest Preview Logo

Vitest Preview

Debug your Vitest tests. Effortlessly. ๐Ÿงช๐Ÿ–ผโšก๏ธ

Vitest Preview Demo

Try Vitest Preview Online. No downloads needed!

All Contributors

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

  • ๐Ÿ‘€ Visualize your testing UI in an external browser in milliseconds.
  • ๐Ÿ”„ Auto reloads the browser when debug() is executed.
  • ๐Ÿ’… Fully support CSS
  • ๐ŸŒ„ Support viewing images.

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):

Hung Viet Nguyen
Hung Viet Nguyen

๐Ÿ’ป
Andre
Andre

๐Ÿ’ก
Renรฉ Wang
Renรฉ Wang

๐ŸŒ

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.

More Repositories

1

jest-preview

Debug your Jest tests. Effortlessly.๐Ÿ› ๐Ÿ–ผ
TypeScript
2,297
star
2

react-linkedin-login-oauth2

Easily get Authorization Code from Linked In to log in without redirecting.
TypeScript
92
star
3

react-conferences

โš› Up-to-date and Comprehensive list of React Conferences Worldwide ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป
46
star
4

jest-with-vite

Setup Jest with Vite React โšก๏ธโš›๏ธ
JavaScript
20
star
5

know-your-stargazers

Know more about who starred your repository ๐Ÿ•ต๏ธ
JavaScript
16
star
6

netlify-plugin-playwright-cache

๐Ÿค– Persist the Playwright executable between Netlify builds
JavaScript
15
star
7

vite-react-template-redux

The unofficial Redux template for Vite React
JavaScript
13
star
8

courses-i-took

Courses I took to improve my technical knowledge and skills
11
star
9

react-linkedin-login-oauth2-demo

JavaScript
7
star
10

blockchain_demo

A very simple blockchain system written in Python
Python
7
star
11

cv

๐Ÿ’ผ Hung Nguyen's Resumรฉ. Powered by Nuxt and vue-notion
Vue
6
star
12

talk-with-dwarves-foundation

Slides for the talk "Visual debugging experience for your frontend tests" hosted by Techie Story x Dwarves Foundation x WeBuild
3
star
13

sample-chat-widget

Sample Chat Widget using styled-components https://sample-chat-widget.netlify.app/
JavaScript
2
star
14

trochuyenit.hung.dev

Vietnamese tech talk podcast. Hosted by nvh95.
JavaScript
2
star
15

nvh95

2
star
16

jsconf-korea2022

Slides for the talk "How I Got 1600 Stars on GitHub in 2 months of Open Source Work". Made with @slidevjs
JavaScript
2
star
17

msw-example

JavaScript
1
star
18

handbook

JavaScript
1
star
19

messenger-clone

Rebuild Messenger using styled-components and flexbox https://messenger-demo.netlify.app/
JavaScript
1
star
20

railway_fastapi

Python
1
star
21

demo-scripts

JavaScript
1
star
22

hieu-sketches

JavaScript
1
star
23

hung.dev

Hung Viet Nguyen's Blog
TypeScript
1
star
24

react-linkedin-login-oauth2-docs

JavaScript
1
star
25

blog

Gatsby starter for a Contentful project from the community.
JavaScript
1
star
26

gi-minihackathon-team2

Created with CodeSandbox
JavaScript
1
star