Running Jasmine tests from Node against code that uses RequireJS - javascript

Is it possible to run Jasmine from Node to test code that uses RequireJS?
I am using the Jasmine NPM. I can run some tests from Node but can't work out how to test my code that uses RequireJS.
V2 of jasmine-node (that supports Jasmine 2.x) has had RequireJS support removed.
Is there an incompatibility with the require keyword because this is used by Node and RequireJS? Perhaps I am misunderstanding something fundamental?
If I have to use a task runner I would favour
If anyone has any experience or thoughts to share, that would be greatly appreciated!
I am using:
Node 0.10.24
RequireJS 2.1.22
Jasmine 2.3.4

Related

JavaScript test runner that supports native modules

Is there a JavaScript test runner that supports native modules?
UPDATE for 2022: Jest now supports native modules experimentally. Complete information on configuring it, and information about current issues, can be found in the Jest docs.
Facebook's Jest supports native modules fairly painlessly through the use of the babel-jest plugin.
I'm not aware of any runners that don't require transpilation. Would love to know about them if they exist.
There is another answer here that discusses using Node's experimental module support to test with Jasmine, but I'm not sure this is better: https://stackoverflow.com/a/47835049/3084820
You can try Karma,
Jest or Jasmine.
Onestly, I prefer Karma or Jest

What is the purpose of jasmine-node?

I can run my specs with either jasmine-node or just jasmine. They both run my specs. So, what value does jasmine-node add? The readme says:
This node.js module makes the wonderful Pivotal Lab's jasmine spec framework available in node.js.
https://github.com/mhevery/jasmine-node/blob/master/README.md
I don't understand. My app runs on node, my specs require node modules .. so when I run jasmine, I'm already using both node and jasmine. What does jasmine-node add?
I specifically am not asking for opinions about why jasmine-node is your favorite, or recommendations of other libraries. I only want to know, what is the purpose of jasmine-node?
The subtitle of jasmine-node is a good answer to your question:
DOM-less simple JavaScript BDD testing framework for Node
Let's go and look at the different parts of the answer:
DOM-less simple testing framework
jasmine is a JS testing tool. At the beginning JS was just for browsers. To give an output inside the browser there is this DOM Model, which is not so easy to use. Node.js gives you the possibility to run JS also on a server. On the server-side there is no DOM. To make things faster and easier you don't need a DOM implementation for your testing tool, when it just runs inside node.js
Jasmine itself is independent of a browser, so that is an intention for both jasmine and jasmine-node.
for Node
This is easy - jasmine-node is just for node and not for browser JS.
But behind that part there is the main purpose. Because the requirements between a brwoser test and a node.js test are totaly different. Because jamsine supports both ways it can not have all features, which are possible with node. If you look at the possible arguments at the documentation you see that there are much more options inside the CLI of jasmine-node. Some of the most interesting features are maybe:
Test a file automaticaly, when it changes
test coffeescript files directly
So to give you an answer to your question:
What is the purpose of jasmine-node?
jasmine-node provides you more CLI options for you tests. It can make some work automaticaly and it uses more of the node functions to provide that. So the future way for jasmine-node will be in providing more functions, which are just able to implement, when you just test on node.js

Run/debug node.js testcases with jasmine in Webstorm 11

I install Webstorm 11 and want to run my tests (for node.js app) implemented with Jasmine.
However it's not easy to do that. I could just type in command line 'jasmine' command and test will be runned, but in this case I'm not able to debug code.
So is there a way to configure Webstorm to deal with jasmine specs as it should?
Ok, so while no one answer at the moment I will try to provide my version:
This flow will allow to run jasmine testsute from Webstrom and debug testcases
install jasmine (ither locally or globally)
in project folder create folder 'spec/support' In this folder place jasmine.json
tests configuration example:
{
"spec_dir": "tests",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
Create node.js configuration in Webstorm
In this configuration select source file - jasmine executable file (for localy installed
jasmine it will be 'node_modules\jasmine\bin\jasmine.js' )
So you are ready. However at the current moment when trying to debug this configuration - it fails with error:
Cannot stop on breakpoint due to internal error org.jetbrains.v8.V8CommandProcessor$1:
If you faced with it - you need to change Webstom configuration and set this settings:
-Dnodejs.debugger.use.jb.support=false For more details check there:
So this allow you to run jasmine tests and debug them. However there is still some things which this solution not able to do:
Run individual testcases
Run individual testcases with right click button and Run command from menu
Jetbrains, if you reading this - please fix this already. I started play with node in Webstorm 3 years ago and since that moment and dozens of version there is still no nice way to run tests. It's ridiculous.
Jasmine works with the JSTestDriver which you get out-of-the-box with WebStorm 11:
https://www.jetbrains.com/webstorm/help/enabling-javascript-unit-testing-support.html
This page also details how to add Jasmine within JSTestDriver:
https://www.jetbrains.com/webstorm/help/preparing-to-use-jstestdriver-test-runner.html
At a high level you're going to:
Install JSTestDriver from JetBrains plugin repo
Configure it as a WebStorm JavaScript library (https://www.jetbrains.com/webstorm/help/configuring-javascript-libraries.html#configure)
Open jsTestDriver.conf and type the following code in it:
load:
lib/jasmine/jasmine.js
lib/jasmine-jstd-adapter/JasmineAdapter.js
WebStorm doesn't manage test running directly. This job is done by a test runner. WebStorm supports several test runners - Mocha, Karma, JsTestDriver, nodeunit. Most of them can execute Jasmine tests

Ember.js/Addon: How do I jshint all javascript files?

I'm writing an ember.js addon. When running ember test Ember will add generic should pass jshint tests to my test suite. That's great as far as it goes, but the javascript files from the main directory (index.js, Brocfile.js) are missing as are the files from app/**/*. As far as I can see, only files in addon/**/\ and tests/**/\ are covered.
Am I missing some obvious configuration option? Is this a bug?
No it is not a bug. That's how the ember test works.
Once there was an issue about running linter. But I didn't find any rfc about these issue.
If you want to run linting on your code base, you can use either cli or ide plugins.

Headless jasmine testing with intellij

Is there a way to run headless jasmine JavaScript tests from IntelliJ? I've seen the jstestdriver plugin and that works for in browser testing, but I couldn't find a way to run headless jasmine tests inside the IDE.
I ended up writing a class to parse the js test driver config and generate a spec for the jasmine file. Then I used gradle's envjs plugin run the spec file.

Categories

Resources