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

vitest broken at version 2.32.0 #292

Closed
jthr-sbab opened this issue Oct 11, 2023 · 9 comments
Closed

vitest broken at version 2.32.0 #292

jthr-sbab opened this issue Oct 11, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@jthr-sbab
Copy link

Hi,

I run a vite-project with vitest for testing.
I've done no config for either project in the knip.ts and it all works fine at version 2.31.0.
But when I updated to version 2.32.0 (or newer) it list my test-files as unused.
I see that u done some kind of refactoring for vitest in that version and maybe you broke something.

Br

@jthr-sbab jthr-sbab added the bug Something isn't working label Oct 11, 2023
@webpro
Copy link
Collaborator

webpro commented Oct 11, 2023

Can you share more details? What does the Knip config look like? And the Vitest config? Is this in a public repo I can take a look at?

@birtles
Copy link
Contributor

birtles commented Oct 12, 2023

I'm likewise struggling to upgrade to 2.32.0. Everything works with 2.31.0 but as of 2.32.0 I get 112 issues. I'm not sure if it's related to this because I'm still having a very hard time trying to narrow down what changed. I've compared the debug output from both versions but haven't gotten any clues yet.

My knip config and failure log if it's of any interest.

@jthr-sbab
Copy link
Author

jthr-sbab commented Oct 12, 2023

Knip.ts:


const config: KnipConfig = {
  workspaces: {
    ".": {
      husky: {
        config: [".husky/pre-commit"],
      },
    },
    frontend: {
      entry: ["src/index.tsx", "src/testUtils.tsx"],
      ignore: [
        "src/generated/graphql.ts",
        "src/react-app-env.d.ts",
        "src/GraphQLFetcher.ts",
        "**/pact",
        "**/public/*.js",
      ],
    },
    backend: {
      entry: ["src/index.js"],
      project: ["src/**/*.js"],
    },
  },
};

export default config;

vitest.config.ts:

import { defineConfig, mergeConfig } from 'vitest/config';
import viteConfig from './vite.config';

export default defineConfig((configEnv) =>
    mergeConfig(
        viteConfig(configEnv),
        defineConfig({
            test: {
                environment: 'jsdom',
                globals: true,
                include: ['**/*.test.{ts,tsx}'],
                setupFiles: ['./src/setupTests.tsx'],
                mockReset: true, 
                coverage: {
                    provider: 'v8',
                    all: true,
                    include: ['src'],
                    exclude: [
                        '**/*.test.*',
                        '**/*.d.ts',
                        '**/types',
                        '**/*.pact.ts',
                        '**/queries/*',
                        '**/testUtils.tsx',
                        '**/setupTests.tsx',
                        '**/pactUtils.ts'
                    ],
                    reporter: ['text', 'json', 'lcov', 'html']
                }
            }
        })
    )
);

vite.config.ts:

/// <reference types="vitest" />
import react from '@vitejs/plugin-react-swc';
import path from 'path';
import { defineConfig } from 'vite';
import svgr from 'vite-plugin-svgr';
import checker from 'vite-plugin-checker';

export default defineConfig(() => {
    return {
        root: './',
        server: {
            proxy: {
                '/api': {
                    target: 'http://localhost:5000',
                    changeOrigin: true,
                    cookieDomainRewrite: ''
                }
            }
        },
        plugins: [
            react({ plugins: [['@swc/plugin-styled-components', {}]] }),
            svgr(), 
            checker({
                typescript: true
            })
        ]
    };
});

@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

I've pushed a few fixes in v2.33.2, can you please try that and see whether the issues are fixed?

Either way, please use code blocks (surround with three backticks) to share your configurations here.

@jthr-sbab
Copy link
Author

jthr-sbab commented Oct 12, 2023

Did not solve my problem. :S
And sorry about the format, I just used the buttons in the editor.

@webpro webpro closed this as completed in 432a308 Oct 12, 2023
@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

🚀 This issue has been resolved in v2.33.3. See Release 2.33.3 for release notes.

@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

This might fix it, but not 100% sure since I haven't seen a good reproduction.

@jthr-sbab
Copy link
Author

Solved it! Thanks so much, I really worship the work you do!

@webpro
Copy link
Collaborator

webpro commented Oct 12, 2023

In that case, to be fair, the Vitest plugin wasn't really working at all in your case, it didn't return any dependencies. I didn't know the Vitest config could be a function. So that's fixed now. But since the test file patterns were a global Knip thing before, it may have seemed to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants