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

no test suite found when using vitest from global pnpm #2840

Closed
6 tasks done
scarf005 opened this issue Feb 8, 2023 · 13 comments
Closed
6 tasks done

no test suite found when using vitest from global pnpm #2840

scarf005 opened this issue Feb 8, 2023 · 13 comments

Comments

@scarf005
Copy link
Contributor

scarf005 commented Feb 8, 2023

Describe the bug

No test suite found error will be raised when using vitest from global pnpm and asdf dependency manager.

related issues: #847 #2604
however the issue keeps coming back even after they are closed.

Reproduction

due to the nature of the issue (global installation and asdf), minimal reproduction is provided in the form of shell script under docker.

  1. docker run -it ubuntu /bin/bash
  2. type along following commands:
apt-get update && apt-get install curl git -y

# intall asdf: https://asdf-vm.com/guide/getting-started.html
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.1
. ~/.asdf/asdf.sh

# install nodejs and pnpm
asdf plugin-add nodejs
asdf plugin-add pnpm
asdf install nodejs latest && asdf global nodejs latest
asdf install pnpm latest && asdf global pnpm latest

# setup pnpm
SHELL=/bin/bash pnpm setup
source /root/.bashrc

# install vitest globally
pnpm i -g vitest

# clone test repo
git clone https://github.com/zxch3n/vitest-ext-basic-example.git test
cd test
pnpm i

# make sure global vitest is used
which vitest #=> /root/.local/share/pnpm/vitest

# run vitest
vitest

which will result in:

root@c67ed93135ee:/test# vitest

 DEV  v0.28.4 /test

 ❯ add.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  add.test.ts [ add.test.ts ]
Error: No test suite found in file /test/add.test.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  no tests
   Start at  16:19:34
   Duration  382ms (transform 75ms, setup 0ms, collect 38ms, tests 0ms)


 FAIL  Tests failed. Watching for file changes...
       press h to show help, press q to quit

System Info

result of pnpm exec envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers from above docker container:

  System:
    OS: Linux 5.19 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (12) x64 AMD Ryzen 5 5600G with Radeon Graphics
    Memory: 17.93 GB / 30.70 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 19.6.0 - ~/.asdf/installs/nodejs/19.6.0/bin/node
    npm: 9.4.0 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    vite: ^2.9.9 => 2.9.15 
    vitest: ^0.12.6 => 0.12.10

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

Vitest resolves twice, if you use it globally. It's always better to run vitest via node script (scripts field in package.json)

@FedericoBiccheddu
Copy link

I have the same problem even if I use a script from the package.json. Tests were working before, but all of a suddenly they stopped working.

Having the following test:

import { describe, it, expect } from 'vitest';

describe('sum test', () => {
	it('adds 1 + 2 to equal 3', () => {
		expect(1 + 2).toBe(3);
	});
});

and launching the following script pnpm run test:watch which resolves to vitest --config ./config/vitest.ts watch:

 DEV  v0.28.4 /srv/app

 ❯ src/index.test.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/index.test.ts [ src/index.test.ts ]
Error: No test suite found in file /srv/app/src/index.test.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  no tests
   Start at  12:12:11
   Duration  2.91s (transform 2.02s, setup 0ms, collect 13ms, tests 0ms)

This is vitest.ts

import path from 'node:path'
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    cache: {
      dir: path.resolve('var', 'cache', 'vitest')
    },
    coverage: {
      reportsDirectory: path.resolve('var', 'coverage')
    },
    include: [
      path.resolve('src', '**', '*.spec.ts'),
      path.resolve('src', '**', '*.test.ts'),
    ],
    watch: false,
  },
})

System Info (with pnpm@7.27.0):

  System:
    OS: Linux 5.15 Alpine Linux
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 10.62 GB / 15.57 GB
    Container: Yes
    Shell: 1.35.0 - /bin/ash
  Binaries:
    Node: 18.13.0 - /usr/local/bin/node
  npmPackages:
    @vitest/coverage-c8: 0.28.4 => 0.28.4 
    vitest: 0.28.4 => 0.28.4 

@FedericoBiccheddu
Copy link

Downgrading to vitest@0.27.3 it works correctly.

@meduzen
Copy link
Contributor

meduzen commented Feb 10, 2023

I confirm I have the same issue: I switched from npm to pnpm, and v0.27.3 is working while v0.28.x gives the same error.

My project runs Vitest through package.json / scripts ("test": "vitest run").

@juanrgm
Copy link

juanrgm commented Mar 21, 2023

Same case here, it works with 0.27.3 but fails with 0.28.x and 0.29.x.

@yarinsa
Copy link

yarinsa commented Apr 18, 2023

Update:
I believe it related to the fact the the describe that is imported is imported from "another" module. Or redeclared. It can be resolved by using "globals: true" for the rest of vitest utils. And defining "describe" on the global.
I hope the maintainers will solve it soon
Screenshot 2023-04-18 at 17 49 05
Screenshot 2023-04-18 at 17 49 19

@bartektelec
Copy link

bartektelec commented Apr 22, 2023

Im having the same problem with one particular test,
deps:

		"vite": "4.2.2",
		"vitest": "0.30.1",
		"jsdom": "21.1.1",
		"zod": "3.20.2"

I'm using 0.30.1 and I've tried downgrading to 0.27.3, 0.28, 0.29.1, I also tried both npm and pnpm.

This only happens to a test where I'm trying to test a zod validator.
Eventhough the code is simple and I'm sure it works properly, the moment I try to assert the good answer it prompts "No test found in suite ...", but when I assert a wrong answer it will actually run the test and display what is wrong with it.

This happens no matter which matcher I use

expect(r.name === 'example').toEqual(true);
expect(r).toHaveProperty('name', 'example');
expect(r.name).toEqual('example');
expect(r.name).toBe('example');
expect(r).toEqual({name: 'example', age: 69});

See attached screenshots

image
image

@sheremet-va
Copy link
Member

Im having the same problem with one particular test, I'm using 0.30.1 and I've tried downgrading to 0.27.3, 0.28, 0.29.1, I also tried both npm and pnpm.

This only happens to a test where I'm trying to test a zod validator. Eventhough the code is simple and I'm sure it works properly, the moment I try to assert the good answer it prompts "No test found in suite ...", but when I assert a wrong answer it will actually run the test and display what is wrong with it.

This happens no matter which matcher I use

expect(r.name === 'example').toEqual(true);
expect(r).toHaveProperty('name', 'example');
expect(r.name).toEqual('example');
expect(r.name).toBe('example');
expect(r).toEqual({name: 'example', age: 69});

See attached screenshots

image image

Your tests should be inside „test“ or „it“ function to be considered tests.

@bartektelec
Copy link

Shoot that took me long time to try figure it out, thanks man 🙌

@space-nuko
Copy link

space-nuko commented May 16, 2023

Same error but I want to upgrade vitest so I can fix #3004, so I'm at a loss. Nothing changed about my tests, and even putting the minimal example in my test suite fails with No test suite found. I run vitest in package.json script

@sheremet-va
Copy link
Member

Same error but I want to upgrade vitest so I can fix #3004, so I'm at a loss. Nothing changed about my tests, and even putting the minimal example in my test suite fails. I run vitest in package.json script

Check you have the same version installed globally and inside a package

@space-nuko
Copy link

space-nuko commented May 16, 2023

I didn't have vitest installed globally, installed it and same error. I'm on 0.31.0 and vite 4.3.1, and use pnpm as my package manager everywhere

Downgrading to 0.27.3 works for me but the test stacktraces are incorrect

@sheremet-va
Copy link
Member

In the next version, Vitest will fail if it encounters a different Vitest instance (for reference #3301).

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

No branches or pull requests

8 participants