Skip to content

Commit

Permalink
feat(jasmine): configure XML reporter to capture detailed testlogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Jeske authored and alexeagle committed Mar 2, 2020
1 parent 18e8001 commit 8abd20d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"is-builtin-module": "3.0.0",
"jasmine": "~3.4.0",
"jasmine-core": "~3.4.0",
"jasmine-reporters": "~2.3.2",
"karma": "~4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-firefox-launcher": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/jasmine/src/index.from_src.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load(":index.bzl", _jasmine_node_test = "jasmine_node_test")

def jasmine_node_test(
deps = [],
jasmine_deps = ["@npm//jasmine", "@npm//jasmine-core", "@npm//v8-coverage"],
jasmine_deps = ["@npm//jasmine", "@npm//jasmine-core", "@npm//jasmine-reporters", "@npm//v8-coverage"],
**kwargs):
_jasmine_node_test(
# When there is no @npm//@bazel/jasmine package we use @npm_bazel_jasmine instead.
Expand Down
8 changes: 8 additions & 0 deletions packages/jasmine/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ exports.boot = boot;
// re-export jasmine and its transitive dep jasmine-core
exports.jasmine = require('jasmine');
exports.jasmineCore = jasmineCore;

let JUnitXmlReporter = null;
try {
JUnitXmlReporter = require('jasmine-reporters').JUnitXmlReporter;
} catch (err) {
// fail quietly if jasmine-reporters is not available
}
exports.JUnitXmlReporter = JUnitXmlReporter;
4 changes: 4 additions & 0 deletions packages/jasmine/src/jasmine_node_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def jasmine_node_test(
**kwargs):
"""Runs tests in NodeJS using the Jasmine test runner.
Detailed XML test results are found in the standard `bazel-testlogs`
directory. This may be symlinked in your workspace.
See https://docs.bazel.build/versions/master/output_directories.html
To debug the test, see debugging notes in `nodejs_test`.
Args:
Expand Down
16 changes: 16 additions & 0 deletions packages/jasmine/src/jasmine_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const bazelJasmine = require('@bazel/jasmine');

const JasmineRunner = bazelJasmine.jasmine;
const JUnitXmlReporter = bazelJasmine.JUnitXmlReporter;

let jasmineCore = null
if (global.jasmine) {
Expand Down Expand Up @@ -112,6 +113,21 @@ function main(args) {
noSpecsFound = false
},
});

if (JUnitXmlReporter) {
const testOutputFile = process.env.XML_OUTPUT_FILE;
if (testOutputFile) {
jrunner.addReporter(new JUnitXmlReporter({
filePrefix: path.basename(testOutputFile),
savePath: path.dirname(testOutputFile),
consolidate: true,
consolidateAll: true
}));
} else {
console.warn('Skipping XML Test Result: $XML_OUTPUT_FILE not found.')
}
}

// addReporter throws away the default console reporter
// so we need to add it back
jrunner.configureDefaultReporter({});
Expand Down
1 change: 1 addition & 0 deletions packages/jasmine/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"jasmine": "~3.5.0",
"jasmine-core": "~3.5.0",
"jasmine-reporters": "~2.3.2",
"v8-coverage": "1.0.9"
},
"bazelWorkspaces": {
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4265,6 +4265,14 @@ jasmine-core@~3.4.0:
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-3.4.0.tgz#2a74618e966026530c3518f03e9f845d26473ce3"
integrity sha512-HU/YxV4i6GcmiH4duATwAbJQMlE0MsDIR5XmSVxURxKHn3aGAdbY1/ZJFmVRbKtnLwIxxMJD7gYaPsypcbYimg==

jasmine-reporters@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/jasmine-reporters/-/jasmine-reporters-2.3.2.tgz#898818ffc234eb8b3f635d693de4586f95548d43"
integrity sha512-u/7AT9SkuZsUfFBLLzbErohTGNsEUCKaQbsVYnLFW1gEuL2DzmBL4n8v90uZsqIqlWvWUgian8J6yOt5Fyk/+A==
dependencies:
mkdirp "^0.5.1"
xmldom "^0.1.22"

[email protected]:
version "2.8.0"
resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-2.8.0.tgz#6b089c0a11576b1f16df11b80146d91d4e8b8a3e"
Expand Down Expand Up @@ -8155,6 +8163,11 @@ xmlbuilder@~9.0.1:
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"
integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=

xmldom@^0.1.22:
version "0.1.31"
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==

xmlhttprequest-ssl@~1.5.4:
version "1.5.5"
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e"
Expand Down

0 comments on commit 8abd20d

Please sign in to comment.