Chutzpah 2.4.3

This release of Chutzpah contains a few bug fixes, upgraded versions of Blanket.js and TypeScript and a new feature for injecting HTML templates.

TypeScript Upgraded

Chutzpah now uses TypeScript 0.9.0.1. This change may require an update for your .ts files. In this version of TypeScript the compiler errors if you do not specify the .d.ts file corresponding to your third party JS library. For example, if you are using QUnit you must reference the QUnit.d.ts file.

Improved Code Coverage

Code coverage has improved with two changes. The version of Blanket.js was upgraded to 1.1.5. In addition, Chutzpah will now prevent files you exclude from code coverage from getting instrumented. This helps improve performance of the coverage runs.

HTML Template Feature

This feature came in as pull request from Matthew Osborn. This allows you to specify an HTML template file from your tests. Chutzpah will inject this templates content into the head section of the generated test harness. For example, lets say you have an HTML template file named template.tmpl.html with the contents:

<script id="testTemplateId" type="text/html">
    <div id="testTemplateDiv">
        Cool!
    </div>
</script>

Then you can reference this file from your test with the syntax:

/// <template path="template.tmpl.html"/>

For example, this is a test case I wrote in Chutzpah to assert this feature works correctly:

/// <reference path="qunit.js" />
/// <template path="template.tmpl.html"/>
/// <reference path="../jquery-1.7.1.min.js" />

module("Html Template Test - QUnit");
test("Will load html template", function () {
    // Grab template text, convert to html, append to body
    $($("#testTemplateId").text()).appendTo("body");

    var templateDiv = $("#testTemplateDiv");

    equal(templateDiv.length, 1);
});

Which results in an HTML test harness which looks something like this:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="qunit.css"/>
  <script type="text/javascript" src="qunit.js"></script>
  <script id="testTemplateId" type="text/html">
      <div id="testTemplateDiv">
          Cool!
      </div>
  </script>
  <script type="text/javascript" src="query-1.7.1.min.js"></script>
  <script type="text/javascript" src="template-qunit.js"></script>
</head>

<body>
    <h1 id="qunit-header">Unit Tests</h1>
    <h2 id="qunit-banner"></h2>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture"></div>
</body>
</html>

The content from the template was injected into the head section above. This ability is useful for things like jQuery widgets and JS template renderers.

 

12 thoughts on “Chutzpah 2.4.3

  1. Hi,
    is there any chance that you will support testing for node project. So that I can inspect result in Visual Studio for jasmine-node?

    and by the way, this is really a great extension
    :)

    1. That is a feature I would love to get to. I can’t commit to when but its up there on the list of things I want to add. If you are interesting feel free to create a fork and experiment with this functionality yourself.

  2. Hi,
    The latest release breaks all my tests that use AngularJS. I suspect it is the new version of blanket.js, which is complaining that AngularJS is reassigning the ‘window’ variable: angular.js v1.1.3, line 1048: function setupModuleLoader(window).
    Is there any way to revert to the previous version of Chutzpah until this is fixed?

    1. Wow, I can’t thank you enough for the 2.4.1 installer. I will save a copy of it this time :)

      The code I am working on is under NDA but I will try to create a sample project for repro and file it on Codeplex for you. I think notifying Blanket.js is a good idea too. Or maybe the Google guys who wrote Angular.

      I read the error message from the Test output in VS2012 and it pointed me to the line 1048 in angular.js (Google’s own code) that had a function parameter called ‘window’. Looking at the source of the error message I also confirmed it was being reported by blanket_jasmine.js, lines 4241-4256.

      Cheers

    2. Sorry forgot to say – no it was preventing me from running the tests at all. When I go to Test Explorer and click Run All, the C# tests run fine but then there are a bunch of timeout errors and messages dumped to the Test output and the Jasmine tests won’t run at all. I think that is because it runs the tests through code coverage at the same time?

    3. Well this is frustrating. I am still having the issue with 2.4.3 but am unable to repro the issue in a new project. 2 things are happening: first, it’s not automatically running code coverage when I click ‘Run All’ from Test Explorer (but it does do that from my real project). Second, the tests are running just fine with an AngularJS controller and service dependency (still breaking on my real project).

      The exact error message is:

      Log Message: waiting for blanket… from c:\dev\project\system\website\scripts\unit-tests\jasmine\section\ctrlspec.js
      JS Error: Error: Instrumentation error, you cannot redefine the ‘window’ variable in file:///c:/dev/project/system/website/scripts/lib/angular/angular.js:1048
      in file:///C:/USERS/USER/APPDATA/LOCAL/MICROSOFT/VISUALSTUDIO/11.0/EXTENSIONS/********.ATP/TestFiles/Coverage/blanket_jasmine.js (line 4253)
      While Running:c:\dev\project\system\website\scripts\unit-tests\jasmine\section\ctrlspec.js

      The error seems to cycle between “Instrumentation error”, “error loading source script” and “Timeout occured when executing test file” for each spec file in the project.

      I will try again tomorrow (but soon I probably will have to pick this up in my own time). Thanks

    4. That is odd. Chutzpah should only have anything to do with Blanket.js when you explicitly run code coverage. So it looks like their might be two issues

      1. Chutzpah is someone running code coverage when it shouldn’t
      2. Blanket.js might have an issue with Angular.js

    5. I can’t figure out why Chutzpah wants to run tests through blanket when I click “Run All”. I tried in my real project deleting all but one test (expect(true).toBe(true)), but it still wants to analyse code coverage when I Run All. I can’t repro this behaviour in my sample project, nor can I find any setting anywhere that should trigger code coverage analysis when I Run All. It does not analyse code coverage for the C# tests either. I wish I could send you the solution but unfortunately I will have to leave this one up to you to investigate the logic contained within Chutzpah to see if there are any edge cases where it might run tests through blanket when Run All is activated in VS2012 Premium (I also have ReSharper 7.1.3 but AFAIK it does not interact with Test Explorer). If you manage to work it out, let me know as it’s somewhat annoying that it pops open the browser every time we run our tests.

      If I just run some tests by right-clicking on them in the Test Explorer and choose Run Selected Tests, then code coverage does not open and the tests run fine. However even in my sample project, if I manually run Analyze Code Coverage for Selected Tests and the spec references angular.js it will not run the tests and the error messages appear in the Test Output. This seems to indicate that there is indeed an incompatibility between Angular and the new version of Blanket.

      For now I am happy to live with 2.4.1 and I can’t thank you enough for it. I will report the issue to Blanket and also Angular and maybe they can sort it out between themselves.
      Cheers

Comments are closed.