Latest Chutzpah Feature, JavaScript Unit Testing

Chutzpah (pronounced: hutz·pah) — is a Visual Studio extension that ties into both the context menus and the Test Explorer window of the IDE.

Chutzpah is an open source JavaScript test runner which enables you to run unit tests using QUnit, Jasmine, Mocha, CoffeeScript and TypeScript.

To install these extensions navigate to Tools › Extensions and Updates... within Visual Studio. This will open the dialog, first select Online from the tabs on the left then in the top-right hand corner search for “chutzpah”. Install both and then restart Visual Studio.

vs-extensions

These extensions are great for executing JavaScript tests and they have already served me well. I discovered an issue recently though as it pertains to Google Chrome, I know what you’re thinking “usually when someone runs into browser issues they’re talking about IE” — not this time!

The issue is when you attempt to debug the JavaScript source code with the “Open in browser” context menu feature. This launches your computer’s default browser, mine being google chrome. A quick note, when you run the tests outside the context of the “Open in browser” feature it executes them headless via PhantonJS — and there are no issues.

Google Chrome added a security feature a long time ago, but they added a flag (cmd line switch) that will override this behavior. The security change works to prevent the file:// protocol from accessing other files on the system. The flag to override this behavior is as follows:

--allow-file-access-from-files

Here are a few more details on this flag.


I attempted to follow all of the suggested methods for adding this switch to the registry and shortcuts, and custom launch args — everything. Still it didn’t work with this Chutzpah feature. I then decided to take action! Being that Chutzpah is open source and we are using it, I thought it best to contribute a new feature.

Here is the error that Chrome displays in its Developer Tools (F12) window.

chutzpah

After this error is encountered the browser window displays nothing at all. Now with version Chutzpah 4.2.0 the chutzpah.json configuration file accepts browser arguments that are then passed into the launching of the browser — it looks like this.

That is basically it, once the Chutzpah test runner parses your configuration file — it will use the given browser arguments when executing the test. You then get the expected test results in the Chrome browser window.

chutzpah-results

Advertisements