Skip to content

Chutzpah File References

Matthew Manela edited this page Mar 21, 2016 · 5 revisions

One of the most important steps to having Chutzpah successfully run your tests is to set up your file references correctly. You accomplish this in two ways.

The first (and recommended) is using the references setting in the Chutzpah.json Settings File:

{
    "References": [
        { "Path": "someDependency.js" },
        { "Path": "some/folder", "Includes": ["**.js"], "Excludes": ["**Resource*"] }
    ]
    
}

This is the most clear and flexible way to add references. However, Chutzpah also supports a second way by adding a special file reference comment at the top of your files:

/// <reference path="someDependency.js" />

When Chutzpah sees this it will include that file in the generated test harness as well as recursively scan that file to find all of its references.

If you want to include a whole directory of files you can just specify a folder:

/// <reference path="some/folder" />

Chutzpah will the recursively scan that folder to find all references.

Excluding References

The reference syntax is also used by VS to give intellisense in JS files. This leads to an issue since sometimes you may reference a version of a file just for intellisense but you do not want Chutzpah to copy it. In this case you can include the chutzpah-exclude attribute to have it ignored by Chutzpah:

/// <reference path="someDependency.js" chutzpah-exclude="true" />

Alternate Reference Syntax

The reference syntax is also used by the TypeScript compiler for referencing files. This can cause an issue since Chutzpah expects you to reference your implementation files and TypeScript excepts you to reference your definition files. To mitigate this issue you can use a Chutzpah specific version of the reference command:

/// <chutzpah_reference path="someDependency.js" />

This works the same as the other syntax except that TypeScript (and VS) will ignore it.

Root Reference Path Mode

If you write a reference path like

/// <reference path="someDependency.js" />

then Chutzpah searched for that dependency relative to the current file. However, you can also specify a reference path like

/// <reference path="/someDependency.js" />

The beginning forward slash will tell Chutzpah to find that file at the root of the drive the file is in (e.g C:). This behavior is configurable using a chutpah.json file. For example if you want the rooted reference path to be relative to a different directory you can place the a chutzpah.json file in that directory with the following content:

{
    "RootReferencePathMode":"SettingsFileDirectory"
}

HTML Template Injection

Chutzpah supports injecting HTML templates you reference into the test page. You can do this through the chutzpah.json file or the reference comments. For example, below shows how to inject your html template and have it wrapped in a script tag. Read more about the configuration options here.

Using Chutzpah.json

{
    "References": [
        { "Path": "template.html", "TemplateOptions": {"Mode": "Script", "Id": "MyTemplate", "Type": "text/ng-template" }
    ]
}

Using a reference comment in a .js file

/// <template path="template.html" mode="script" id="MyTemplate" type="text/ng-template" />