vscode icon indicating copy to clipboard operation
vscode copied to clipboard

React is not defined

Open juanruben opened this issue 3 years ago • 2 comments

Describe the bug In a very simple test for a component I keep getting React is not defined

To Reproduce Run test in the UI for a component

Expected behavior Run test successfully. The plugin works ok with non react tests. The react tests run without any issue in the console.

Screenshots Screen Shot 2022-08-22 at 7 14 46 PM

Environment

  • OS: macOS
  • VSCode version: 1.70.2
  • Vitest version: 0.22.1
  • Vitest plugin version: 0.2.24

juanruben avatar Aug 22 '22 23:08 juanruben

Probably related to #13, but with my example it'll work fine until monorepo is supported.

If you have a monorepo, the command should be started with the help of your package manager. Here is an example with npm:

"vitest.commandLine": "npm -w @monorepo/package-name test --"

Put this line in .vscode/settings.json and it should work. Can't give yarn/pnpm examples but it's the same for all.

Also the package's package.json should contain the script you are calling, in this case is test:

"scripts": {
    "test": "vitest",
}

Pustinyak avatar Aug 30 '22 05:08 Pustinyak

Probably related to #13, but with my example it'll work fine until monorepo is supported.

If you have a monorepo, the command should be started with the help of your package manager. Here is an example with npm:

"vitest.commandLine": "npm -w @monorepo/package-name test --"

Put this line in .vscode/settings.json and it should work. Can't give yarn/pnpm examples but it's the same for all.

Also the package's package.json should contain the script you are calling, in this case is test:

"scripts": {
    "test": "vitest",
}

@Pustinyak Thanks for the solution, I changed it a little bit for yarn, and works fine in one monorepo

"vitest.commandLine": "yarn workspace @monorepo/package-a test --watch" 

but I also have a package-b in this monorepo, vitest.commandLine is specific with package-a already,
I tried, it failed in package-b.

If you have any idea about this, please. Thanks in advance. Ken

gaokun avatar Sep 20 '22 03:09 gaokun

You can try using the vscode workspace to open folders that require different configs. Each folder can have its own .vscode settings.

zxch3n avatar Feb 08 '23 14:02 zxch3n