Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vitest-preview

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-preview

Visual Debugging Experience for Vitest 🧪🖼⚡️

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25K
increased by6.48%
Maintainers
1
Weekly downloads
 
Created
Source

Vitest Preview Logo

Vitest Preview

Debug your Vitest tests. Effortlessly. 🧪🖼⚡️

Vitest Preview Demo

Try Vitest Preview Online. No downloads needed!

npm version PRs Welcome

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

Contributing

Please see the contribution guide at CONTRIBUTING.md.

Is there a similar library for Jest

Yes, it is. It's Jest Preview.

License

This is open source software

MIT

Support

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

Keywords

FAQs

Package last updated on 23 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc