🧪 Japa extension for VSCode
Features
- Vscode Testing API integration
- Run tests without typing anything. Either with a shortcut, Code Lenses, or using Vscode Test Explorer
- "See snapshot" codelens to quickly see the snapshot of a test ( for @japa/snapshot )
- Support multiple workspaces
- Support Javascript, Typescript, ESM, CJS
- Works with Adonis.js projects using Japa
- Snippets
Demo
Using Vscode Test Explorer
Using Code Lenses
Instructions
Test Explorer
If you wish to use the vscode test explorer integration, you will need to have Japa version 3.0.0
or higher to be able to use the --reporter
flag.
Also note that you need to have the ndjson
reporter activated in your Japa config file, since we are using it to communicate with the extension. ndjson
is enabled by default if you don't have a reporters
key in your config file. So if you have a reporters
config, make sure to inclure ndjson
in it.
import { configure, processCLIArgs, run } from '@japa/runner'
import { assert } from '@japa/assert'
import { ndjson, spec } from '@japa/runner/reporters'
processCLIArgs(process.argv.splice(2))
configure({
files: ['tests/**/*.spec.js'],
plugins: [assert()],
reporters: {
activated: ['spec'],
list: [ndjson(), spec()], // 👈 Make sure to include ndjson
}
})
Configuration
tests.npmScript
: The npm script to run when executing tests. Defaults to test
i.e if you set it to test:unit
, the extension will run npm run test:unit --flags
when executing tests
tests.enableCodeLens
: Show CodeLenses above each test. Defaults to true
tests.watchMode
: Run tests in watch mode when executed via shortcut/codelens. Defaults to false
tests.filePattern
: The glob pattern to use when searching for tests. Defaults to **/*.{test,spec}.{ts,js}
misc.useUnixCd
: Use Unix-style cd for windows terminals ( Useful when using Cygwin or Git Bash )
misc.disableNodeWarnings
: Disable node warnings by setting NODE_NO_WARNINGS=1
when running tests. Defaults to true
.
Keybindings
ctrl+shift+t
: Run the test at the cursor position
ctrl+shift+f
: Run the test file in the active editor
These keybindings can be easily changed in your VSCode configuration :
- F1 -> Preferences: Open Keyboard Shortcuts
- Type
japa-vscode
in the search bar
- Change the
japa-vscode.runTest
or japa-vscode.runTestFile
keybindings
Snippets
All snippets are prefixed with ja:
. Give it a try in your editor to see what's available.
Contributing
- See contributing guide
- Clone the project and open it in VS Code
- Run
npm install
- Press
F5
to open a new VSCode window with your extension loaded.
- You can relaunch the extension from the debug toolbar after changing code in
src/index.ts
.
- You can also reload (
Ctrl+R
or Cmd+R
on Mac) the VS Code window with your extension to load your changes.