Skip to content

Commit

Permalink
Configure Jest to generate JUnit formatted reports
Browse files Browse the repository at this point in the history
Jest is able to generate JUnit formatted reports using the
jest-junit (1) package. It has been defined in the main configuration
file as additional reporter next to the `default` report format.
See Circle CI's documentation about to how to collect test data (2) for
more details about setups with Jest.

References:
  (1) https://github.com/codecov/jest-junit
  (2) https://circleci.com/docs/2.0/collect-test-data/#jest

GH-44
  • Loading branch information
arcticicestudio committed Nov 25, 2018
1 parent dd1a155 commit 246857e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 36 deletions.
15 changes: 10 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ commands:
path: ./public
- store_artifacts:
path: ./node_modules.tgz
- store_tests_results:
path: ./build/reports/junit
- codecov/upload:
file: ./build/reports/coverage/coverage-final.json
flags: unit
Expand Down Expand Up @@ -79,8 +81,8 @@ commands:
name: Lint
command: npm run lint
- run:
name: Run tests with coverage
command: npm run test:cov
name: Run tests with coverage in CI mode
command: npm run test:ci

jobs:
nodejs-v8:
Expand Down Expand Up @@ -115,6 +117,9 @@ workflows:
version: 2.1
build-multi-version:
jobs:
- nodejs-v8
- nodejs-v10
- nodejs-latest
- nodejs-v8:
context: nord-docs-ctx
- nodejs-v10:
context: nord-docs-ctx
- nodejs-latest:
context: nord-docs-ctx
17 changes: 16 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* @author Sven Greb <[email protected]>
* @see https://jestjs.io/docs/en/configuration
* @see https://www.gatsbyjs.org/docs/testing
* @see https://circleci.com/docs/2.0/collect-test-data/#jest
* @since 0.1.0
*/

const { BASE_DIR_BUILD_REPORTS_COVERAGE } = require("./src/config/internal/constants");
const { BASE_DIR_BUILD_REPORTS_COVERAGE, BASE_DIR_BUILD_REPORTS_JUNIT } = require("./src/config/internal/constants");

module.exports = {
/*
Expand Down Expand Up @@ -70,6 +71,20 @@ module.exports = {
*/
modulePaths: ["<rootDir>/test/__utils__"],

/*
* An array of module names to specify which reporters will be used.
*/
reporters: [
"default",
[
"jest-junit",
{
outputDirectory: `${BASE_DIR_BUILD_REPORTS_JUNIT}`,
outputName: "jest.xml"
}
]
],

/*
* The paths to modules that run some code to configure or set up the testing environment before each test.
* The `___loader` shim is a global function used by internal Gatsby APIs.
Expand Down
60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
"lint": "npm-run-all lint:*",
"lint:js": "eslint --ext .js,.jsx .",
"lint:md": "remark --no-stdout . \".github/**/*.md\"",
"report:js:junit": "eslint --ext .js,.jsx --format junit -o ./build/reports/junit/eslint.xml .",
"serve": "gatsby serve",
"test": "jest",
"test:ci": "jest --ci --coverage",
"test:cov": "jest --coverage",
"test:watch": "jest --watch"
},
Expand Down Expand Up @@ -67,6 +69,7 @@
"identity-obj-proxy": "3.0.0",
"jest": "23.6.0",
"jest-dom": "2.1.1",
"jest-junit": "5.2.0",
"lint-staged": "8.0.5",
"npm-run-all": "4.1.3",
"prettier": "1.15.2",
Expand Down
9 changes: 9 additions & 0 deletions src/config/internal/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ const BASE_DIR_BUILD_REPORTS = `${BASE_DIR_BUILD}/reports`;
*/
const BASE_DIR_BUILD_REPORTS_COVERAGE = `${BASE_DIR_BUILD_REPORTS}/coverage`;

/**
* The relative path of the build base directory for JUnit reports starting from the project root.
*
* @constant {string}
* @since 0.1.0
*/
const BASE_DIR_BUILD_REPORTS_JUNIT = `${BASE_DIR_BUILD_REPORTS}/junit`;

/**
* The relative path of the config base directory starting from the project root.
*
Expand Down Expand Up @@ -109,6 +117,7 @@ module.exports = {
BASE_DIR_BUILD,
BASE_DIR_BUILD_REPORTS,
BASE_DIR_BUILD_REPORTS_COVERAGE,
BASE_DIR_BUILD_REPORTS_JUNIT,
BASE_DIR_CONFIG,
BASE_DIR_CONTENT,
BASE_DIR_PAGES,
Expand Down

0 comments on commit 246857e

Please sign in to comment.