Cross Project TypeScript Unit Testing – Part 2

Part 1 of this post focused on cross project TypeScript (TS) referencing, this post will focus on how this can be used with Chutzpah to conduct cross project unit testing. Chutzpah is a TS, CoffeeScript and JavaScript unit test runner, with a built in Visual Studio extension and command line runner.

In the last post I used “Link Referencing” to compile TS over two projects, but this will not be enough for Chutzpah to run any unit tests written in Project B. The test runner needs all the following files to run:

  • The TS file being tested
  • Any definitely typed files being used
  • JS files behind the above definitely typed files

If you have already got TS installed and are writing unit tests using one of the supported frameworks (QUnit, Jasmine, Mocha), then we are ready to get Chutzpah running your tests headless inside Visual Studio (VS) or via command line.

In order to run unit tests with Chutzpah inside VS you need to download both or one of the below extensions:

  • Chutzpah Test Adapter for the Test Explorer
  • Chutzpah Test Runner Context Menu Extension

I would recommend both. The ‘Test Explorer’ extension allows tests to be run headless along side your other unit tests, and the ‘Test Runner’ allows you to run tests in the output window or inside a browser which is needed for debugging. Once they are both installed the ‘Test Explorer’ extension will automatically discover your tests and allow them to run inside the VS test explorer.

Continuing with the solution used in the previous post (and shown below), all of our unit tests have been written in Project B but the code being tested is in Project A. Although this now compiles inside VS, the test will not run automatically though Chutzpah.

Project Structure

If you attempt to run the run the tests (right click, ‘Run JS Tests’) you will get the error detailed below, this is caused because the extensions do not know where the files being tested, and any external libraries are located.

Chutzpah Error

This can be solved using the ‘reference’ tags detailed in the previous post, alongside the ‘chutzpah_reference’. As stated in part one this approach will quickly become unmanageable.

Reference Tags

The solution to this issue was found through the use of the ‘Chutzpah.json’ settings file. This file can be added inside any directory above the unit tests, and the most direct file from the unit test will be used. Within the file an array of references can be provided using file paths and wildcarding.

Chutzpah JSON

Inside the Chutzpah file we can detail where to find the TS files being tested, any typings and the external libraries. All sub folders inside any folder referenced will be scanned for files matching the ‘Include’ rule . This will now automatically pick up any new files created, removing the maintenance cost of updating this file.

Tests can now be run using the runner as shown above or inside the test explorer as shown below. This settings file will also be used when run from command line.

Test Explorer



  1. […] Cross Project TypeScript Unit Testing – Part 2 (Martyn Frank) […]

  2. […] Cross Project TypeScript Unit Testing – Part 1 Cross Project TypeScript Unit Testing – Part 2 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: