JavaScript test runner that supports native modules - javascript

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

Related

Difference between #vue/cli-plugin-unit-jest and vue-jest?

What is the difference between these two packages:
#vue/cli-plugin-unit-jest
vue-jest
If I have one is the other unnecessary? If so, when should one use one or the other?
Jest is JS testing framework and understands only JS.
So vue-jest is used to transform the SFC(.vue) file to a format understandable by jest. Its job ends there.
On the other hand, #vue/cli-plugin-unit-jest is the webpack type plugin that does more things in addition to just transforming the code and has deeper level integration with vue cli. It internally uses vue-jest to achieve some level of functionality.
Capabilities of #vue/cli-plugin-unit-jest includes
Transforms your vue files to JS to be feed to jest.
creating a boilerplate jest setup with example tests when installed.
Adding all the eslint and package dependencies.
providing wrappers to run the jest tests which provide specific hints to babel to avoid build issues.

Running Jasmine tests from Node against code that uses RequireJS

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

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

How do I integrate jasmine into mocha?

I have a large set of unit test written in jasmine-node for a Node project. I want to use Mocha for the expanded feature set but I'm pretty in bed with jasmine both for style and extensive use of spies. I have several helpers and custom code that is very jasmine dependent.
How can I use jasmine-node or the jasmine library as the framework while mocha is the testing engine? Can the two play nicely or do I have to rewrite my testing environment for mocha, chai, and sinon?
How can I use jasmine-node or the jasmine library as the framework while mocha is the testing engine?
What? Do you mean you want to code your tests against jasmine and then somehow run them in mocha? While I'm sure it's possible, it just sounds bizarre.
For a given suite of tests, it's one or the other. They have similar but different APIs so you have to choose one. Choosing BOTH in a single project is almost certainly poor judgement IMHO. Other than mocha's vastly superior async support, I can't see how you could justify using both when they are so closely related. It's just going to create a confusing annoyance for maintenance.
Suggestion: split your project apart into smaller, separate modules. Than you can port each of these smaller modules when the time is right if you want to migrate from jasmine to mocha.

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