mmanela / chutzpah

Chutzpah is an open source JavaScript test runner which enables you to run unit tests using QUnit, Jasmine, Mocha and TypeScript.
http://mmanela.github.io/chutzpah/
Apache License 2.0
550 stars 142 forks source link

VS 2019 - Open in browser works, runner does not #773

Closed djjohnjoseph closed 4 years ago

djjohnjoseph commented 4 years ago

Can someone point me in the right direction of how to get this working under VS 2019 using the context menu test runner?

I have a .NET Core 3.0 MVC app and am trying to test some javascript compiled from typescript (MSBuild which compiles on save) - Jasmine nuget pacakage 2.6.4.

chutzpah.json (in the project root):

 {
   "Framework": "jasmine",
   "EnableTestFileBatching ": true,
   "RootReferencePathMode ": "SettingsFileDirectory",
   "Compile": {
     "Mode": "External",
     "Extensions": [ ".ts" ],
     "ExtensionsWithNoOutput": [ ".d.ts" ]
   },
   "References": [
     {
       "Path": "scripts/compiled/site.js"
     }
   ],
   "Tests": [
     {
       "Includes": [ "*.spec.js" ],
       "Path": "scripts/tests",
       "ExpandReferenceComments": true
     }
   ]
 }

Project structure:

scripts/
--compiled/
    -- site.js
--tests/
   --app.spec.js
app.ts
ajax.ts

Using the context menu to 'Open in Browser' on the app.spec.js file passes tests. Selecting 'Run JS Tests' however returns an 'Cannot find variable: 'Format'.

app.spec.js:

/// <reference path="../compiled/site.js" />
describe("Format Tests", function () {
    it("Can format a variable in a message", function () {
        var message = "Request failed: {0}";
        var replacement = "Reason";
        var result = "Request failed: Reason";

        expect(Format(message, [replacement])).toBe(result);
    });

    it("Does not replace without placeholder", function () {
        var message = "Request failed:";
        var replacement = "Reason";
        var result = "Request failed:";

        expect(Format(message, [replacement])).toBe(result);
    });
});

compiled/site.js (extract)

function Format(pattern, ...variables) {
    return pattern.replace(/{(\d+)}/g, (match, index) => {
        return typeof variables[index] !== undefined ? variables[index] : match;
    });
}

Stack trace in VS output:

ReferenceError: Can't find variable: Format in file:///C:/Users/test/source/repos/CCBCForms/src/CCBCForms/scripts/tests/app.spec.js (line 8)
attempt@file:///c:/users/test/appdata/local/microsoft/visualstudio/16.0_0b2fdc68/extensions/ubcahz0h.iup/ChutzpahTestHarnessFiles/jasmine/v2/jasmine.js:4478:50
run@file:///c:/users/test/appdata/local/microsoft/visualstudio/16.0_0b2fdc68/extensions/ubcahz0h.iup/ChutzpahTestHarnessFiles/jasmine/v2/jasmine.js:4402:27
execute@file:///c:/users/test/appdata/local/microsoft/visualstudio/16.0_0b2fdc68/extensions/ubcahz0h.iup/ChutzpahTestHarnessFiles/jasmine/v2/jasmine.js:4384:13
queueRunnerFactory@file:///c:/users/test/appdata/local/microsoft/visualstudio/16.0_0b2fdc68/extensions/ubcahz0h.iup/ChutzpahTestHarnessFiles/jasmine/v2/jasmine.js:964:42
execute@file:///c:/users/test/appdata/local/microsoft/visualstudio/16.0_0b2fdc68/extensions/ubcahz0h.iup/ChutzpahTestHarnessFiles/jasmine/v2/jasmine.js:563:28

I'm stuck as to why the app.spec.js file doesn't seem to be picking up that compiled file that is referenced both using the <reference path> and the References section within the chutzpah config file.

Can anyone shed any light?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.