TypeScript dependencies

Nov 21, 2012 at 11:30 AM
Edited Nov 21, 2012 at 11:30 AM

Hi, I just got Chutzpah working with Typescript.

However, not surprisingly, the test failed because '$' was undefined. (jQuery)

It would be nice to have somewhere to define which files should be injected in the PhantomJS engine.

 

I suggest:

A) a Chutzpah.config file in the root of the project so you could setup project-specific script dependencies

or

B) a catch-all config in the Chutzpah settings

Coordinator
Nov 29, 2012 at 5:13 PM

Does it still error if you include a /// <reference  comment for jquery?

Coordinator
Dec 11, 2012 at 4:13 PM

I think I know what the issue is and will be hopefully resolving this in the next release.

Feb 6, 2013 at 11:53 AM
caroen wrote:
Hi, I just got Chutzpah working with Typescript. However, not surprisingly, the test failed because '
was undefined. (jQuery) It would be nice to have somewhere to define which files should be injected in the PhantomJS engine.   I suggest: A) a Chutzpah.config file in the root of the project so you could setup project-specific script dependencies or B) a catch-all config in the Chutzpah settings
I think your suggestion is good.
In my typescript project,I want to test my typescript file(a.ts), but this file(a.ts) reference jquery.ts. so when I use Chutzpah to test it. It will have a error :'$ is undefined'.

I think Chutzpah should have a config to set some specific script file path. so I can reference some specifical javascript file.
Hope new release will resolve this problem.
Feb 6, 2013 at 2:19 PM
Edited Feb 6, 2013 at 2:44 PM
another option is to add new key word like "/// <reference " such as "/// <include " to specify additional js file to be included in generated file!
If we can't specify additional js files, we will only be able to test ts code write be ourselves, can't test code which call 3d part libraries such as jquery, knockout,etc.
Feb 7, 2013 at 8:34 AM
adding references to js files within your ts works fine:

/// <reference path="../libs/jquery-1.7.2.js" />
/// <reference path="../libs/jasmine.d.ts"/>
declare var $;
describe("test browser version with jquery", () => {
it("version should be 534.34", () => {
    expect($.browser.version).toBe("534.34");
});
});
Feb 8, 2013 at 2:49 PM
Yes you can add .js as references but look at the errors log and it will be full or errors typescript has reported because it thinks it should compile the .js as as .ts.

Anybody got any ideas on how to get around this. I have the same problem and have not resolved it yet.
Coordinator
Feb 8, 2013 at 2:53 PM
Are you saying Chutzpah is trying to compile the .js files as ts? I don't think it does that. Could you give me a sample project to test with?
Feb 9, 2013 at 6:53 AM
I am saying that typescript is trying to compile .js files

My understanding is ...
• chutzpah needs 'reference' to d.ts files to run tests
• the tests are failing because there are variables that cannot be found
• adding 'reference' to the .js of d.ts associated with the errors fixes it
• but now typescript tries to compile the added .js
• because typescript also uses 'reference' to compile at dev time to give you intellisense
• therefore many errors are put in the error list for things like jquery, knockout, underscore
Coordinator
Feb 9, 2013 at 8:26 PM
Could you provide me with a sample project that demonstrates your issue so I can test with it?
Feb 11, 2013 at 8:29 AM
how do I send you an example project?
Feb 11, 2013 at 9:20 AM
If you look at the default jasmine example files you'll notice that the SpecRunner.cshtml file includes it's own references to included js library files (like jquery, knockout, underscore).

This ability is missing in the Chutzpah runner , there is no way to specify dependent js libraries.
Coordinator
Feb 11, 2013 at 2:41 PM
You can send me a sample either by
  1. Upload it to a file sharing site and send me a link
  2. File an issue on this site and attach the file
  3. Upload it as a github repo
Coordinator
Mar 1, 2013 at 3:19 PM
Edited Mar 1, 2013 at 5:10 PM
Hey jbyfordrew,

I got your repro and have checked in a solution for it. You are correct about the issue. Both typescript and Chutzpah are trying to use the <reference comments for their own competing needs. I added a new feature for chutzpah that lets you optionally write
/// <chutzpah_reference path="foo.js" />
Chutzpah will parse these and typescript will not.

Do you think that will work?
Mar 1, 2013 at 5:06 PM
Yep I expect so. Thanks, can't wait to check out the latest code and all my erroneous errors will go. Thanks again.
Mar 6, 2013 at 11:11 AM
Hi mmanela,

When do you think you'll get a new version up to download?
Coordinator
Mar 8, 2013 at 3:49 PM
There are a few more features I would like to get done before the release but if this is blocking you I can get you a adhoc drop.
Mar 29, 2013 at 1:04 PM
I've added the references to the JS files as a comment in my TS file like this:
/*
/// <reference path="my_js_file.js"/>
*/
I originally did this so I could just remove the / / from the generated .js file and be able to run my tests. Ever since I've added them it just works, even without removing the / /. I am using the VS2012 Test Explorer and it just picks up new test cases whenever I save my TS file and I never have to fix the references the this JS files that I need in order to run the tests. Perhaps this will work for others as well.
Apr 13, 2013 at 9:39 PM
@tbusser, Thanks, using / / to hide the library javascript declaration from typescript (but not chutzpah) worked for me, too:
/// <reference path="../CodeUnderTest.ts" />
/// <reference path="../lib/jquery.d.ts" />
/// <reference path="jasmine/jasmine.d.ts"/>
/*
/// <reference path="c:\dev\Bloom\web\Scripts\lib\jquery-1.9.1.js"/>
*/
The planned solution, "/// <chutzpah_reference=", though, doesn't seem to be shipping yet.
Coordinator
Apr 13, 2013 at 11:38 PM
The Chutzpah_reference syntax is checked in and I hope to have the release out within the next 2 weeks
Coordinator
Apr 24, 2013 at 3:05 PM
Version 2.4 is now released so you can use the chutzpah_reference syntax:
/// <chutzpah_reference path="thing.js" />
Apr 24, 2013 at 3:14 PM
@mmanela Thanks for that!
May 10, 2013 at 3:34 AM
Edited May 10, 2013 at 3:36 AM
Hi everyone!
Finally I got the place where i think someone can help me..
I am working on a new project where i am using asp.net mvc +hot towel template. I am trying usechutzpah for my viewmodels... sadly my viewmodles are AMD modules so I am getting problems because i think chutzpah is not able to load require.js library... am i right? ...
is there some posibility for chutzpah run Qunit Tests (tests builded using typescript) for AMD modules?.

See :
Br,
Rolando
Coordinator
May 11, 2013 at 11:51 PM
The answer given on the StackOverflow page:
Just adding an import statement doesn't include an AMD module - you need a loader such as require.js to do that.

A bit of Googling throws up this https://github.com/jrburke/requirejs/wiki/Test-frameworks which may help you get QUnit working with async modules.

And this discussion about using Chutzpah with Require, which links to this example.