Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow export of UI including coverage #4760

Closed
4 tasks done
jacando-timo-zimmermann opened this issue Dec 15, 2023 · 5 comments · Fixed by #4717
Closed
4 tasks done

Allow export of UI including coverage #4760

jacando-timo-zimmermann opened this issue Dec 15, 2023 · 5 comments · Fixed by #4717

Comments

@jacando-timo-zimmermann

Clear and concise description of the problem

Running vitest --ui --coverage on my machine correctly opens the Vitest UI including the visual coverage. Running vitest run --coverage runs the tests once and creates the directories /html and /coverage. I want to put the results on a web server that serves static files. I copied the content of the /html folder on the webserver and it works well. However, unlike locally, it does not show the coverage, which makes sense since I didn't do anything with the /coverage folder. Running Vitest UI in watch mode on the server is not possible.

Suggested solution

I would like to see an export function that creates static files of the Vitest UI including the coverage that I can serve with a simple web server.

Alternative

No response

Additional context

Config:

export default defineConfig({
    plugins: [tsconfigPaths(), swc.vite()],
    test: {
        globals: true,
        environment: 'node',
        coverage: {
            provider: 'v8',
            reporter: ['text', 'lcov', 'clover', 'html', 'json'],
            reportsDirectory: 'coverage',
            all: true
        },
        reporters: ['default', 'html']
    },
    resolve: {
        alias: {
            '@': 'src'
        }
    }
});

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 16, 2023

I think this is a same issue as #4149.
I have a quick PR to support this just for a special case when coverage.reportsDirectory: 'html/coverage' #4717

@jacando-timo-zimmermann
Copy link
Author

Thank you @hi-ogawa, that's exactly what we need. Do you have a feeling until when we can see it being released?

@jacando-timo-zimmermann
Copy link
Author

@hi-ogawa @sheremet-va unfortunately, it still doesn't work with v1.1.0. This is my config:

// eslint-disable-next-line spaced-comment
/// <reference types="vitest" />

import swc from 'unplugin-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';

export default defineConfig({
    plugins: [tsconfigPaths(), swc.vite()],
    test: {
        globals: true,
        environment: 'node',
        coverage: {
            enabled: true,
            provider: 'v8',
            reporter: ['text', 'lcov', 'clover', 'html', 'json'],
            reportsDirectory: 'html/coverage',
            all: true
        },
        reporters: ['default', 'html']
    },
    resolve: {
        alias: {
            '@': 'src'
        }
    }
});

This is the command I run:

"test:cov": "vitest run --coverage"

This correctly creates an html and coverage folder. I then do:

$ cd html
$ npx http-server -g

I was expecting to see the coverage button in the menu in the top left, but it doesn't appear.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Dec 19, 2023

Hmm... not sure what went wrong. I just tested quickly on stackblitz and it seems working fine (except stackblitz initially opens __vitest__ which is 404):

https://stackblitz.com/edit/vitest-dev-vitest-g8ia47?file=vite.config.ts

screenshot

image

Just in case, could you check @vitest/ui is also upgraded to v1.1.0?

Also asset hash in html/assets should be exactly like this:

$ ls -lh html/assets
total 590.0K
-rw-r--r--  1  staff  staff  534.3K    12    20  07:55  index-O8DR2YZv.js    
-rw-r--r--  1  staff  staff   54.7K    12    20  07:55  index-z19Uws5U.css   

@jacando-timo-zimmermann
Copy link
Author

Updating @vitest/ui solved it. Thanks a lot! @hi-ogawa

@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants