hbenl / vscode-jasmine-test-adapter

Jasmine Test Adapter for the VS Code Test Explorer
MIT License
20 stars 20 forks source link

trouble with initial setup for vs code TypeScript tests #37

Closed grapevinegizmos closed 4 years ago

grapevinegizmos commented 4 years ago

I am moving from various IntelliJ dev environments to VS Code and the config its all a bit mysterious to me, but as a complete newbie, I can't quite figure out how to get jasmine tests running. but I have so far been able to compile and run Typescript files

I followed your guidance on installation (install/restart/press run debug button on the test explorer) but nothing happens. Right now I have only one simple test in /spec/test/classes.spec.ts

I read previous comment - "Not fully understanding how to setup" where you suggest running jasmine init to create the file, but it doesnt create a spec/support/jasmine.json. Instead it looks like it creates rubyish support files (jasmine_helper.rb and jasmine.yml.) Not sure whether rthat is by design or Ive got something configured wrong. Is there some guide somewhere that has sep by step instructions for necessary configuration for TyepScript testing? Or can you lead me in right direction?

hbenl commented 4 years ago

I read previous comment - "Not fully understanding how to setup" where you suggest running jasmine init to create the file, but it doesnt create a spec/support/jasmine.json. Instead it looks like it creates rubyish support files (jasmine_helper.rb and jasmine.yml.)

Apparently you have Jasmine for Ruby installed and called that when you ran jasmine init. Try installing Jasmine for Node in your project with npm install --save-dev jasmine and then run ./node_modules/.bin/jasmine init.

To enable support for Typescript, you can npm install --save-dev ts-node and set the helpers property in spec/support/jasmine.json to [ "../node_modules/ts-node/register" ].

None of this is specific to this extension, this is for configuring the command line version of jasmine, once the command line version works, the extension should automatically work as well.

grapevinegizmos commented 4 years ago

Thank you., appreciate the guidance. It seemed to be working there for a minute, but now it getting hung up on importing a module I think.

I am working in typescript and I am importing some classes for testing in Jasmine. I had to set tsconfig "module" option to "amd" in order to run AngularJs, but now when I run jasmine from the terminal I run into a reference error "define is not defined" which seems to have something to do with "require.js" or "module":"amd". This is all pretty much still greek to me, but the error it encounters when it tries to run the spec is ts compiles to javascript test which looks like this:

define(["require", "exports", "../fringe"], function (require, exports, fringe_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    describe('Fringe', function () {
        it("returns a name", function () {
            let f = new fringe_1.Fringe("Frank");
            expect(f.name).toEqual("Franok");
        });
    });
});

When I run the test from the command line using node -r ts-node/register ./node_modules/.bin/jasmine a reference error is thrown "define is not defined".

Any thoughts appreciated. I 've been struggling with this for days now.

hbenl commented 4 years ago

Sorry, I'm not really a Jasmine (or Angular) expert, so I can't really help here. Trying to test code in Node that was written for the browser can be very challenging. In fact, I would advise against it and would either try to refactor the code so that the part which you want to test doesn't depend on Angular or try using a test framework for the browser. There is a test adapter for Karma, so perhaps that could help.

grapevinegizmos commented 4 years ago

Ok understood –

On another note, with respect to your extension in particular, I’ve been running the jasmine tests in the commandline with “node -r ts-node/register ./node_modules/.bin/jasmine” and they are now passing, specs arent’ showing up in the explorer for some reason. Some setting to deal with that? Previously when I had the been able to run the tests from the extension, they ran (very nice, thanks), but I couldn’t see the console output to see the failures. So Ihad to run them from theconsole. Is that the intended workflow?

PS> What I’m doing with jasmine is not so much testing the angular code as unit testing the ts classes that are used by the angular code. The issue is trying to have both jasmine unit tests and the AngularJS application within the same workspace. I did discover the cause of the problem, although I don’t yet have solution. In order for AngularJS to work properly, I need to set “module”:”amd” in tsconfig. If module is set to commonJs, the jasmine tests work, but I can no longer run the application with live server chrome. So I am having to change configuration to run jasmine test, but at least they run. Maybe stackoverflow knows.

From: Holger Benl notifications@github.com Reply-To: hbenl/vscode-jasmine-test-adapter reply@reply.github.com Date: Wednesday, December 18, 2019 at 11:06 AM To: hbenl/vscode-jasmine-test-adapter vscode-jasmine-test-adapter@noreply.github.com Cc: Josh Kramer josh@grapevinegizmos.com, Author author@noreply.github.com Subject: Re: [hbenl/vscode-jasmine-test-adapter] trouble with initial setup for vs code TypeScript tests (#37)

Sorry, I'm not really a Jasmine (or Angular) expert, so I can't really help here. Trying to test code in Node that was written for the browser can be very challenging. In fact, I would advise against it and would either try to refactor the code so that the part which you want to test doesn't depend on Angular or try using a test framework for the browser. There is a test adapter for Karma, so perhaps that could help.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/hbenl/vscode-jasmine-test-adapter/issues/37?email_source=notifications&email_token=ACCIEBL6QFSCMFJXYNQI6HLQZJYD7A5CNFSM4J2Y2BTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHHEXIY#issuecomment-567167907, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACCIEBPCFHTPG4DSIAVBI5TQZJYD7ANCNFSM4J2Y2BTA.

hbenl commented 4 years ago

I’ve been running the jasmine tests in the commandline with “node -r ts-node/register ./node_modules/.bin/jasmine” and they are now passing, specs arent’ showing up in the explorer for some reason

You need to run Jasmine from the extension for the results to show up in the extension. If you run Jasmine from the command line, there is no way for the extension to access the results.

when I had the been able to run the tests from the extension, they ran (very nice, thanks), but I couldn’t see the console output to see the failures

The output should be shown in VS Code's status bar when you click on a failed test in the Test Explorer or the "Show Log" code lens in the editor. Furthermore, there is the "Jasmine Tests" output channel (in the "Output" tab of the status bar), which contains the complete output from the test runs.