In this tutorial, we will create some tests in JavaScript for Node.js, using jasmine-node.

"jasmine-node" is an implementation of Jasmine for Node.js and supports out-of-the-box JUnit reports.


  • nodejs
  • "jasmine-node", "express" and "request" node modules


This example is a simple Node.js web server tutorial from SemaphoreCI, based on the "express" node module.

It consists of two source files: one that basically returns an array of strings given a number, and another that implements the web server that processes an argument.


 exports.generateHelloWorlds = function(number) {
  var result = [];
  for(var i=0; i < number; i++) {
    result.push("Hello World");
  return result;
var generator = require('./generator');
var express   = require('express');
var app = express();
app.get("/", function(req, res) {
  var number = req.query.number;
  var helloWorldArray = generator.generateHelloWorlds(number);
  res.send(200, helloWorldArray);
  "name": "jasmine_helloworld_express",
  "version": "1.0.0",
  "description": "simple express hello world",
  "main": "index.js",
  "scripts": {
    "test": "node_modules/.bin/jasmine-node --junitreport --captureExceptions spec"
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.14.1",
    "request": "^2.79.0"
  "devDependencies": {
    "jasmine-node": "^1.14.5"

There are two jasmine-node "specs" containing the tests that validate the previous implementations.

var generator = require("../app/generator");
describe("Hello World Generator", function() {
  it("returns an array", function() {
  it("returns the correct number of Hello Worlds", function() {
    var result = generator.generateHelloWorlds(3);
  it("returns only Hello Worlds", function() {
    var result = generator.generateHelloWorlds(3);
    result.forEach(function(element) {
      expect(element).toBe("Hello World");
var request = require("request");
describe("Hello World Server", function() {
  describe("GET /", function() {
    it("returns status code 200", function(done) {
      request.get("http://localhost:3000", function(error, response, body) {
    it("returns Hello World array", function(done) {
      request.get("http://localhost:3000?number=3", function(error, response, body) {
        expect(body).toBe(JSON.stringify(["Hello World", "Hello World", "Hello World"]));

In order to run the tests, we need first to run our basic web server in the background or in another console.

node app/hello_world.js

After running the tests and generating the JUnit XML reports (e.g., TEST-HelloWorldGenerator.xmlTEST-HelloWorldServer.xml), they can be imported to Xray (either by the REST API or through the Import Execution Results action within the Test Execution).

npm test
# jasmine-node --junitreport --captureExceptions spec

JUnit's Test Case is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the value of the "it" concatenated with the several "describe"' that make up the test case.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the concatenation of the test's "describe".