mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-10 17:48:50 +08:00
feat(specs): Add support for generating JUnit XML by passing --junit-xml=<path>
Summary: A prerequesite to integrating with `arc unit` or CI for each patchset is being able to generate JUnit XML output for spec runs. This commit adds this feature using the JUnitXMLReporter from jasmine-reporters. Invoke it like this: npm run test-junit (We output to the terminal as well when this is run, so in the case that you're doing `arc diff` you have some idea of what is going on.) Test Plan: run it Reviewers: halla, juan, evan Reviewed By: juan, evan Differential Revision: https://phab.nylas.com/D3891
This commit is contained in:
parent
d6a234e94a
commit
e71fb04bd8
5 changed files with 32 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,6 +14,7 @@ debug.log
|
|||
/tags
|
||||
/electron/
|
||||
/_docs_output
|
||||
/junitxml
|
||||
|
||||
spec/fixtures/evil-files/
|
||||
build/resources/certs
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
"jasmine-json": "~0.0",
|
||||
"jasmine-react-helpers": "^0.2",
|
||||
"jasmine-tagged": "^1.1.2",
|
||||
"jasmine-reporters": "1.x.x",
|
||||
"jsx-transform": "^2.3.0",
|
||||
"juice": "^1.4",
|
||||
"kbpgp": "^2.0.52",
|
||||
|
@ -132,6 +133,7 @@
|
|||
"scripts": {
|
||||
"test": "electron . --test --enable-logging",
|
||||
"test-window": "electron . --test=window --enable-logging",
|
||||
"test-junit": "electron . --test --enable-logging --junit-xml=junitxml",
|
||||
"start": "electron . --dev --enable-logging",
|
||||
"lint": "script/grunt lint",
|
||||
"build": "script/grunt build",
|
||||
|
|
|
@ -129,24 +129,34 @@ class N1SpecRunner {
|
|||
const timeReporter = new TimeReporter();
|
||||
const consoleReporter = new ConsoleReporter();
|
||||
|
||||
// This needs to be `required` at runtime because terminal-reporter
|
||||
// depends on jasmine-tagged, which depends on jasmine-focused, which
|
||||
// on require will attempt to extend the `jasmine` object with
|
||||
// methods. The `jasmine` object has to be attached to the global
|
||||
// scope before it gets extended. This is done in
|
||||
// `_extendGlobalWindow`.
|
||||
const N1TerminalReporter = require('./terminal-reporter').default
|
||||
const loadSettings = NylasEnv.getLoadSettings();
|
||||
|
||||
const terminalReporter = new N1TerminalReporter();
|
||||
|
||||
if (NylasEnv.getLoadSettings().showSpecsInWindow) {
|
||||
this.jasmineEnv.addReporter(N1GuiReporter);
|
||||
NylasEnv.show();
|
||||
} else {
|
||||
this.jasmineEnv.addReporter(terminalReporter);
|
||||
if (loadSettings.jUnitXmlPath) {
|
||||
// jasmine-reporters extends the jasmine global with methods, so needs to
|
||||
// be `required` at runtime. The `jasmine` object has to be attached to the
|
||||
// global scope before it gets extended. This is done in
|
||||
// `_extendGlobalWindow`
|
||||
require('jasmine-reporters');
|
||||
const jUnitXmlReporter = new jasmine.JUnitXmlReporter(loadSettings.jUnitXmlPath, true, true);
|
||||
this.jasmineEnv.addReporter(jUnitXmlReporter);
|
||||
}
|
||||
this.jasmineEnv.addReporter(timeReporter);
|
||||
this.jasmineEnv.addReporter(consoleReporter);
|
||||
|
||||
if (loadSettings.showSpecsInWindow) {
|
||||
this.jasmineEnv.addReporter(N1GuiReporter);
|
||||
NylasEnv.show();
|
||||
} else {
|
||||
// this package's dep `jasmine-focused` also adds methods to the
|
||||
// `jasmine` global
|
||||
// NOTE: this reporter MUST be added last as it exits the test process
|
||||
// when complete, which may result in e.g. your XML output not getting
|
||||
// written to disk if that reporter is added afterward.
|
||||
const N1TerminalReporter = require('./terminal-reporter').default
|
||||
|
||||
const terminalReporter = new N1TerminalReporter();
|
||||
this.jasmineEnv.addReporter(terminalReporter);
|
||||
}
|
||||
}
|
||||
|
||||
_initializeDOM() {
|
||||
|
|
|
@ -113,9 +113,9 @@ export default class Application extends EventEmitter {
|
|||
const {specMode, pathsToOpen, urlsToOpen} = options;
|
||||
|
||||
if (specMode) {
|
||||
const {resourcePath, specDirectory, specFilePattern, logFile, showSpecsInWindow} = options;
|
||||
const {resourcePath, specDirectory, specFilePattern, logFile, showSpecsInWindow, jUnitXmlPath} = options;
|
||||
const exitWhenDone = true;
|
||||
this.runSpecs({exitWhenDone, showSpecsInWindow, resourcePath, specDirectory, specFilePattern, logFile});
|
||||
this.runSpecs({exitWhenDone, showSpecsInWindow, resourcePath, specDirectory, specFilePattern, logFile, jUnitXmlPath});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -762,6 +762,7 @@ export default class Application extends EventEmitter {
|
|||
// :specPath - The directory to load specs from.
|
||||
// :safeMode - A Boolean that, if true, won't run specs from ~/.nylas-mail/packages
|
||||
// and ~/.nylas-mail/dev/packages, defaults to false.
|
||||
// :jUnitXmlPath - The path to output jUnit XML reports to, if desired.
|
||||
runSpecs(specWindowOptionsArg) {
|
||||
const specWindowOptions = specWindowOptionsArg;
|
||||
let {resourcePath} = specWindowOptions;
|
||||
|
|
|
@ -86,6 +86,7 @@ const parseCommandLine = (argv) => {
|
|||
const devMode = args['dev'] || args['test'];
|
||||
const logFile = args['log-file'];
|
||||
const specMode = args['test'];
|
||||
const jUnitXmlPath = args['junit-xml'];
|
||||
const safeMode = args['safe'];
|
||||
const background = args['background'];
|
||||
const configDirPath = args['config-dir-path'];
|
||||
|
@ -129,6 +130,7 @@ const parseCommandLine = (argv) => {
|
|||
background,
|
||||
logFile,
|
||||
specMode,
|
||||
jUnitXmlPath,
|
||||
safeMode,
|
||||
configDirPath,
|
||||
specDirectory,
|
||||
|
|
Loading…
Reference in a new issue