I'm trying to debug some Jasmine tests that I have written using WebStorm 2016.1.2.
My test code looks like this:
var should = require("should");
var myLib = require("../my-lib");
describe("Scenario", () => {
it("works as expected", () => {
myLib.do().should.not.throw()
});
});
My directory structure looks like this:
│
├───node_modules
│ ├───.bin
│ ├───aws-sdk
│ │ └───<snip>
│ ├───jasmine
│ │ └───<snip>
│ ├───jasmine-core
│ │ └───<snip>
│ ├───karma
│ │ └───<snip>
│ ├───karma-jasmine
│ │ └───<snip>
│ ├───should
│ │ └───<snip>
│ └───sinon
│ └───<snip>
├───spec
│ ├───support
│ │ └───jasmine.json
│ └───my-lib.spec.js
└───my-lib.js
And my NodeJS settings in WebStorm look like this:
To debug I'm just hitting F5 and choosing the my-lib.spec.js
file to run. I Then get the following stack trace:
"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.2\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=22714 my-lib.spec.js
Debugger listening on port 22714
c:\Users\<me>\WebstormProjects\my-lib\spec\my-lib.spec.js:4
describe("Scenario", () => {
^
ReferenceError: describe is not defined
at Object.<anonymous> (c:\Users\<me>\WebstormProjects\my-lib\spec\<my-lib>.js:4:1)
at Module._pile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.runMain [as _onTimeout] (module.js:442:10)
at Timer.listOnTimeout (timers.js:92:15)
Process finished with exit code 1
If anyone knows how to make WebStorm recognise that Jasmine is installed globally that'd be great.
EDIT: I've set up a Karma run configuration as suggested by lena with the following configuration:
When I hit F5 to run this, a Chrome browser pops up and is blank (I have the JetBrains plugin for Chrome installed)
I'm trying to debug some Jasmine tests that I have written using WebStorm 2016.1.2.
My test code looks like this:
var should = require("should");
var myLib = require("../my-lib");
describe("Scenario", () => {
it("works as expected", () => {
myLib.do().should.not.throw()
});
});
My directory structure looks like this:
│
├───node_modules
│ ├───.bin
│ ├───aws-sdk
│ │ └───<snip>
│ ├───jasmine
│ │ └───<snip>
│ ├───jasmine-core
│ │ └───<snip>
│ ├───karma
│ │ └───<snip>
│ ├───karma-jasmine
│ │ └───<snip>
│ ├───should
│ │ └───<snip>
│ └───sinon
│ └───<snip>
├───spec
│ ├───support
│ │ └───jasmine.json
│ └───my-lib.spec.js
└───my-lib.js
And my NodeJS settings in WebStorm look like this:
To debug I'm just hitting F5 and choosing the my-lib.spec.js
file to run. I Then get the following stack trace:
"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.2\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=22714 my-lib.spec.js
Debugger listening on port 22714
c:\Users\<me>\WebstormProjects\my-lib\spec\my-lib.spec.js:4
describe("Scenario", () => {
^
ReferenceError: describe is not defined
at Object.<anonymous> (c:\Users\<me>\WebstormProjects\my-lib\spec\<my-lib>.js:4:1)
at Module._pile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.runMain [as _onTimeout] (module.js:442:10)
at Timer.listOnTimeout (timers.js:92:15)
Process finished with exit code 1
If anyone knows how to make WebStorm recognise that Jasmine is installed globally that'd be great.
EDIT: I've set up a Karma run configuration as suggested by lena with the following configuration:
When I hit F5 to run this, a Chrome browser pops up and is blank (I have the JetBrains plugin for Chrome installed)
Share Improve this question edited May 27, 2016 at 16:33 brimble2010 asked May 27, 2016 at 15:32 brimble2010brimble2010 18.4k7 gold badges29 silver badges47 bronze badges 4- Shouldn't you be using mocha along with should? – Jonathan Eustace Commented May 27, 2016 at 15:36
- Can you just require('jasmine'); in the test file? – joshvito Commented May 27, 2016 at 15:44
- Were you able to figure it out ? – coding_idiot Commented Jun 27, 2018 at 22:57
- From the answer from @lena, I started using Karma to get this to work. – brimble2010 Commented Jun 28, 2018 at 8:25
5 Answers
Reset to default 2You are using Node.js run configuration to run your tests - and Node knows nothing about your test framework. You should be using a test runner (karma, for example - as you have karma installed). Try using karma run configuration. See https://confluence.jetbrains./display/WI/Running+JavaScript+tests+with+Karma.
BTW, if you like using Should with karma, try karma-should
Try using jasmine-node
module.
It depends on the mand send to the js file when you press F5. It needs to be jasmine-node <test files>
not node <test files>
.
Try doing that in the console/terminal and see if it works. It could be web storm sending the wrong mand.
If you haven't got jasmine node installed you can do
npm install jasmine-node -g
use mocha test.js
, not node test.js
To find the answer to this, I ran DiffMerge on my project root and a new Angular CLI project created in Webstorm that properly detected jasmine types.
What I found is that the tsconfig.json
and tsconfig.spec.json
files from my project defined typeRoots
and types
, whereas the other project did not.
The behavior of the typeRoots
option is:
If typeRoots is specified, only packages under typeRoots will be included.
Types
behaves a similar way.
Typescript documentation goes on to say:
By default all visible ”@types” packages are included in your pilation. Packages in node_modules/@types of any enclosing folder are considered visible.
So, for my project, this behavior is good enough for me. Deleting typeRoots
and types
from both my tsconfig.json
and tsconfig.spec.json
files solved this immediately.
In your main folder, there is a 'package.json' file. Open that and you will see something like this:
{
"name": "prep",
"version": "1.0.0",
"main": "server/server.js", //This can be different
"scripts": {
"lint": "eslint .",
"start": "node .",
"posttest": "npm run lint && nsp check"
}, ....
Then add the following after "start": "node .", => "test": "jasmine". It should look like this:
{
"name": "prep",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"lint": "eslint .",
"start": "node .",
"test": "jasmine",
"posttest": "npm run lint && nsp check"
},....
Then run 'npm test' in the terminal