Giter Club home page Giter Club logo

japa-vscode's Introduction

๐Ÿงช 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.

japa-vscode's People

Contributors

cahnory avatar julien-r44 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cahnory

japa-vscode's Issues

Cannot provide custom file matching pattern

When I run my tests from the terminal I can rely on the files param for example like this:

configure({
  ...processCliArgs(process.argv.slice(2)),
  ...{
    files: ['test/**/*.e2e-spec.ts'],
    ...
  },
});

But code lenses do not show up on those files because I can't set the same pattern to match for the extension.

Snippets not included

Currently, Japa snippets are bundled as a part of the Adonis extension. I think they should be bundled as a part of this one.

CodeLense buttons do not display anymore

Just realized that codelens buttons to execute a test or a group have all disappeared.

The codeLens option in the settings is still enabled
Tried to reinstall the extention but no luck.
using version 1.0.1
Any idea why ?

Configuring test explorer with @japa/reporter ndjson?

I see on the Instructions section there is

import { configure, processCLIArgs, run } from '@japa/runner'
import { assert } from '@japa/assert'
import { ndjson, spec } from '@japa/reporters'

processCLIArgs(process.argv.splice(2))
configure({
  files: ['tests/**/*.spec.js'],
  plugins: [assert()],
  reporters: {
    activated: ['spec'],
    list: [ndJson(), spec()], // ๐Ÿ‘ˆ Make sure to include ndjson
  }
})

but i can't seem to find ndjson nor the package @japa/reporters. All i can find is @japa/spec-reporter which is used for the spec reporter. I am using japa with adonisjs so i'm configuring japa through tests/bootstrap.ts. I can add reporters here

/*
|--------------------------------------------------------------------------
| Japa Reporters
|--------------------------------------------------------------------------
|
| Japa reporters displays/saves the progress of tests as they are executed.
| By default, we register the spec reporter to show a detailed report
| of tests on the terminal.
|
*/
export const reporters: Required<Config>['reporters'] = [specReporter()]

But i don't know how to add ndjson here. help?

Can't run a test with the $self placeholder

Hi,

As the title say, I can 't individually run the test below by clicking on the codelense button:

  test('test with {$self}')
    .with(['a', 'b', 'c'])
    .run((ctx, data) => {
      expect(data).toBe(data)
    })

it works fine by running the whole group though.
The console execute the line cd "/path/to/project && npm run test -- --files "tests/dir/mytest.ts" --tests "test with {\$self}"
and the output is NO TESTS EXECUTED

I tried to tweak a little the command but didn't find a way to launch the test with CLI. As far as i know, it's undocumented on japa, so it could be a Japa bug, I don't know

Wrongly escape quotes when running a unique test

Hi,

I just got bamboozled for a couple of hours by a bug when trying to run a unique test in a file. Here an exemple :

test("Can't do something", ({ assert }) => {
    assert.isTrue(false)
})

When clicking the "Run the below test" button, the terminal will execute the command npm run test -- --files "tests/functional/myfile.spec.ts" --tests "Can\'t do something"

as a result the terminal shows NO TESTS EXECUTED

Indeed, the right command should be npm run test -- --files "tests/functional/myfile.spec.ts" --tests "Can't do something"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.