jest-community / vscode-jest Goto Github PK
View Code? Open in Web Editor NEWThe optimal flow for Jest based testing in VS Code
License: MIT License
The optimal flow for Jest based testing in VS Code
License: MIT License
Since the plugins starts without allowing the user to specify what version of node should be used, and use the default selected version in its own process, it is not yet possible to select what version of node should be used.
In my case, my default nvm node version is 4.x. But my project has a .nvmrc with 6.9.1
in it. But Jest uses the default one. (which makes the whole extension unusable since it crashed instantly)
Would it be possible to either specify what path of node we want Jest to use, or, more simply, run a nvm use
before the plugin starts if there is a .nvmrc
file in the root folder?
I'm setting up a new project, I'm stopping and starting all the time
Hi, how do I interact with the test runner using these inputs?
Watch Usage
› Press a to run all tests.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
If you look at how we run tests inside Metaphysics
we have this node foreman dance - DEBUG=info,error nf run jest --env .env.test
.
I was wondering about whether we could support a property on Package.json
that gives you the command context to run within?
Hi!
I've installed the plugin, made sure I got this in package.json:
"test": "jest --watchAll --config node_modules/ca-ui-module-test/__jestDist__/jest.config"
But the runner keeps telling me all the time:
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.
I can do yarn test
and everything works normally. Am I missing something? What should I look for? Is there anything I can activate that gives more more info?
Thanks!
So, one thing our company likes to see is code coverage numbers. I'd love to see this plugin enable support for this.
Mainly, I'd like to see two things:
Thoughts on the matter?
I'd also love to help build this, though I'm a noob at VS Code extensions.
Hello,
Tried to use the extension today, but it seems to work only in part for me.
//Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:133 [Extension Host] Uncaught Exception: SyntaxError: Unexpected token, expected , (31:6)d.logExtensionHostMessage @ //Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:133
//Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/electron-browser/workbench.main.js:133 [Extension Host] SyntaxError: Unexpected token, expected , (31:6)
at Parser.pp$5.raise (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:4246:13)
at Parser.pp.unexpected (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:1627:8)
at Parser.pp.expect (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:1615:33)
at Parser.pp$7.flowParseTypeParameterDeclaration (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:4645:12)
at Parser.parseMaybeAssign (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:5674:33)
at Parser.pp$3.parseExprListItem (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:4101:16)
at Parser.parseExprListItem (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:5425:24)
at Parser.pp$3.parseCallExpressionArguments (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3410:20)
at Parser.pp$3.parseSubscripts (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3370:31)
at Parser.pp$3.parseExprSubscripts (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3341:15)
at Parser.pp$3.parseMaybeUnary (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3311:19)
at Parser.pp$3.parseExprOps (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3241:19)
at Parser.pp$3.parseMaybeConditional (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3218:19)
at Parser.pp$3.parseMaybeAssign (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:3181:19)
at Parser.parseMaybeAssign (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:5694:20)
at Parser.pp$1.parseVar (/Users/alex/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:2205:24)
Not sure what else i could provide as details, please let me know.
Cheers
Version 1.6.1 is working with my environment, thanks @orta !
Since I'm using an external configuration file to run my jest tests, it fails. It is possible to add a new setting where I define the path to a config file?
I can try to do a PR with some guidance, never worked with VS Code extensions.
I am getting (with 1.6.5)
import { winner } from "./gameplay";
^^^^^^
SyntaxError: Unexpected token import
Works from the terminal though.
I've just installed this amazing plugin - thanks a lot for all the hard work put into it.
Unfortunately, even though the plugin seems to load and run tests fine (I see the little jest
button at the status bar in the bottom of the screen) - I don't see the pass/fail indicators in the gutter (those precious green/red dots)
In the dev console, is see the following log each time I navigate to one of my .spec.js
files:
TypeError: Cannot read property 'concat' of undefined
at babylonParser (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/parsers/BabylonParser.js:57:32)
at Object.parse (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/ScriptParser.js:31:12)
at JestExt.triggerUpdateDecorations (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:118:51)
at JestExt.updateWithData (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:262:14)
at Runner.jestProcess.on.on (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:41:18)
at emitOne (events.js:96:13)
at Runner.emit (events.js:188:7)
at readFile (/Users/guy/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/Runner.js:61:18)
at tryToString (fs.js:455:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
I'm working on a react-native project and to be honest, I'm pretty new to the whole Js ecosystem - it's possible my setup is wrong and or missing some config?
Orta.vscode-jest-2.0.5
react-native 0.38.2
vs code 1.8.1
How can I use Flowtypes with this extension? It's failing the tests because the types aren't removed and I can't seem to figure out where I need some config to tell the extension to strip them.
Thanks for any help!
Jason
I'm on Windows using npm3.
When I have this plugin installed and a project open that uses Jest, I cannot npm install any plugins unless I close VS Code. I am greeted with errors that look like files in use, probably because this plugin has something locked. A way to easily turn the watcher off would be useful here: even better would for it to stop when npm install is running.
I run just like this:
node --harmony-async-await ./node_modules/.bin/jest
I would like to suggest adding a setting for command line variables.
How can I run vscode-jest to include document as global?
It works with npm run ./bin/test.js
//./bin/test.js
process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';
// Load environment variables from .env file. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.
// https://github.com/motdotla/dotenv
require('dotenv').config({
silent: true
});
const jest = require('jest');
const argv = process.argv.slice(2);
// Watch unless on CI
if (!process.env.CI) {
argv.push('--watch');
}
argv.push('--no-cache');
jest.run(argv);
Ref: https://twitter.com/gabro27/status/803592079188365316
When installing the extension and opening an existing test file, all dots are white.
This is because jest only runs on changed files.
This is not a big deal, but the experience is not the most rewarding, as in "I installed this extensions to see green dots! Where are my green dots?!"
Possible ways of handling this:
Others?
Would it be possible to attach a debugger to the tests being run? I like to set breakpoints in tests while doing TDD.
Hey Orta,
Trying to give this a whirl. Got it installed via the extension menu, enabled it. In my package.json I have this script:
"scripts": {
"stats": "webpack -p --profile --json > stats.json",
"production": "webpack -progress -p",
"test": "jest"
},
But in VSCode I'm not seeing the lovely output you have in the footer, what am I missing?
Cheers
Pete
Hi there,
First, great extension. Very helpful.
I noticed in your gif that you have autocomplete working for Jest (expect), is that something that this extension adds? Or do you have something else set up to enable that?
Thanks!
it would be cool if the // error display is remove, because it alters the code. better to make the UI like Wallaby.js which shows passed and failed test on the number pane. and does not show errors written to file in comments.
I looked into the console this time when trying to enable vscode-jest and saw that this error is popping up:
extensionHost.ts:293[Extension Host] Uncaught Exception: TypeError: Cannot read property 'split' of undefinedA.logExtensionHostMessage @ extensionHost.ts:293
extensionHost.ts:293[Extension Host] TypeError: Cannot read property 'split' of undefined
at TestReconciler.lineOfError (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:123:32)
at assertions.map.assertion (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:96:21)
at Array.map (native)
at TestReconciler.mapAssertions (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:85:23)
at results.testResults.forEach.file (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:50:26)
at Array.forEach (native)
at TestReconciler.updateFileWithJestStatus (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:45:25)
at JestExt.updateWithData (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:254:25)
at Runner.jestProcess.on.on (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:41:18)
at emitOne (events.js:96:13)
at Runner.emit (events.js:188:7)
at readFile (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/Runner.js:61:18)
at tryToString (fs.js:455:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)A.logExtensionHostMessage @ extensionHost.ts:293
shell.ts:541Cannot read property 'split' of undefined: TypeError: Cannot read property 'split' of undefined
at TestReconciler.lineOfError (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:123:32)
at assertions.map.assertion (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:96:21)
at Array.map (native)
at TestReconciler.mapAssertions (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:85:23)
at results.testResults.forEach.file (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:50:26)
at Array.forEach (native)
at TestReconciler.updateFileWithJestStatus (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/TestReconciler.js:45:25)
at JestExt.updateWithData (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:254:25)
at Runner.jestProcess.on.on (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/out/src/JestExt.js:41:18)
at emitOne (events.js:96:13)
at Runner.emit (events.js:188:7)
at readFile (/home/capaj/.vscode/extensions/Orta.vscode-jest-2.0.5/node_modules/jest-editor-support/build/Runner.js:61:18)
at tryToString (fs.js:455:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
I have version 2.0.5 on vscode 1.8.1
The Vscode extension fails to run the the tests, output
FAIL src/App.test.js
● Test suite failed to run
/Users/pkearney/Development/react-app/src/App.test.js: Unexpected token (6:10)
4 |
5 | it('renders without crashing', () => {
> 6 | shallow(<App />);
| ^
7 | });
8 |
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.058s
Ran all test suites.
The tests run normally on the command line with npm test
I'm writing my code and my tests in TypeScript. Could you add support for that too?
throws Error and stops working when switching to "output" or "debug console" tab.
Reports this error message:
Exception raised: Process failed: spawn node_modules/.bin/jest ENOENT
On windows you'd have to spawn node_modules/.bin/jest.cmd
Not sure why but it gives me "'node_modules' is not recognized as an internal or external command,
operable program or batch file." while using inside create react app APP.
We could add this to the tasks:
{
"name": "Run Tests With Debugger (slower, use npm run watch for normal work)",
"type": "node",
"request": "launch",
"port": 5858,
"address": "localhost",
"stopOnEntry": false,
"runtimeExecutable": null,
"runtimeArgs": [
"--debug-brk",
"./node_modules/.bin/jest",
"-i"
],
"cwd": "${workspaceRoot}",
"sourceMaps": true
}
When using stackgl/headless-gl
, running jest from command line works fine, but this plugin will fail:
import GL from 'gl';
let gl = GL(100, 100); // <-- Errors
Causes this error:
TypeError: bindFramebuffer(GLenum, WebGLFramebuffer)
at WebGLRenderingContext.bindFramebuffer (node_modules/gl/webgl.js:1054:11)
at WebGLRenderingContext.bindFramebuffer (node_modules/gl/webgl.js:1068:22)
at resizeDrawingBuffer (node_modules/gl/webgl.js:4092:20)
at Object.allocateDrawingBuffer (node_modules/gl/webgl.js:4079:3)
at createContext (node_modules/gl/node_index.js:105:9)
at Object.<anonymous> (shader.spec.js:10:53)
I just installed the latest create-react-app and I can no longer get the watcher to run. I'm currently getting the following error in vscode:
fs.js:1431
throw error;
^
Error: watch /home/bill/dev/react-client/node_modules/es5-ext/test/string/#/contains ENOSPC
at exports._errnoException (util.js:1026:11)
at FSWatcher.start (fs.js:1429:19)
at Object.fs.watch (fs.js:1456:11)
at NodeWatcher.watchdir (/home/bill/dev/react-client/node_modules/sane/src/node_watcher.js:144:20)
at Walker.<anonymous> (/home/bill/dev/react-client/node_modules/sane/src/node_watcher.js:353:12)
at emitTwo (events.js:106:13)
at Walker.emit (events.js:191:7)
at /home/bill/dev/react-client/node_modules/walker/lib/walker.js:69:16
at go$readdir$cb (/home/bill/dev/react-client/node_modules/graceful-fs/graceful-fs.js:149:14)
at FSReqWrap.oncomplete (fs.js:123:15)
All the tests are marked with empty green circles and indicate that tests haven't been run even though they have been.
From the keyboard you can't get to the Jest output info. Need a mouse, that's a shame. 👍
This #25 wasn't quite right in the end, I need to run npm run jest -- --watch
from the root of the jest repo in order to ensure the build transformations work right. So ideally, I'd be able to say "if I open at this folder, use this as cwd for jest".
First; this is a very cool extension.
When you get a JS error you'd expect it to display as thus:
state = STORE.getStateXXX() // TypeError: STORE.getStateXXX is not a function
Instead it's
state = STORE.getStateXXX() //
Still useful, but could use a message.
I couldn't get on with wallabyjs
, and was pleasantly surprised to find this! However, it turns out that for some reason there were a bunch of issues in the BabylonParser
within jest-editor-support
- I'm not entirely certain what caused them (as no one else seems to be having these issues) - must be something specific to my .babelrc
. However, a few adjustments to the source made it work pretty much alright - there's still some issues which I'm investigating, but wanted to share here for anyone else struggling to get this plugin working (yay for the pretty coloured circles!).
It's mainly to do with poor (or non-existent) defensive coding. I had a lot of "cannot read type of undefined" and "cannot read type of null" - adding in checks for these in the searchNodes
function of the jest-editor-support/build/parsers/BabylonParser.js
stopped these.
ie:
// before
.filter(declaration => isFunctionDeclaration(declaration.init.type))
.forEach(declaration => searchNodes(declaration.init.body, file));
// after
.filter(declaration => isFunctionDeclaration(declaration.init ? declaration.init.type : null))
.forEach(declaration => searchNodes(declaration.init ? declaration.init.body : null, file));
// before
element.type === 'ExpressionStatement' &&
element.expression.type === 'AssignmentExpression' &&
// after
element.type === 'ExpressionStatement' &&
element.expression &&
element.expression.type === 'AssignmentExpression' &&
element.expression.right &&
don't know if this is already implemented yet. showing passed and failed test inline in a typescript file ( like in the gif shown but for js) because this is only shown for js files currently. if there is a way to make it show the same either via sourcemaps or something else can someone show me? appreciate you help in advance thanks
I'm using version 0.9.3 of react-scrips in CRA, which relies on Jest v18.1.
I run the tests using npm test
(or npm run test
), and the CLI works perfectly.
However, the extension doesn't seem to be recognizing that the tests are being run. I have empty green circles next to all of them, and, upon highlight, they all display: Test has not run yet, due to Jest only running tests related to changes.
Yet the tests are definitely running. I'm not sure what the problem is, since opening VSCode DevTools doesn't show any errors.
That's where the error will be.
This test updates the comment string each time:
it('tests jest', () => {
expect(33).toBe(new Date().getTime()); // Expected value to be (using ===): 1482978207691 Recieved: 33
});
This test doesn't show it at all or doesn't update it after a ES7 spread
operator is added.
it('tests jest', () => {
const test = { ...{} };
expect(33).toBe(new Date().getTime());
});
In the dev console it errors with:
workbench.main.js:132 Unexpected token (8:19): SyntaxError: Unexpected token (8:19)
at Parser.pp$5.raise (/home/sam/.vscode/extensions/Orta.vscode-jest-2.0.3/node_modules/jest-editor-support/node_modules/babylon/lib/index.js:4246:13)
Weird. I have JS validation enabled in vscode & am using v1.8.1.
Im guessing the plugin doesn't inherit the projects babel config?
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.