linux-china / vitest-jetbrains-plugin Goto Github PK
View Code? Open in Web Editor NEWVitest JetBrains plugin
Home Page: https://plugins.jetbrains.com/plugin/19220-vitest-runner
License: Apache License 2.0
Vitest JetBrains plugin
Home Page: https://plugins.jetbrains.com/plugin/19220-vitest-runner
License: Apache License 2.0
If I have a test case with name prefixes strings that don't have the prefix yet
for example, and then click on run single test button on that test, vitest will quit with
filter: have, the, prefix, yet packages/web-app/src/shared/helpers/routeHelper.test.ts
include: **/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**
watch exclude: **/node_modules/**, **/dist/**
No test files found, exiting with code 1
I assume ' symbol messes up command line arguments somewhere. Why are they not wrapped and is it possible to wrap them, so I don't have to change my test names?
IMPORTANT: It's only when I use the plugin and click on the icon to run the tests. When I run them in the terminal, all is fine.
I wanted to add some extra info in the description, e.g.:
describe('foo (bar / baz)', () => ...)
When I run it, the whole suite (and tests in it) are skipped.
When if the description contains only (/
it does not run.
import { describe, it, expect } from 'vitest';
describe("Anything (/)", () => {
it("should not be skipped", () => {
expect(1).toEqual(2); // <-- it will not fail as the whole suit is skipped
});
});
describe("It can have more text in it (like/this)", () => {
it("should not be skipped", () => {
expect(1).toEqual(2); // <-- it will not fail as the whole suit is skipped
});
});
import { describe, it, expect } from 'vitest';
describe("Anything (/", () => {
it("should run this test", () => {
expect(1).toEqual(2); // <-- it will not fail as the whole suit is not run
});
});
In IntelliJ (or Webstorm), it is possible to debug Jest tests by choosing the debug option from the dropdown menu. This allows you to set breakpoints, step through the code, etc.
Would it be possible to support debugging for Vitest tests?
/usr/bin/pnpm exec -- vitest -t handleError src/foo.spec.ts
ERROR The "pnpm exec" command currently only works with the "-r" option
Plugin version: 0.6.3
pnpm version: 5.18.10
Hey @linux-china
First of all, a huge thank you for this marvelous plugin.
In monorepos the cli don't run in the workspace directory but in the root which creates some issues. It's stange because when looking at the code it should actually work: https://github.com/linux-china/vitest-jetbrains-plugin/blob/main/src/main/kotlin/com/github/linuxchina/jetbrains/plugins/vitest/VitestBaseRunLineMarkerProvider.kt#L62
I'm using latest PhpStorm 2022.2.1 with latest vitest plugin.
Tested on this repo: https://github.com/belgattitude/nextjs-monorepo-example.
.
├── apps
│ └── nextjs-app
│ ├── next.config.mjs
│ ├── package.json
│ ├── tsconfig.json
│ └── vitest.config.ts ## CONFIG FOR NEXTJS_APP WORKSPACE
│
├── packages
│ ├── core-lib
│ │ ├── src/
│ │ ├── CHANGELOG.md
│ │ ├── package.json
│ │ └── tsconfig.json
│ │ └── vitest.config.json ## CONFIG FOR CORE_LIB WORKSPACE
│ └── ui-lib
├── .yarnrc.yml
└── package.json
Is it an issue on your side too ?
PS: a picture
When running the same command from the cli but in the workspace folder, it works
cd packages/core-lib/
/home/sebastien/.nvm/versions/node/v16.17.0/bin/yarn exec -- vitest -t usePromise packages/core-lib/src/hooks/__tests__/use-promise.test.tsx
I have not tested this plugin at all but want ask you first, is it can run at debug mode or any plan to do it rn?, if so, the plugin so desirable
Hi,
I just installed the plugin in IntelliJ-Ultimate 2021.3.3 and restarted the idea.
I open up a index.test.tsx
or index.spec.tsx
but I only see the cypress and jest options to run the test.
The icons as shown in the screenshot do not present themselves, and the run configuration does not show an entry for vitest either. I've tried both version 0.2.1 and 0.2.2 of the plugin.
Am I maybe missing a configuration step?
Gerard.
Running npm exec -- vitest run -t test tests/Frontend/Views/HelloWorld.spec.ts
works fine as shown below.
But when I try to run through the green arrow in the gutter, I get the following error:
"CMD.EXE was started with the above path as the current directory."
The command also being run is npm.cmd exec ...
instead of npm exec ...
I'm using the latest version of Vitest Runner (0.6.1) and on PhpStorm 2022.1
We want to be able to support the way vitest is introduced globally
希望支持全局vitest的方式
vite.config.ts
/// <reference types="vitest" />
/// <reference types="vitest/globals" />
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
test: {
environment: 'jsdom',
globals: true,
},
})
We should add the cts
and mts
extensions, here the commit removing both extensions on my PR: 988b50f
It seems Vite
is adding them again, here the PR on Vitest
: https://github.com/vitest-dev/vitest/pull/1540/files
Hey,
thank you for your great work on this. I really like the plugin, however we have a repository that has the frontend-code under /frontend which the plugin does not respect when searching for the node_modules/vitest/vitest.mjs file.
In this case we manually have to add the right directory in the generated config.
When using Yarn 3 package manager with PnP there is no nodes_modules
so there is the following error when clicking the vitest icons in IDE
Error running 'vitest -t 'Top bar' src/components/__tests__/the-top-bar.spec.test.ts'
Cannot run program "node_modules/.bin/vitest" (in directory "/home/rom1/Projects/daia-ihm"): error=2, No such file or directory
Hi, thank you so much for this
I am reading .env.test
files in my tests like this in vitest.config.ts
:
import { defineConfig, loadEnv } from "vite"
// noinspection JSUnusedGlobalSymbols
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "")
Object.assign(process.env, env)
return {}
})
but my env vars are not loaded when running vitest
with this plugin
Any help appreciated
export default defineConfig({
test: {
+ // cause an exception to trigger
+ include: ['./playground/**/*.spec.[tj]s'],
testTimeout: timeout,
hookTimeout: timeout,
globals: true,
reporters: 'dot',
},
esbuild: {
target: 'node14'
}
})
npm exec -- vitest run -t test1 __tests__/auto-script-jsx.spec.js
RUN v0.18.1 E:/Desktop/Task/07-cdp-cfe/xzq-vite-plugins/playground/auto-script
-jsx
filter: __tests__/auto-script-jsx.spec.js
include: ./playground/**/*.spec.[tj]s
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,out
put,temp}/**
watch exclude: **/node_modules/**, **/dist/**
No test files found, exiting with code 1
Hello!
I see an error when I have backtics inside the it()
section and I want to run just one test:
it('should allow to use backticks `here`', () => {
// test code
});
As a workaround I need to run whole describe()
section (where I'm not using backticks)
npm exec -- vitest run -t "should allow to use backticks `here" src/my-test.tsx
sh: -c: line 0: unexpected EOF while looking for matching ``'
sh: -c: line 1: syntax error: unexpected end of file
Process finished with exit code 2.
In PhpStorm 2023.1 I get an incompatibility warning:
Incompatible: requires IDE build 223.* or earlier
Can you add support for 2023.1?
Hi,
is it possible to support node version 14.x as well with this plugin?
We would love to use this plugin, but cannot easily upgrade our node version yet.
The issue is currently, that your plugin runs the tests as:
npm exec -- vitest run -t "Require Test" tests/unit/main.spec.ts
Which fails with under nodejs v.14:
Usage: npm
where is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview
The working version for node v.14 would be:
npx vitest run -t "Require Test" tests/unit/main.spec.ts
Can you please add support for this?
This plugin uses the system node js interpreter and does not utilize the project-configured nodejs interpreter. Thus, when my system is version 12 (other projects I work on demand it), vitest will not run as it requires at least 14 (which I have configured in my webstorm project configuration).
The jetbrains plugin marketplace versions show 0.6.6 available but there is no corresponding branch/ tag on repository.
Can you please push/ link source where that is?
Hello, for some reason the icons to start the tests are only displayed in .js and .jsx files. My setup looks like this:
vite.config.js:
test: { globals: true, },
tsconfig.json:
"compilerOptions": { "types": [ "vitest/globals"] }, "include": [ "src", "node_modules/vitest/globals.d.ts" ]
I am trying to migrate tests from jest to vitest. For all of my tests I need to use UTC timezone. Currently, I was able to achieve it by TZ=UTC
in package.json
(refer: vitest-dev/vitest#1575 (comment)).
"scripts": {
"dev": "vite",
"serve": "vite preview",
"build": "vite build",
"test": "TZ=UTC vitest run",
"test:watch": "TZ=UTC vitest"
}
My all the tests pass successfully when I am running the tests from CLI by using npm test
. But when it comes to run tests from intellij looks like the tests aren't picking the timezone information from package.json
. Is it expected behaviour?
I am using v0.6.6 of vitest runner and IntelliJ IDEA 2022.2.3.
I'm using Vitest with Remix.
In Remix, you should use the $
in the file name to define variables in the URLs.
My files files are called for example: posts.$postId.tsx
. So, my test files are called posts.$postId.test.tsx
With that file name, I become the following error:
filter: app/routes/posts..test.tsx
include: **/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**
watch exclude: **/node_modules/**, **/dist/**
No test files found, exiting with code 1
As a workaround, I renamed my test file to posts.test.tsx
I believe this can be fixed to avoid the workaround
Great project!
Currently, on every project on WebStorm, I have the vitest gutter icons in the test even for projects that not using vitest
First, thanks so much for the plugin...do you know how it could be tweaked to run the tests in debug mode?
Thanks!
there is error below.
Error running 'vitest run -t 'foo' packages/bar/test/codegen.spec.ts': Cannot run program "node_modules/.bin/vitest" (in directory error=2, No such file or director
Thanks for the plugin!
With jest we were able to provide a custom configuration file and custom arguments in the Run/Debug configurations.
The use-case is that we would like to have two different vitest configs, one for unit tests and one for integration tests as they do different things (e.g. integration tests need more global setup + longer test timeouts + other things).
Is it possible to support this in the plugin as well?
when alias used in test - plugin gives error -> "Error: [vite-node] Failed to load @/generated/types"
checked on 0.6.0 - everything is good there. Vitest - latest version.
Config -
test: { alias: { '@': resolve(__dirname, './src'), },
After I installed the plugin (and did NOT restart WebStorm as I was not prompted to), I opened a test file to see if the plugin was loaded correctly. The run
and watch
icons took a second to show, then WebStorm reported the following stacktrace in its "IDE Internal Errors" window.
WebStorm 2022.1.1
Build #WS-221.5591.52, built on May 10, 20
Runtime version: 11.0.14.1+1-b2043.45 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
OS: Garuda Linux
java.lang.ClassCastException: class java.lang.String cannot be cast to class com.github.linuxchina.jetbrains.plugins.vitest.AssertionResult (java.lang.String is in module java.base of loader 'bootstrap'; com.github.linuxchina.jetbrains.plugins.vitest.AssertionResult is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @5b8f57ac)
at com.github.linuxchina.jetbrains.plugins.vitest.ui.VitestTreeCellRender.getTreeCellRendererComponent(VitestToolWindowFactory.kt:132)
at com.intellij.ui.tree.ui.DefaultTreeUI.getRenderer(DefaultTreeUI.java:166)
at com.intellij.ui.tree.ui.DefaultTreeUI$2.getNodeDimensions(DefaultTreeUI.java:509)
at java.desktop/javax.swing.tree.AbstractLayoutCache.getNodeDimensions(AbstractLayoutCache.java:493)
at java.desktop/javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.updatePreferredSize(VariableHeightLayoutCache.java:1344)
at java.desktop/javax.swing.tree.VariableHeightLayoutCache.updateNodeSizes(VariableHeightLayoutCache.java:903)
at java.desktop/javax.swing.tree.VariableHeightLayoutCache.invalidateSizes(VariableHeightLayoutCache.java:371)
at java.desktop/javax.swing.plaf.basic.BasicTreeUI.setCellRenderer(BasicTreeUI.java:465)
at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.propertyChange(BasicTreeUI.java:3816)
at com.intellij.ui.tree.ui.DefaultTreeUI$5.propertyChange(DefaultTreeUI.java:616)
at java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:341)
at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:333)
at java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:266)
at java.desktop/java.awt.Component.firePropertyChange(Component.java:8756)
at java.desktop/javax.swing.JTree.setCellRenderer(JTree.java:776)
at com.github.linuxchina.jetbrains.plugins.vitest.ui.VitestToolWindowPanel.vitestTree(VitestToolWindowFactory.kt:85)
at com.github.linuxchina.jetbrains.plugins.vitest.ui.VitestToolWindowPanel.<init>(VitestToolWindowFactory.kt:40)
at com.github.linuxchina.jetbrains.plugins.vitest.ui.VitestToolWindowFactory.createToolWindowContent(VitestToolWindowFactory.kt:29)
at com.intellij.openapi.wm.impl.ToolWindowImpl.createContentIfNeeded$intellij_platform_ide_impl(ToolWindowImpl.kt:529)
at com.intellij.openapi.wm.impl.ToolWindowImpl.scheduleContentInitializationIfNeeded$intellij_platform_ide_impl(ToolWindowImpl.kt:508)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.doShowWindow(ToolWindowManagerImpl.kt:921)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.showToolWindowImpl(ToolWindowManagerImpl.kt:861)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.activateToolWindow$intellij_platform_ide_impl(ToolWindowManagerImpl.kt:586)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.activateToolWindow$intellij_platform_ide_impl$default(ToolWindowManagerImpl.kt:565)
at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.activated$intellij_platform_ide_impl(ToolWindowManagerImpl.kt:1930)
at com.intellij.toolWindow.StripeButton$1.actionPerformed(StripeButton.kt:59)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:401)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:270)
at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:298)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6654)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3345)
at com.intellij.toolWindow.StripeButton.processMouseEvent(StripeButton.kt:248)
at java.desktop/java.awt.Component.processEvent(Component.java:6419)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5029)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2793)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4861)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:820)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:743)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
Hello
It looks like it doesn't work with WSL. I got the following error message:
Cannot run program "\wsl$\Ubuntu\home\mishaa\dev\deepvue\node_modules.bin\vitest.CMD" (in directory "\wsl$\Ubuntu\home\mishaa\dev\deepvue"): CreateProcess error=2, Le fichier spécifié est introuvable
I'm using this template : https://github.com/antfu/vitesse-lite for Vue 3 and Vitest test framework. It's working good with CLI.
I'm under the last version of PHPStorm. Same error with Webstorm.
The basic tere is here :
import { describe, expect, it } from 'vitest'
describe('Hi', () => {
it('should works', () => {
expect(1 + 1).toEqual(2)
})
})
Estou com problemas para rodar o debugger
node_modules/vitest/vitest.mjs run --threads false --coverage -t should return an entity with errors src/@core/company/application/use-case/update-company.use-case.spec.ts
Debugger listening on ws://127.0.0.1:45253/92ab3c49-bf70-4b84-bf71-cb5e52b09cba
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
^C
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.