Skip to content

Commit

Permalink
added a few improvements for mocha with reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Feb 24, 2022
1 parent aa0bd8c commit cb92ced
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 834 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -24,4 +24,6 @@ output
screenshot.png
/sample
/screens
/logs
/logs
html-report/
test-results.xml
2 changes: 0 additions & 2 deletions examples/tests/duckDuckGo.js
@@ -1,6 +1,4 @@
describe('duckduckgo example', function() {
this.timeout(999999);

it('Search Nightwatch.js and check results', function(browser) {
browser
.navigateTo('https://duckduckgo.com')
Expand Down
25 changes: 13 additions & 12 deletions lib/runner/cli/cli.js
Expand Up @@ -334,26 +334,27 @@ class CliRunner {
throw error;
}

if (this.isConcurrencyEnabled(modules)) {
let promise = Promise.resolve();
let promise = Promise.resolve();

if (this.test_settings.selenium && this.test_settings.selenium.start_process) {
const SeleniumServer = require('../../transport/selenium-webdriver/selenium.js');
this.seleniumService = SeleniumServer.startServer(this.test_settings);
promise = this.seleniumService.init();
}
if (this.test_settings.selenium && this.test_settings.selenium.start_process) {
const SeleniumServer = require('../../transport/selenium-webdriver/selenium.js');
this.seleniumService = SeleniumServer.startServer(this.test_settings);
promise = this.seleniumService.init();
this.test_settings.selenium['[_started]'] = true
}

return promise.then(() => {
return promise.then(() => {
if (this.isConcurrencyEnabled(modules)) {
return this.testRunner.runConcurrent(this.testEnvArray, modules)
.then(exitCode => {
if (exitCode > 0) {
this.processListener.setExitCode(exitCode);
}
});
});
}
}

return this.executeTestRunner(modules);
return this.executeTestRunner(modules);
});
})
.catch(err => {
if (err.detailedErr) {
Expand Down Expand Up @@ -392,7 +393,7 @@ class CliRunner {
}, 100);
}).then(() => {
return errorOrFailed;
})
});
}
}

Expand Down
25 changes: 25 additions & 0 deletions lib/runner/test-runners/mocha.js
Expand Up @@ -63,6 +63,31 @@ class MochaRunner {

if (argv.reporter === 'html') {
this.mochaOpts.reporter = 'mochawesome';
} else if (argv.reporter === 'junit') {
try {
require('mocha-junit-reporter');
} catch (err) {
const error = new Error('Nightwatch needs the mocha-junit-reporter package for when using Mocha as a test runner.');
error.detailedErr = 'To install it, please run:\n npm install mocha-junit-reporter --save-dev';
error.showTrace = false;
error.displayed = false;

throw error;
}
this.mochaOpts.reporter = 'mocha-junit-reporter';
}

if (this.mochaOpts.reporter === 'mochawesome') {
try {
require('mochawesome');
} catch (err) {
const error = new Error('Nightwatch needs the mochawesome package for when using Mocha as a test runner.');
error.detailedErr = 'To install it, please run:\n npm install mochawesome --save-dev';
error.showTrace = false;
error.displayed = false;

throw error;
}
}

if (argv.grep) {
Expand Down
3 changes: 2 additions & 1 deletion lib/transport/selenium-webdriver/selenium.js
Expand Up @@ -37,7 +37,7 @@ module.exports = class SeleniumServer extends DefaultSeleniumDriver {
}

constructor(nightwatchInstance, browserName) {
if (Concurrency.isChildProcess()) {
if (nightwatchInstance.settings.selenium && nightwatchInstance.settings.selenium['[_started]']) {
nightwatchInstance.settings.selenium.start_process = false;
nightwatchInstance.settings.webdriver.start_process = false;
}
Expand All @@ -50,6 +50,7 @@ module.exports = class SeleniumServer extends DefaultSeleniumDriver {
async sessionFinished(reason) {
this.emit('session:finished', reason);

// TODO: refactor this, selenium server management has moved to runner/cli
if (this.driverService) {
const {service} = this.driverService;
if (service && service.kill) {
Expand Down
Expand Up @@ -129,8 +129,9 @@ class SeleniumServiceBuilder extends BaseService {
const introMsg = `Starting Selenium Server [${serverPathStr}] on port ${options.port}${commandStr}...`;

if (opts.showSpinner) {
opts.showSpinner(introMsg + `\n\n`);
opts.showSpinner(`${introMsg}\n\n`);
} else {
// eslint-disable-next-line
console.info(introMsg);
}

Expand Down

0 comments on commit cb92ced

Please sign in to comment.