Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing external script with Resharper/Jasmine/TypeScript

According to this question, the way to get Resharper's test runner to recognize script dependencies in your jasmine test scripts is to include them in a doc comment, like so:

// include external files like so:
/// <reference path="/path/to/external-file.js" />

// than write your testing suite as usual:
describe('a silly suite', function() {
    it('should test something is happening', function() {
        expect(something).toBe('happening');
    });
});

That's great, but I'm writing my jasmine tests in TypeScript, with a test that looks kinda like so:

///<reference path="../../../Scripts/typings/jasmine/jasmine.d.ts"/>
///<reference path="../../../Scripts/typings/sinon/sinon.d.ts"/>
///<reference path="../../../Scripts/Payboard/Models.ts"/>
///<reference path="../EventReferences.ts"/>

describe('Payboard.Events', () => {

var server: SinonFakeServer;

beforeEach(() => {
    Payboard.Events.setApiKey('apikey');
    server = sinon.fakeServer.create();
});

afterEach(() => {
    server.restore();
});

describe('#getAbsoluteUrl', () => {
    it('should prepend app.payboard.com to the relative url', () => {
        var absoluteUrl = Payboard.Events.getAbsoluteUrl('/some/random/url');
        expect(absoluteUrl).toEqual('//app.payboard.com/some/random/url');
    });
});

and when I include references like ///<reference path="~/Scripts/sinon-1.9.0.js"/>, I get a TS compile message:

Incorrect reference. Only files with a .ts extension are allowed.

In other words, TS doesn't let me include .js files in doc comment reference tags.

Any suggestions for a workaround?

like image 690
Ken Smith Avatar asked Mar 31 '14 20:03

Ken Smith


1 Answers

It looks as if this is a known issue:

http://youtrack.jetbrains.com/issue/RSRP-389196

What they're going to have to do is add support for something like this:

/// <resharper_reference path="Scripts/jquery-1.8.2.js" />
/// <resharper_reference path="Scripts/MyClassUnderTest.js" />

Chutzpah already supports this format, so it would be nice if Resharper picked those up as well:

/// <chutzpah_reference path="Scripts/jquery-1.8.2.js" />
/// <chutzpah_reference path="Scripts/MyClassUnderTest.js" />

The workitem says that it'll be addressed in Resharper 9.0.

It's also possible to hack up a workaround where you copy sinon.js to sinon.d.js, and then put sinon.d.js in the same folder where sinon.d.ts is located.

like image 196
Ken Smith Avatar answered Nov 15 '22 05:11

Ken Smith