My goal is to run mocha unit tests by Atom, which is installed on Windows and also my src code resides. this should work independently from my Meteor App which is running on a different (Linux) machine.
Basically my setup is like this:
I have my repo and sourcecode:
c:\Users\Me\repos\meteor
My tests are inside:
c:\Users\Me\repos\meteor\tests
I have Node:
c:\Program Files\nodejs
installed with "npm i -g mocha --save-dev"
And i try to use this package https://github.com/Tabcorp/atom-mocha-test-runner but i can switch to another package if necessary.
What I've tried so far:
I edited my settings for the atom-mocha-test-runner:
Mocha command: C:\Program Files\nodejs\node_modules\mocha\.bin\mocha
Mocha command: C:\Program Files\nodejs\npm mocha
But each time i try to run my test via dropdown menu (Run Mocha Test), i get this error:
Mocha Test Results:
Node binary: C:\Program Files\nodejs\node.exe
Root folder: C:\Source\Repos
Mocha command: undefined
Path to mocha: mocha
Debug-Mode: false
Test file: tests\unit\first.js
Selected test: should return url
Failed to run Mocha
spawn mocha ENOENT
Anyone know what i miss or do wrong?
Still having no idea about why the package isn't working, I'm going to give a cop-out answer. If we figure out how to make it work, you can accept that answer instead. process-palette gives you the ability to run highly specific command-line instructions from Atom commands. Here's an example of a command that runs mocha in the project path for the current file with the same hotkey and also conveniently organized into its own menu item:
The disadvantage of this approach is that you have to know how to use the external program yourself. Packages like mocha-test-runner are designed to remove that need from the user, but as we can see here, sometimes the package doesn't know what it needs to be doing. The disadvantage is mitigated by the fact that you only have to learn the command for long enough to set up the configuration to run it, and from that point on it's very easy.
Advantages versus other packages include the ability to precisely control what's going on. Say you have multiple top-level folders in the current project, and they have different test suites. A package like mocha-test-runner can get the path from the active file, or from the project. If the developer chose to grab the project path, then you're going to have trouble running individual test suites. With the configuration I've shared, the command will always be run in the absolute path of the current file's project folder, so the tests will be run for whichever file you're working on at the time.
Related
I am getting an error message:
"C:\Program Files\nodejs\node.exe" C:\Users\keechan\Desktop\NodeJS\my-module\tests\sample.test.js
ReferenceError: describe is not defined
This issue only happens when I run via Run (ctrl+shift+F10).
When I run via the Debug Configuration I created, it works okay.
But considering if I have many test.js files and I want to be able to run each individual test suite, I do not want to have to make a debug configuration for each one of them.
I already tried:
installing #types/jest library under settings (Languages & Frameworks > JavaScript > Libraries)
added #types/jest as well as jest in my package.json
Also, I noticed that it is calling node.exe in:
"C:\Program Files\nodejs\node.exe" C:\Users\keechan\Desktop\NodeJS\my-module\tests\sample.test.js
Maybe this is the reason why? So how do I change it to use jest?
Thank you so much!
You are not running Jest, you run your spec file by passing it directly to Node.js using Node.js run configuration. Make sure to use Jest run configuration to start your spec
Mocha is installed and runs fine through Terminal, Mocha Sidebar extension added in VS Code, however when using within VS Code it doesn't appear to find any tests within either a test folder I have set up, or a test folder I navigate to within VS Code
How do you alter the Mocha settings within VS Code to point it to a different/ correct location for the /test folder?
Is it possible to run tests on a folder you navigate to within VS code explorer and how to config that?
In the Output I am currently seeing the below:
Finding tests with Mocha on Node.js at "/usr/local/bin/node"
Running Mocha with Node.js at "/usr/local/bin/node"
No Mocha options are configured. You can set it under File > Preferences > Workspace Settings.
Test file(s):
undefined
I had this issue, and a couple of things solved it:
npm install -g glob
npm install -g mocha
npm install -g bluebird
Add "mocha.options": {} to the workspace configuration.
Add a glob option to the workspace configuration.
Restart VSCode.
Apparently not having global glob, mocha, and bluebird installed will cause it to fail on this.
I'm adapting an existing project to use Grunt, Assemble and other workflow tools. I have the workflow working on one machine, but when I try to run the Gruntfile on a different system I get an error:
[/home/ian/workspace/myproject] (master)
ian#ian-desktop $ grunt assemble
Running "assemble:pages" (assemble) task
Warning: Cannot find module '/home/ian/workspace/myproject/node_modules/
grunt-assemble/node_modules/assemble/node_modules/handlebars-helpers/
lib/helpers/home/ian/workspace/myproject/node_modules/grunt-assemble/
node_modules/assemble/node_modules/handlebars-helpers/lib/helpers/code.js'
Use --force to continue.
Aborted due to warnings.
The path that Grunt is trying to load is completely messed up (note the re-occurrence of the cwd about halfway through), but the filename it's looking for - code.js - is installed locally (by npm -i):
[/home/ian/workspace/myproject] (master)
ian#ian-desktop $ find . -name code.js
./node_modules/grunt-assemble/node_modules/assemble/node_modules/
handlebars-helpers/node_modules/remarkable/lib/rules_block/code.js
./node_modules/grunt-assemble/node_modules/assemble/node_modules/
handlebars-helpers/test/code.js
./node_modules/grunt-assemble/node_modules/assemble/node_modules/
handlebars-helpers/lib/helpers/code.js
./node_modules/grunt-mocha/node_modules/mocha/node_modules/jade/
lib/nodes/code.js
Both the systems I'm working on are Ubuntu 14.10, so shouldn't differ in any material way. Node -v gives v0.10.33, npm -v gives 2.1.5. I've tried:
checking out a fresh copy of the entire project from git
clearing all Bash environment vars before running Grunt
I'm having a hard time figuring out what's at the root of the different behaviour of the same code on two similar machines. Other tasks in my Gruntfile seem to be working fine, it's just the assemble task that's broken. Suggestions of where to look, or debug techniques to try, would be very welcome!
I have a node project which I've imported into Visual Studio from Web Storm. The mocha tests run fine in Web Storm but in Visual Studio they don't run at all. I've set the test framework on the relevant files and the test discovery phase correctly locates them. When I run the tests they get a green tick even if I modify the system such that they must fail. If I click on the output for a test then I see the error:
NTVS_ERROR: Failed to find Mocha package. Mocha must be installed in
the project locally...
I have installed Mocha locally, uninstalled and re-installed but with no difference.
I've managed to get some more specific error information by editing the mocha.js file to print out what's going wrong. The problem occurs during the detectMocha function. The exception that I get in the log now is:
[Error: Cannot find module
'C:\projects\FastLaneVS"\node_modules\mocha'] code: 'MODULE_NOT_FOUND'
Now my assumption is that this extra double quote after my project directory is the problem. I've gone back to the run_tests.js and printed out the argv array to see where the project directory is coming from and indeed it's already appended by the time that function is called.
Now I'm happy to accept that I've done something and added this quote somewhere but I can't find it. I also don't understand why the find_tests should work since that calls the same method and passes the Project Directory in correctly.
In my project it's directory is listed just as . and I've checked both the sln and nsproj files in notepad++ to try and find a spurious double quote.
I'm using VS pro 2013 update 4 with node tools 1.0.21029.05
I could modify the mocha runner to trim a trailing double quote but any ideas on how I can correctly fix this would be great.
I run jasmine tests in my node.js application via grunt. I've added grunt test to Webstorm's run configurations.
In "Run/Debug Configurations" the "Grunt Test" has following properties specified: node interpreter (node.exe in Program Files), working directory (project location), JavaScript file (grunt binary), and application parameters (test - grunt task name).
The configuration works correctly but stops without printing full jasmine output. Sometimes before printing any output, most often after some part of jasmine log, but before test summary or error details. Always the last line of output is
Process finished with exit code 0
When I take the Webstorm command and run it manually in console it works fine and always prints full output:
"C:\Program Files\nodejs\node.exe" C:\...\node_modules\grunt-cli\bin\grunt test
My tests includes asynchronous cases, so it takes about 20 seconds to run them all.
I noticed that each attempt to run tests via Webstorm prints a bit longer output. First attempt ends without any but after ten further I got full output with test summary.
Known issue, please see http://youtrack.jetbrains.com/issue/WEB-1926 and discussion on stackoverflow (mocha + webstorm - error message broken)
To fix the case described in question we can run jasmine tests directly by jasmine-node command (skipping grunt).
We have to set up new "Run/Debug Configuration" based on "Node.js" pre-conf.
Node interpreter (as usual):
C:\Program Files\nodejs\node.exe
Working directory: project root,
JavaScript file:
node_modules\grunt-jasmine-node\node_modules\jasmine-node\lib\jasmine-node\cli.js
This is for my case (using grunt-jasmine-node). We can also provide path to cli.js of jasmine-node installed globally.
Application variables:
--verbose src/test/js
Of course the last one is a path to directory of tests in my project. Here we can specify list of files or use other jasmine-node commands and parameters.
The problem that process.exit() does not wait the stdout. You should defer the exit call with one tick, that's all.