5

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?

Community
  • 1
  • 1
Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • - did you ever get a resolve for this? Looks like R# 10 still struggles when the d.ts files are managed via nuget. – BMac Feb 17 '16 at 16:23

2 Answers2

6

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.

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • Very useful. I was having this problem trying to run with Chutzpah a Typescript code for Mocha. Now is solved. – Aebsubis Oct 24 '14 at 16:25
  • From what I can tell, R# has never actually fixed this. Their suggested workaround is an ugly hack that requires you to copy the corresponding .js file to wherever the .d.ts file is located. This not only assumes that there *is* a corresponding .d.ts file, but also doesn't work when you're using nuget to manage your DefinitelyTyped definitions. – Ken Smith Feb 14 '16 at 04:32
0
///<reference path="~/Scripts/sinon-1.9.0.js"/>

You can't do this in a TypeScript file as reference is a language feature reserved for .ts and .d.ts.

Also '~/Scripts/' seems wrong from the get go. Resharper will index All js files included in your Visual Studio project and provide you intellisence, no comments necessary.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • 1
    Just to be clear - I'm not looking for Intellisense. I'm trying to figure out how to get Resharper's test runner to run my Jasmine unit tests that have dependencies on other libraries, such as sinon. When I run my tests with Chutzpah, I specify those dependencies in the page that gets loaded by PhantonJS. But Resharper runs the script directly in PhantomJS with no intermediate page, and so the only way to specify the dependencies (that I can find) is via the `///` doc comment. I know TS won't allow this - so what I want to know is - how do I accomplish this? – Ken Smith Apr 01 '14 at 00:02
  • And `resharper` test runner picks up `/// ` ? If so does it still work after you remove `///`? – basarat Apr 01 '14 at 09:07
  • Well, Resharper's test runner is *supposed* to pick up `///`. In my testing - inserting it manually into the generated javascript - it doesn't seem to be. Not sure why. I've asked this same question on the Resharper boards - if I hear back a good answer, I'll cross-post it here. – Ken Smith Apr 01 '14 at 17:00