Giter Club home page Giter Club logo

jest-junit's Introduction

Build Status

jest-junit

A Jest reporter that creates compatible junit xml files

Installation

yarn add --dev jest-junit

Usage

In your jest config add the following entry:

{
  "testResultsProcessor": "jest-junit"
}

Then simply run:

jest

For your Continuous Integration you can simply do:

jest --ci --testResultsProcessor="jest-junit"

Configuration

jest-junit offers five configurations based on environment variables or a jest-junit key defined in package.json. All configuration values should be strings.

Variable Name Description Default Possible Injection Values
JEST_SUITE_NAME name attribute of <testsuites> "jest tests" N/A
JEST_JUNIT_OUTPUT File path to save the output. "./junit.xml" N/A
JEST_JUNIT_SUITE_NAME Template string for name attribute of the <testsuite>. "{title}" {title}, {filepath}, {filename}, {displayName}
JEST_JUNIT_CLASSNAME Template string for the classname attribute of <testcase>. "{classname} {title}" {classname}, {title}, {filepath}, {filename}, {displayName}
JEST_JUNIT_TITLE Template string for the name attribute of <testcase>. "{classname} {title}" {classname}, {title}, {filepath}, {filename}, {displayName}
JEST_JUNIT_ANCESTOR_SEPARATOR Character(s) used to join the describe blocks. " " N/A
JEST_USE_PATH_FOR_SUITE_NAME DEPRECATED. Use suiteNameTemplate instead. Use file path as the name attribute of <testsuite> "false" N/A

You can configure these options via the command line as seen below:

JEST_SUITE_NAME="Jest JUnit Unit Tests" JEST_JUNIT_OUTPUT="./artifacts/junit.xml" jest

Or you can also define a jest-junit key in your package.json. All are string values.

{
  ...
  "jest-junit": {
    "suiteName": "jest tests",
    "output": "./junit.xml",
    "classNameTemplate": "{classname}-{title}",
    "titleTemplate": "{classname}-{title}",
    "ancestorSeparator": " › ",
    "usePathForSuiteName": "true"
  }
}

Configuration Precedence

If using the usePathForSuiteName and suiteNameTemplate, the usePathForSuiteName value will take precedence. ie: if usePathForSuiteName=true and suiteNameTemplate="{filename}", the filepath will be used as the name attribute of the <testsuite> in the rendered jest-junit.xml).

Examples

Below are some example configuration values and the rendered .xml to created by jest-junit.

The following test defined in the file /__tests__/addition.test.js will be used for all examples:

describe('addition', () => {
  describe('positive numbers', () => {
    it('should add up', () => {
      expect(1 + 2).toBe(3);
    });
  });
});

Example 1

The default output:

<testsuites name="jest tests">
  <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161">
    <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004">
    </testcase>
  </testsuite>
</testsuites>

Example 2

Using the classNameTemplate and titleTemplate:

JEST_JUNIT_CLASSNAME="{classname}" JEST_JUNIT_TITLE="{title}" jest

renders

<testsuites name="jest tests">
  <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:45:42" time="0.154">
    <testcase classname="addition positive numbers" name="should add up" time="0.005">
    </testcase>
  </testsuite>
</testsuites>

Example 3

Using the ancestorSeparator:

JEST_JUNIT_ANCESTOR_SEPARATOR="" jest

renders

<testsuites name="jest tests">
  <testsuite name="addition" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:47:12" time="0.162">
    <testcase classname="addition › positive numbers should add up" name="addition › positive numbers should add up" time="0.004">
    </testcase>
  </testsuite>
</testsuites>

Example 4

Using the suiteNameTemplate:

JEST_JUNIT_SUIT_NAME ="{filename}" jest
<testsuites name="jest tests">
  <testsuite name="addition.test.js" tests="1" errors="0" failures="0" skipped="0" timestamp="2017-07-13T09:42:28" time="0.161">
    <testcase classname="addition positive numbers should add up" name="addition positive numbers should add up" time="0.004">
    </testcase>
  </testsuite>
</testsuites>

jest-junit's People

Contributors

cmalard avatar crudo avatar danjamin avatar joezeng avatar palmerj3 avatar phawxby avatar samertm avatar wedvich avatar yangshun avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.