Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chutzpah and Jasmine 2.0 and RequrieJs

I'm having some bother getting Chutzpah to work with requireJs/jasmine 2.0. This method worked for version 1.3 but now for jasmine version 2.0 chutzpah has stopped picking up the tests. I upgraded chutzpah to 3.1.1 for the jasmine 2.0 support as well. I did have to make a small change to load jasmine from requireJs to make it work but I figured this shouldn't affect chutzpah as it was just loading the html.

Here's the command I run for chutzpah.

chutzpah.console.exe path/to/SpecRunner.html

The console now fails to pick up tests

=== 0 total, 0 failed, took 0.25 seconds ===

But when I run the actual html file it finds the tests

Jasmine example

Any help would be greatly appreciated


Instead of the HTML route I've been trying just the chutzpah built in configuration

{
    "Framework": "jasmine",
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "Tests": [
        {"Path" : "Specs/example.spec.js"}, 
    ],
    "References" : [
        {"Path" : "../../../Scripts/lib/require/require.js" }, 
        {"Path" : "../../../Scripts/app/app.js" }
    ]
}

This runs however I'm getting an error

Error: Error: Script error for: specs/example.spec

Error: Timeout occured when executing test file
While Running:C:\path\to\specs\example.spec.js

System.AggregateException: One or more errors occurred. 
---> System.NullReferenceException: Object reference not set to an instance of an object.

at Chutzpah.FileProbe.<FindScriptFiles>d__1a.MoveNext() in c:\Dev\chutzpah\Chutzpah\FileProbe.cs:line 159

The path here is definitely correct as i've copied and pasted it into an explorer window just to make sure.

The test is a simple compiled coffeescript file which looks like this

(function() {

  define([], function() {
    return describe('==== example test ====', function() {
      return describe('the test should', function() {
        return it('showcase toBe', function() {
          return expect(true).toBe(true);
        });
      });
    });
  });

}).call(this);

And I'm certain that this works as it's passing in my browser html based equivalent.


This was my final configuration that works with html. I couldn't get it to work with just the config discovering the tests. Hopefully this will be resolved when item 214 is resolved as in the below answer

{
    "Framework": "jasmine",
    "RootReferencePathMode": "SettingsFileDirectory",
    "TestHarnessReferenceMode": "AMD",
    "TestHarnessLocationMode": "SettingsFileAdjacent",
    "Tests": [
        { "Path" : "specrunner.html" }
    ],
    "References" : [
        {"Path" : "../../../Scripts/lib/require/require.js" }, 
        {"Path" : "../../../Scripts/app/app.js" }
    ]
}
like image 864
Neil Avatar asked Feb 28 '14 09:02

Neil


1 Answers

I looked into your code and here is what I found

Running HTML

This works fine if you make a couple small changes. 1. Your tests setting in the chutzpah.json file has a trailing comma. This exposes a bug where the deserializer returns this as a null entry and chutzpah isnt handling it. I will fix this issue but you can just delete the extra comma. 2. Once I deleted that command I saw that your chutzpah.json file has a tests setting that is listing just the .js file. But when running the html file then that is your test file. So your chutzpah.json is filter it out. If you update the tests setting to point to the html file this works.

Once I made those changes the test ran successfully.

Running Chutzpah.json

Looking into this the way you load the example.spec in SpecRunner you reference the .js extension in your require call. This tells require.js to ignore the baseurl and look at the file relative to current location. When you have chutzpah generate the test harness it generates a require call without extension. This means that file needs to be able to be loaded given the current baseurl setting.

Now there is a bug in chutzpah where it doesn't understand baseurls. See https://chutzpah.codeplex.com/workitem/214. The planned solution is to allow you to tell chutzpah in the chutzpah.json file what your baseurl is. Without that it is still possible to get this to work but you would need to tell chutzpah to place its generated .html file where your baseurl would point.

Let me know if that helps.

like image 84
Matthew Manela Avatar answered Oct 10 '22 04:10

Matthew Manela