Jasmine expect is not defined in intellij - node.js

I am new to typescript and am struggling to run individual jasmine tests in my IDE (Intellij or Webstorm are not working).
An easy example is if I try to run the jasmine examples loaded with the jasmine examples. When I try to run them manually in intellij I get the following error:
ReferenceError: expect is not defined
at Context.<anonymous> (spec/jasmine_examples/PlayerSpec.js:14:5)
at processImmediate (internal/timers.js:458:21)
When I run jasmine from the command line it runs the tests fine and they pass.
I have tried installing karma with npm and running a karma intellij plugin but doesn't do anything.
What am I missing here? Something obvious I'm assuming!

Related

When trying to run a jest test, I receive the error "sh: jest: command not found"

Im working on a node command line application which requires jest testing. Ive installed it as a dependency in my package.json, and when I try to run the 'npm run test' command, it gives me a bunch of errors. Anyone know what's going on? Im very new to node and web dev in general, so any feedback would be much appreciated!

Run E2E tests in IDE or command line

I'm using Stencil.js to create a web component library and I'm heavily relying on E2E tests. As they're rather slow it becomes more and more cumbersome to run the entire test suite (using the Stencil.js CLI) while developing new components.
However, I'm not able to run single tests in my IDE (IntelliJ IDEA) or via command line. It works perfectly fine for unit tests though.
My Jest config looks like this:
module.exports = {
"roots": [
"<rootDir>/src"
],
"preset": "#stencil/core/testing"
}
When I try to run tests in a single file (jest --config jest.config.js --testPathPattern src/components/button/button.e2e.ts$)
it fails, because
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
newE2EPage() comes with Stencil.js and I don't know what Stencil.js's CLI does in the background. Furthermore, I cloned the Stencil.js repository, just to see if it is working with their E2E tests (https://github.com/ionic-team/stencil/tree/master/test/end-to-end) but it doesn't work either.
Any idea how I can configure Jest so that it's able to run Stencil.js-E2E tests from the command line?
The --e2e flag is used for the npm script in the package.json. To start e2e tests, you can add this in your package.json:
"scripts": {
"test:e2e": "stencil test --e2e"
}
And run npm run test:e2e. For a specific file, you add it at the end like this:
npm run test:e2e src/components/button/button.e2e.ts
For more info, see the StencilJS doc: https://stenciljs.com/docs/end-to-end-testing
i have the same problem. IntelliJ and 'Run' single 'it' didnt work.
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
when i run 'npm run test' everything will work fine. the difference is that npm run stencil before and only jest dont work.
here is the stencil jest dir https://github.com/ionic-team/stencil/tree/master/src/testing/jest aswell a config.
i found in here https://stenciljs.com/docs/testing-overview a VS-CODE run jest code but no Intellij setup.
im on the run to get the path of the current file to run stencil via npm and the path the e2e file. but i cant find the correct variable for the run config.
i hope we got this solved soon.
cheers
I am not a VS Code user, but in contrast to IntelliJ there is a launch.json for VSC to run single tests: https://github.com/ionic-team/stencil-site/pull/480

Debugging mocha test cases in WebStorm has incorrect line numbers

I'm having trouble getting WebStorm to set breakpoints and step through my coffeescript test cases in the debugger, as it appears the IDE is using line numbers from the generated .js file rather than the original .coffee file. For example, when I set a breakpoint in a .coffee file, the debugger may break in near it but at a non-code line.
This is a node application, the test cases for which are written in coffeescript and run with mocha.
The test cases run fine both from the command line and from the IDE. And if an error is encountered in either scenario, the line numbers in the reported stack trace show the correct coffeescript line numbers.
ReferenceError: bad_thing is not defined
at Context.<anonymous> (C:\[project]\test\e2e\basic.test.coffee:22:5) # This is the correct line number in the coffeescript
at Hook.Runnable.run (C:\...\mocha\lib\runnable.js:218:15)
at next (C:\...\mocha\lib\runner.js:259:10)
at Immediate._onImmediate (C:\...\mocha\lib\runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:358:17)
I have WebStorm set up for automatic transpiling, and it generates output .js and .map files automatically. I am running the tests in the IDE from a "Mocha" debug configuration.
Any ideas?
I'm on Windows with:
WebStorm 10.0.0
Node 0.12.2
CoffeeScript 1.9.3
Mocha 2.1.0

Run CucumberJS tests in Webstorm with Harmony flag?

I am just spiking to see if we can get some of the ES6 goodness into our existing codebase, and so far so good although when I went to start up our cucumber js tests from webstorm it blows up with the ES6 syntax.
So has anyone else got this working? I have tried adding --harmony to the CucumberJs arguments but no luck :(

Exporting the same object that is required confuses mocha

I'm working on a node app that uses mocha to run unit tests.
When I run this command:
mocha --compilers coffee:coffee-script --reporter spec ./test/unit/*-test.coffee
I get this error:
ERROR: Unknown option --compilers
It seems mocha is confused, because it definitely has a compilers option. This error started happening when I added a new file to the project. It's the only output I can get mocha to generate. --debug does nothing.
Let's say I have a package called person installed. I want to configure this package globally so that I can import the configured object anywhere in my project. To do that, I import person, configure it as a driver, and then export it again.
However, when I import it (either in Car.coffee or Car-test.coffee), mocha fails with the above error.
Driver.coffee
driver = require 'person'
driver.setSkill "Drive"
module.exports = driver
Car.coffee
driver = require './driver'
...
Car-test.coffee
driver = require '../../src/driver'
...
Note that this works fine if I'm just compiling with coffee and running the node project. There's no issue importing it there. But when I run with mocha, it fails if I import the file.
I can't really pinpoint the error. It seems just like a bug in mocha, but maybe I'm doing something "bad" by exporting the same object that I import, and node is just more forgiving?
I'm using the latest version of mocha (1.13.0). Thanks!
Edit:
This doesn't fix the error, and is not ideal syntax-wise:
person = require 'person'
class driver
constructor: ->
person.setSkill "Drive"
#person = person
module.exports = driver
Note that simply wrapping it in a plain object doesn't work.
Edit 2:
Here's something else that doesn't work:
configure-driver.coffee
configureDriver = (person) ->
person.setSkill "Drive"
module.exports = configureDriver
car.coffee
driver = require('./configure-driver')(require 'person')
Mocha throws the same error as before.
Maybe a little late but hopefully it will help someone (I just spent an hour paging through mocha's source code to track this down).
Try that command instead (the important bit is the equal sign after --compilers):
mocha --compilers=coffee:coffee-script --reporter spec ./test/unit/*-test.coffee
I ran into that bug while trying to create a new grunt test taks using grunt-mocha-istanbul and coffeescript test definitions. Strangely, if I ran the command directly in my shell it worked but using the grunt task I got the same error as you did.
It seems Mocha uses commander and it's global. In my case I had a script under the test directory that uses commander. It looks like Mocha executes the test scripts, parses mocha.opts, and then executes the specs. To fix it I just moved the scripts using commander out of the test dir and all was good.

Resources