GithubHelp home page GithubHelp logo

asvetliakov / run-current-test Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 5.97 MB

VSCode Run current test extension

License: MIT License

TypeScript 100.00%
testing tdd tdd-workflow vscode vscode-extension ava mocha jest

run-current-test's Introduction

Run currest test

Features

  • Run current test at cursor position
  • AST parser, no regex checks
  • Configurable
  • Supports Jest, Mocha, Ava

features

Requirements

You must set run or runAndUpdateSnapshots command:

Way 1 (preferred): Define your test command in package.json, for example:

    "scripts": {
        "test": "jest"
    }

Then define commands in .vscode/settings.json similar to these (example for jest):

    "runCurrentTest.run": "npm run test -- ${relativeTestPath} --runTestsByPath --testNamePattern \"^${fullTestName}$\"",
    "runCurrentTest.runAndUpdateSnapshots": "npm run test -- -u ${relativeTestPath} --runTestsByPath --testNamePattern \"^${fullTestName}$\""

Way 2: Use full path without involing npm scripts, similar to these:

For Jest:

    "runCurrentTest.run": "${workspaceRoot}/node_modules/.bin/jest ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\"",
    "runCurrentTest.runAndUpdateSnapshots": "${workspaceRoot}/node_modules/.bin/jest -u ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\""
    // windows
    "runCurrentTest.run": "${workspaceRoot}\\node_modules\\.bin\\jest.cmd ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\"",
    "runCurrentTest.runAndUpdateSnapshots": "${workspaceRoot}\\node_modules\\.bin\\jest.cmd -u ${relativeTestPath} --runTestsByPath --testNamePattern \"${fullTestName}\""

For ava:

    "runCurrentTest.run": "${workspaceRoot}/node_modules/.bin/ava ${relativeTestPath} --match \"${fullTestName}\"",
    "runCurrentTest.runAndUpdateSnapshots": "${workspaceRoot}/node_modules/.bin/ava -u ${relativeTestPath} --match \"${fullTestName}\""
    // windows
    "runCurrentTest.run": "${workspaceRoot}\\node_modules\\.bin\\ava.cmd ${relativeTestPath} --match \"${fullTestName}\"",
    "runCurrentTest.runAndUpdateSnapshots": "${workspaceRoot}\\node_modules\\.bin\\ava.cmd -u ${relativeTestPath} --match \"${fullTestName}\""

For mocha:

    "runCurrentTest.run": "${workspaceRoot}/node_modules/.bin/mocha ${relativeTestPath} --grep \"${fullTestName}\"",
    // windows
    "runCurrentTest.run": "${workspaceRoot}\\node_modules\\.bin\\mocha.cmd ${relativeTestPath} --grep \"${fullTestName}\"",

You can pass any command here, for example if you need to additionally set NODE_ENV=test:

    "runCurrentTest.run": "NODE_ENV=test ${workspaceRoot}/node_modules/.bin/jest ${relativeTestPath} --testNamePattern \"${fullTestName}\"",

I'd recommend to use test setup file instead though.

You can use following templates for substitution in run commands:

  • ${workspaceRoot} - Will be replaced with absolute path to workspace root
  • ${testFilePath} - Will be replaced with absolute path to current test file
  • ${relativeTestPath} - Will be replaced with relative current test file to workspace root
  • ${testName} - Will be replaced with single current test name block
  • ${fullTestName} - Will be replaced with full path to current test name block. Full path is the all parent block paths + the current one, i.e "describe innerdescribe test"

Extension Settings

  • runCurrentTest.run - See above
  • runCurrentTest.runAndUpdateSnapshots - See above
  • runCurrentTest.autoSave - Auto-save dirty editor when running run command. Default is true
  • runCurrentTest.usePreviousTestCommand - Use previous test command if no test blocks (it(), describe(), etc) were found in the file. Useful when have opened test & source side-by-side and keep forgetting to switch to test side to run command
  • runCurrentTest.testBlockIdentifiers - Set to the name of test block identifiers (i.e. describe, it, etc...). The default ones provide good match
  • runCurrentTest.testNameSeparator - Separator between block names used in ${fullTestName}. Default is \\s which is space
  • runCurrentTest.unknownTestNameLiteral - Identifier used as block name if block name couldn't be determined. Default is .*

TODO

Debug current test

Release Notes

[0.1.0]

  • Support multi-root workspaces
  • Added license (MIT)
  • Run previous test command if no test blocks were found (configurable, default true)

0.0.2

Added few more identifiers to default test blocks Test block titles are now being escaped properly Close previous opened terminal when running command again

0.0.1

Initial release of 'Run current test'

run-current-test's People

Contributors

asvetliakov avatar weixu365 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

weixu365

run-current-test's Issues

Working with nvm

nvm installed, with the following in ~/.zshrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

And settings.json for run-current-test addon:

{
  "runCurrentTest.run": "${workspaceRoot}/node_modules/.bin/mocha ${relativeTestPath} --grep \"${fullTestName}\""
}

But it gives this error:

nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run npm config delete prefix or nvm use --delete-prefix v12.12.0 --silent to unset it.
/......./node_modules/.bin/mocha test/aaaa.test.js --grep "hello\sshould be ok"
env: node: No such file or directory

missing testFileName variable

with new jest --runTestsByPath not works, but you can use file name to determine which file should be considered.

for Windows it would looks like:

"jest ${testFileName} --testNamePattern \"${fullTestName}\""
which will result e.g.: "jest Modal.test.jsx --testNamePattern "Modal\should render properly""

PS. I know there's --findRelatedTests parameter, but it takes ages to start.

Future

Привет, добавь плз в список доступных переменных переменую ${selectedText}
очень не хватает такого функционала, хочется использовать ее для запуска конкретных тестов для другова фрэймворка, было бы просто супер, заранее спасибо.

пример использования:

"runCurrentTest.run": ". ${workspaceRoot}/.venv/bin/activate; pytest ${relativeTestPath}::${selectedText}"

Debug current test

Great plugin. Really saves time!

Any idea how to implement 'debug current test'?

Suggestion for README

Alexey,

I love your plugin and hope you are proud of it.
There is not much to add to the functionality, but:

I'd suggest to add in the README document, for the test commands, setting this: NODE_ENV=test
E.g. for node.js, mocha, Mac OS X the mocha command would be NODE_ENV=test mocha ${relativeTestPath} .... --watch

Note that in most Node setups, dev environment is the default and the tests may by mistake write (or delete) data in the dev database. Also, note the --watch - I find it useful when working on particular area.

Eventually, the setting of the environment may be done by the plugin's code.

AST parser is not picking up interpolated strings?

Given the following test:

describe(`${MyClass.name}`, () => {
  it('should do something', () => {

The command is being ran:

> jest --runTestsByPath "file.test.ts" "--testNamePattern" "^.*\sshould 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.