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 Runs Tests in node_modules, despite node_modules being excludedI #5943

Closed
6 tasks done
jwalkerinterpres opened this issue Jun 20, 2024 · 1 comment
Closed
6 tasks done

Comments

@jwalkerinterpres
Copy link

Describe the bug

I have the following test section in my vite.config.ts (the "exclude" section is the key part):

  test: {
      environment: 'jsdom',
      exclude: ['e2e/*', 'node_modules/*'],
      globals: true,
      // Fix for React Testing Library + Vite Test
      // @see https://stackoverflow.com/questions/77611978/invalid-chai-property-in-vitest
      setupFiles: ['./setupTests.ts']
      // The above just does: import '@testing-library/jest-dom';
  },

However, despite the above exclude, tests in my e2e and node_modules folders are run.

Example Tests (from excluded folders):

 ❯ e2e/tests/aichat.spec.ts (0)
 ❯ e2e/tests/campaigns.spec.ts (0)
 ❯ e2e/tests/techniques.spec.ts (0)
 ❯ node_modules/graphiql/src/components/__tests__/GraphiQL.spec
.tsx (31)

Example failure (originating in node_modules)

    at StorageContextProvider (file:///Users/jeremywalker/new-ui/interpres-new-ui/node_modules/@graphiql/react/dist/index.mjs:42:13)
    at GraphiQLProvider (file:///Users/jeremywalker/new-ui/interpres-new-ui/node_modules/@graphiql/react/dist/index.mjs:2893:13)
    at GraphiQL (/Users/jeremywalker/new-ui/interpres-new-ui/node_modules/graphiql/src/components/GraphiQL.tsx:18:3)
..

(There are lots more of the above.)

Clearly:

  exclude: ['e2e/*', 'node_modules/*'],

is not being applied.

Reproduction

Since this doesn't seem to have anything to do with my test files (the whole problem is that it's runing files besides mine), and I've provided my vite config, I'm not sure what else I can offer to help with reproduction, but I'd be happy to provide anything else.

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 273.34 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.2.0 - /usr/local/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 126.0.6478.62
    Edge: 126.0.2592.61
    Safari: 17.5
  npmPackages:
    @vitejs/plugin-react: ^4.2.0 => 4.2.0 
    @vitest/coverage-v8: ^0.34.6 => 0.34.6 
    vite: ^5.0.3 => 5.0.3 
    vitest: ^0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Jun 20, 2024

However, despite the above exclude, tests in my e2e and node_modules folders are run.

You have an error in you configuration. node_modules/* excludes only files in the first level - https://www.digitalocean.com/community/tools/glob?comments=true&glob=node_modules%2F%2A&matches=false&tests=node_modules%2Fgraphiql%2Fsrc%2Fcomponents%2F__tests__%2FGraphiQL.spec.

When **, the "globstar", is used it matches zero or more directories and subdirectories. This allows for recursive directory searching easily.

Default pattern correctly excludes node_modules: https://vitest.dev/config/#exclude

['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**', '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*']

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2024
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