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

Configuration - test.outputFile adds a second output file instead of overriding #7204

Closed
6 tasks done
24dlong opened this issue Jan 10, 2025 · 4 comments
Closed
6 tasks done

Comments

@24dlong
Copy link

24dlong commented Jan 10, 2025

Describe the bug

I'm attempting to update the test results output directory by updating the test.outputFile attribute in my vite.config.js file. but instead of changing where the results file is created, it seems to just create a second results file at the specified location.

The default setting seems to be to create the results file in the node_modules directory, and I'm using Yarn PnP on this project. Since node_modules doesn't exist with Yarn PnP, it's annoying that vitest keeps adding one to my project. This unfortunately also seems to confuse some of my plugins, which then start expecting dependencies to be installed in the node_modules directory since it exists.

My vite.config.js is below.

import { defineConfig } from 'vitest/config';

const libraryName = "library";

export default defineConfig({
    build: {
        lib: {
            entry: "lib/main.ts", // Your library's entry point
            name: libraryName, // Global variable name for UMD builds
            fileName: (format) => `${libraryName}.${format}.js`,
        },
        outDir: 'dist',    
    },
    test: {
        coverage: {
            provider: "v8", // or 'istanbul'
            include: ["lib/**/*.ts"],
            reporter: ['text'],
        },
        reporters: ["json"],
        outputFile: './my-custom-results-dir/results.json'
    },
});

Reproduction

  1. Pull down this repository: https://github.com/24dlong/cookiecutter-typescript-library
  2. Run yarn install
  3. Run yarn test
  4. See the two sets of directories created and two results.json files created.

System Info

System:
    OS: macOS 14.3.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.18 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.11.0 - /opt/homebrew/opt/node@22/bin/node
    Yarn: 4.6.0 - /opt/homebrew/opt/node@22/bin/yarn
    npm: 10.9.0 - /opt/homebrew/opt/node@22/bin/npm
    Watchman: 2024.11.18.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 17.3.1

Used Package Manager

yarn

Validations

@hi-ogawa
Copy link
Contributor

.vitest/results.json and test.outputFile are entirely different. You can control where .vitest/results.json is created by cacheDir config.
https://stackblitz.com/edit/vitest-dev-vitest-askcupbs?file=vite.config.ts

export default defineConfig({
  cacheDir: 'my-cache-dir',
});

@24dlong
Copy link
Author

24dlong commented Jan 10, 2025

Hi @hi-ogawa - thank you for taking a look.

I'm not trying to update the location of the cache directory, .vitest is just what I decided to name the new directory I wanted to store my test results in (it could've been named anything). Perhaps I should've picked a different name if .vitest is already being used for storing the cache

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 10, 2025

I think you are confused about the purpose of node_modules/.vite/vitest/results.json. That's not our json reporter output, but it's our test cache file. In order to change the location of cache file, you can use cacheDir. The one in outputFile is the actual user facing json reporter output.

@24dlong
Copy link
Author

24dlong commented Jan 10, 2025

Ah, I see. Thank you @hi-ogawa. I will supply a custom directory for this one as well

@24dlong 24dlong closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants