david-kunz / jester Goto Github PK
View Code? Open in Web Editor NEWA Neovim plugin to easily run and debug Jest tests
License: The Unlicense
A Neovim plugin to easily run and debug Jest tests
License: The Unlicense
Looking at #8 I was expecting that if I re-ran the command it would re-use the same terminal window.
If I run
:lua require"jester".run()```
it will run the tests, if I then move back to my test code and run the command again, it navigates me to the test terminal split, but does not run anything again.
test("i have a-in my name")
does not work. It forwards it to jest like i have a\\-in my name
test("i do not have any in my name")
works
The character escaping breaks the run command for me on MacOS. Escaping probably makes sense on Windows, but on MacOS it seems to be redundant and unneeded. I think it would be great to add a special option to not escape characters in cmd
.
This is probably related to the #7 issue
Nice plugin!
I'm experimenting with this in a TypeScript project and noticed what may be a little bug. If the cursor is directly over a comment, then it seems like it is unable to traverse the parent nodes to find the nearest "test" block. But moving anywhere else inside the test function locates it perfectly fine.
This is basically a copy of #10. I commented there, but given it's closed, it might get lost so just repeating that here:
I can share what is being run on my case:
npx sfdx-lwc-jest -- -t '^c\\-api\\-data\\-fetcher does not display success or error messages when loading$' /home/fede/P
rogramming/Salesforce/one\\-customer\\-care\\-sfdc/force\\-app/main/default/lwc/apiDataFetcher/__tests__/apiDataFetcher\\.test\\.js
Please note the npx sfdx-lwc-jest --
is a wrapper around jest, but works fine if the dashes are not double escaped:
npx sfdx-lwc-jest -- -t '^c-api-data-fetcher does not display' force-app/main/default/lwc/apiDataFetcher/__tests__/apiDataFetcher.test.js
works fine (I dropped the $, but it just ends up running multiple tests)
This is my config:
return {
'David-Kunz/jester',
config = function()
require('jester').setup {
cmd = "npx sfdx-lwc-jest -- -t '$result' $file",
prepend = { 'describe' },
terminal_cmd = ":ToggleTerm direction=float"
}
end
}
Replicated in bash
and zsh
. Both in and out of tmux
, and both in alacritty
and gnome-terminal
.
Let me know what other info I can get for you.
Is there a way to use the same terminal used in the last test run, if it's still open?
Thanks for the great plugin!
Hi! After calling :lua require('jester').debug()
I get the following warning which I'm guessing is because the plugin needs to be updated to Neovim's new treesitter api:
nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.query.get_node_text
Hi! When I run require"jester".debug()
on a jest test I get the message "No active session". If I run require"jester".debug_file()
nothing happens. Do you know what I could be doing wrong?
Here's a link to my dap/jester configuration.
I created an Angular application which offered 3 tests by default:
ng new ng-dummy
I then could run the tests from the command line:
11:12 $ ng test
โ Browser application bundle generation complete.
19 06 2022 11:12:59.914:WARN [karma]: No captured browser, open http://localhost:9876/
19 06 2022 11:12:59.931:INFO [karma-server]: Karma v6.3.20 server started at http://localhost:9876/
19 06 2022 11:12:59.932:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
19 06 2022 11:12:59.936:INFO [launcher]: Starting browser Chrome
19 06 2022 11:13:01.190:INFO [Chrome 102.0.5005.115 (Linux x86_64)]: Connected on socket rEYPsN7y3S_ui1boAAAB with id 55219348
Chrome 102.0.5005.115 (Linux x86_64): Executed 3 of 3 SUCCESS (0.213 secs / 0.164 secs)
TOTAL: 3 SUCCESS
Chrome 102.0.5005.115 (Linux x86_64) ERROR
Disconnected Client disconnected from CONNECTED state (transport close)
Chrome 102.0.5005.115 (Linux x86_64): Executed 3 of 3 SUCCESS (0.213 secs / 0.164 secs)
Chrome 102.0.5005.115 (Linux x86_64) ERROR
Disconnected Client disconnected from CONNECTED state (transport close)
I was hopping to run them from within nvim:
use "David-Kunz/jester"
local status_ok, jester = pcall(require, "jester")
if not status_ok then
return
end
jester.setup {
}
With the current cursor location in the body of one test, I typed in the command:
:lua require"jester".run()
But it did not run the test. Instead of displayed the message:
Could not find any of the following: test, it, describe
Angular CLI: 13.3.3
Node: 16.14.2
Package Manager: npm 8.5.0
OS: linux x64
14:01 $ nvim --version
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az316-460
Add a GIF for the README file.
I'm really loving jester, so a huge thanks for all the work you've put into it. :-)
Basically, what I'd like to do is put jester's terminal output into the nvim-dap-ui repl window. All the other debug windows from the dap-ui work perfectly (stacks, breakpoints, scopes) with Jester, but the repl window stays blank. I've tried to figure out how to pipe the terminal output from jester into that window (running lua require"jester".debug({ terminal_cmd =})
with lots of different options, but none seem to work.
Any direction on how this might be possible? I can definitely rearrange the jester terminal window to fit the layout, but that cuts into the flow of coding, so I'd like to find an automated solution. Thanks again!
Trying to get this to work with typescript. Is it asking too much to post a sample typescript config? Thank you.
As nvim-dap repo suggests to use vscode-dap I have switched to vscode-dap. Also I have adjusted jester
setup a accordingly. Here is my jester setup.
require'jester'.setup{
cmd = "NODE_OPTIONS=--experimental-vm-modules node ./node_modules/jest/bin/jest.js -t \"$result\" $file", -- run command
terminal_cmd = ":ToggleTerm",
dap = {
type = 'pwa-node',
request = 'launch',
name = 'Jest Debug',
cwd = "${workspaceFolder}",
rootPath = "${workspaceFolder}",
runtimeExecutable = "node",
runtimeArgs = {
"./node_modules/jest/bin/jest.js",
"--runInBand",
"-t",
"$result",
"$file",
},
-- args = { "--runTestsByPath", "${relativeFile}" },
args = { "--no-cache" },
env = { NODE_OPTIONS = '--experimental-vm-modules' },
sourceMaps = true,
skipFiles = { "<node_internals>/**" },
port=9229,
console = 'integratedTerminal',
disableOptimisticBPs = true
},
}
also I have following mappings
nnoremap <silent> <leader>jr :lua require"jester".run()<CR>
nnoremap <silent> <leader>jd :lua require"jester".debug()<CR>
jester.run()
works like expected by jester.debug()
executes always the first debugged test. I always need to restart nvim to be able to debug second test.
Hi ๐ As the title says, can't find tests when the filename has regex symbols in it. For example, one of my projects has a filename like [productType].test.tsx
which is a perfectly valid filename in a Node/TS project.
I can run this test from command line:
> yarn jest src/pages/some-page/__tests__/\\[productType\\].test.tsx
But when running from Jester, it can't find the test likely because it interpreted [productType]
as a regex character class, instead of just a plain string. No escaping is done before passing the filename to Jest.
Debugger listening on ws://127.0.0.1:9229/5ddc50
f6-7908-4b7d-9b34-7fc41391553e
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/kahnclusions/src/myproject
607 files checked.
testMatch: **/?(*.)+(spec|test).[tj]s?(x) - 52
matches
testPathIgnorePatterns: /node_modules/ - 607 matches
testRegex: - 0 matches
Pattern: /Users/kahnclusions/src/myproject/src/pages/some-page/__tests__/[productType].test.tsx|--no-cache - 0 matches
Waiting for the debugger to disconnect...
[Process exited 137]
Yarn (and maybe other package managers) support different ways of storing dependancies. This makes the local node modules not compliant in those cases. https://yarnpkg.com/features/pnp/#initializing-pnp
For example running :lua require"jester".debug()
Debugger listening on ws://127.0.0.1:9229/08a2389d-5a16-4aed-9437-48d1d61740d3
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module '/home/rockerboo/code/ecogarden/create/node_modules/.bin/jest'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
[Process exited 1]
The suggestion is to run yarn run --inspect --inspect-brk jest
instead. This will look up the binary and apply the inspects for the debugger.
I think with this example it starts running a node process so would need to pass through the suggested paths
node -r ./.pnp.cjs ./server.js
NODE_OPTIONS="--require $(pwd)/.pnp.cjs" node ./server.js
I am also working with yarn workspaces so these 2 modes are not generally good enough to automate depending on where I am in the workspaces.
Hi @David-Kunz ,
Would you be interested into adding the workspace folder automatically by adding lsp dependency to the package ? I was struggling to setup up the path correctly for running the commands while now lsp can get the workspace folder automatically.
I have the code ready on my local copy just wondering if you are intersted into adding it into yours
Hi, great work with this plugin! Does this work for TS projects?
I am using create-react-app
so need to override the cmd
to make sure it's loaded correctly.
require("jester").setup({
cmd = "NODE_PATH=. react-scripts test --testPathPattern=$file --testNamePattern='$result'",
})
This works great for
:lua require"jester".run()
But it breaks
:lua require"jester".run_file()
because it tries to filter test names matching /$result/
When running :lua require"jester".debug_file()
:
init.lua:154: module 'dap' not found:
Could not find a 'dap' module in src code.
Hi!
Im trying to debug a jest test file with :lua require"jester".debug_file()
It throws me the following error:
The selected configuration references adapter node2
, but dap.adapters.node2 is undefined
Im testing an API rest using javascript/NodeJS and I dont know anything (so far) about lua coding, sorry :)
Thanks in advance!
Regards.
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.