vitest-preview icon indicating copy to clipboard operation
vitest-preview copied to clipboard

No index.html previews after version 0.0.1

Open lutam opened this issue 2 months ago • 3 comments

Describe the bug

Hello,

we're experiencing a problem with the debug() functionality. It has stopped generating the index.html after 0.0.1

We upgraded from 0.0.1 to 0.0.3 and since then no index.html is being generated inside the .vitest-preview folder.

version 0.0.1: debug() has the index.html inside the .vitest-preview folder version 0.0.2 and 0.0.3: debug() doesnt have the index.html inside the .vitest-preview folder

Reproduce

vite.config.js

/// <reference types="vitest" />
/// <reference types="vite/client" />

// import react from '@vitejs/plugin-react';
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: "./src/setup-tests2.tsx",
    // Need to enable this to use with vitest-preview
    css: true,
  },
});

setup-test2.tsx

// Import global css to use with vitest-preview
import "./index.css";

import "@testing-library/jest-dom";

actual test

import { render, screen } from "@testing-library/react";
import { debug } from "vitest-preview";

describe("NOT A REAL TEST", () => {
  it("should render", () => {
    render(<div>Hello World</div>);

    debug();

    expect(screen.getByText("Hello World")).toBeInTheDocument();
  });
});

we expect this to create an html inside .vitest-preview but it's not. With version 0.0.1 the file index.html is there.

Environment (please complete the following information)

npm version: 10.9.0 node version: 23.1.0

relevant packages:

"dependencies": {
   ...
    "react": "18.3.1",
    "react-dom": "18.3.1",
    
    "react-router-dom": "7.9.3",
    
  },
  "devDependencies": {
    
    "@testing-library/jest-dom": "6.9.1",
    "@testing-library/react": "16.3.0",
    
    "@types/react": "18.3.25",
    "@types/react-dom": "18.3.7",
    
    "@vitejs/plugin-react-swc": "3.11.0",
    "@vitest/browser": "2.1.9",
   
    "vite-plugin-environment": "1.1.3",
    "vite-plugin-svgr": "4.5.0",
    "vitest": "2.1.9",
    "vitest-canvas-mock": "0.3.3",
    "vitest-preview": "0.0.X
  },

lutam avatar Oct 23 '25 11:10 lutam

Hi @lutam. It's actually an improvement. I moved the cache from .vitest-preview to OS's temporary directory in #41, so users do not need to manually add .vitest-preview to .gitignore.

Do you experience any bugs regarding this?

Also, can you share your use case for reading this HTML? We may add support to save snapshots to a specific location of users' choices.

nvh95 avatar Oct 28 '25 16:10 nvh95

hey @nvh95, I used to read this html directly so there was no need to run npx vitest-preview. the library is obviously very much useful even with no accessible html, but I think that being able to access the preview file would be nicer.

but you're right, this is not actually a bug.

lutam avatar Nov 03 '25 11:11 lutam

@lutam Thanks for your clarification. I will add an option to output it as a file in upcoming version and let you know.

nvh95 avatar Nov 03 '25 11:11 nvh95