DEV Community

Sean Killeen
Sean Killeen

Posted on • Originally published at seankilleen.com on

2

How to: Show Jasmine test results in TeamCity

A colleague wanted to surface their jasmine tests in a TeamCity build system. Wanted to document the steps I used to help them solve their problem.

Setting up the Jasmine Output

  • Add the jasmine-reporters package: npm -i jasmine-reporters --save-dev
  • Add an index.js to set up the tests if you haven’t already:
var Jasmine = require('jasmine'); 

var reporters = require('jasmine-reporters');

var jasmine = new Jasmine();

// Load configuration from a file or from an object. jasmine.loadConfig({
    "spec_dir": "spec",
    "spec_files": [
      "**/*\[sS]pec.js" ],
    "helpers": [
      "helpers/**/*.js" ],
    "stopSpecOnExpectationFailure": false,
    "random": true
  });

jasmine.execute();

Enter fullscreen mode Exit fullscreen mode
  • Prior to executing the steps, add the TeamCity reporter:
var teamCityReporter = new reporters.TeamCityReporter();

jasmine.configureDefaultReporter(teamCityReporter);

Enter fullscreen mode Exit fullscreen mode
  • Update the “test” or “tests” command in your package.json:
"tests": "node .path/to/specs/index.js"

Enter fullscreen mode Exit fullscreen mode
  • Prior to executing, add an additional NUnit XML Reporter:
var nunitXmlReporter = new reporters.NUnitXmlReporter();

jasmine.addReporter(nunitXmlReporter);

Enter fullscreen mode Exit fullscreen mode

Updating TeamCity

  • Open the build in question
  • From the Menu, add a build feature:

TeamCity build menu showing the option to add a build feature

  • Select the “XML Report Processing” feature, choose an NUnit-style report, and point it to nunitresults.xml (the default location for the jasmine NUnit output):

XML report processing options

  • Double-check the saved feature:

The added build feature

The Results

We see our tests listed in the build list:

Tests in the build list

And we see the test output in the overview tab:

Tests in the overview page of the build

And we see the a tests tab with the output of each individual test:

Tests in the build's tests tab

Hope this helps! Happy testing!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay