Node.js mocha test with mysql works from terminal but not from visual studio with test explorer

Jan 28, 2015 at 7:54 PM
I originally posted this on stackoverflow, but as there was no response yet, I thought I would bring this to the topic experts!

I am using Node.js tools for Visual Studio version 1.0 RC2 with Visual Studio Community edition 2013. I have node v0.10.36 installed, with mocha installed both locally and globally. I have set up some unit tests using the assert package, using the describe / it convention. I am able to run all my tests fine from the command line with mocha. I am also able to run some simple mocha tests with Visual Studio via the test explorer, having specified mocha as the TestFramework in the properties of my test file (test.js), as per directions here.

However, if I try to run integration tests against my MySQL database, it simply hangs when run within Visual Studio. There is not output (at least not anywhere I know to look), the test just keeps running.

When I run the same test from the command line, it works fine.

Here is a basic test that replicates this behavior on my machine (personal details removed):
var assert = require('assert');
var mysql = require('mysql');

describe('MySQL connectivity', function () {
    it('connects to database', function (done) {
        var connection = mysql.createConnection({
            host     : 'localhost',
            user     : 'redacted',
            password : 'redacted',
            multipleStatements: true,
            database : 'testdb'
        connection.query('SELECT 1 + 1 AS solution', function (err, rows, fields) {
            if (err) throw err
            assert(rows[0].solution == 2);
If I set my solutions properties such that it runs mocha instead of node (as described here), I can run the tests from Visual Studio (but then the results are spit out to a file, and the tests do not show up in the test explorer).

Any ideas how I can get my MySQL integration tests to run with Test Explorer under Visual Studio?

Thanks in advance.
Mar 11, 2015 at 10:15 PM
Having the same problem - the test below is stalling in VS but works if I run Mocha from the terminal.

Commenting out the line that creates connection, i.e. pool.getConnection(); in my case, prevents VS from stalling...

Any ideas?
"use strict"

var assert = require("assert");
var mysql = require("mysql");
var Q = require("Q");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");

describe("Visual Studio", function () {
    it("I am going to st-a-a-a-a-l-l", function () {
        var config = {
            host: "localhost",
            user: "uid",
            password: "pwd",
            database: "database_name",
            multipleStatements: true
        var pool = mysql.createPool(config);
        return Q.delay(true, 1000).should.eventually.equal(false);
Mar 15, 2015 at 11:55 PM
Edited Mar 15, 2015 at 11:56 PM
Given the lack of response it is safe to assume that Node JS tools for VS are still very unstable and hence not recommended for development. Stick with your CLI tools until the tools has been stabilized.
Mar 17, 2015 at 9:34 AM
Apologies for the delay - we've been heads down on other issues, and are only just getting to this one. For future reference, there's no need to extrapolate the world from a single data point. A simple 'ping' or 'bump' would have sufficed. :-)

Anyways thanks for reporting this and for bumping up the thread - I can reproduce the issue, and I'm looking into it. No workaround at the moment other than the one you already described.

I've created an issue tracking it here:

Thanks again!
Mar 17, 2015 at 12:22 PM
Edited Mar 17, 2015 at 12:26 PM
Okay, try replacing the mocha.js file in
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Node.js Tools for Visual Studio\1.0\TestFrameworks\Mocha\"


I need to add unit tests and verify the fix first, but in the meantime, please try this out on your machine to make sure you are getting consistent results between the terminal and visual studio.

EDIT: filepath
Marked as answer by mousetraps on 3/23/2015 at 11:06 PM
Mar 17, 2015 at 6:39 PM
It is working now. I can go back to my beloved VS :-) Thanks a trillion guys!!
Mar 17, 2015 at 6:43 PM
And no worries about the delayed response - we know you've got plenty of ground to cover! Thanks again for the excellent tools!
Mar 19, 2015 at 2:55 AM
Nice! I am getting my mysql integration tests to run now.

3 remaining issues (none of which may in fact have anything to do with your tool set):
  1. (Minor): The test runner seems to think all my tests are at test.js line 0. That is the correct file, but obviously not the correct line number. So when I double click a test, or click the Source: test,js line 0 link in the test information pane (just below the test explorer), I do not get taken to the correct place in the file to work on the test.
  2. (Moderate): The test explorer recognizes all my tests, but does not maintain their order. My tests need to run in a specific order (because the build upon data items that were created or removed in prior tests). Is there a way to preserve order in test explorer?
  3. (Moderate): When running these tests, VS thinks my working directory is /myproject/test, where as when I run mocha from the command line, I run it from /myproject, and then the working directory is /myproject. The problem here is that I need to change paths to config files, etc. depending on whether I am running from command line or from VS. (Maybe I just need to change some project config within VS?)
Thanks again for the great tool set and getting mysql integration to work.