From ab253b901fab237a99ef206f30718a46520d0a62 Mon Sep 17 00:00:00 2001 From: Ravi Sawlani Date: Tue, 1 Nov 2022 14:58:24 +0530 Subject: [PATCH] Fixed `--open` cli argument wasn't working properly (#3459) --- lib/runner/test-runners/default.js | 2 +- test/src/runner/testReporter.js | 54 +++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/lib/runner/test-runners/default.js b/lib/runner/test-runners/default.js index a694981e9a..1ba734c942 100644 --- a/lib/runner/test-runners/default.js +++ b/lib/runner/test-runners/default.js @@ -19,7 +19,7 @@ class DefaultRunner { this.addtOpts = addtOpts; this.publishReport = true; // in-case of an uncaught exception, the report will not be published this.globalReporter = new GlobalReporter(argv.reporter, settings, { - open: argv.open, + openReport: argv.open, reportFileName: argv['report-filename'] }); } diff --git a/test/src/runner/testReporter.js b/test/src/runner/testReporter.js index 8028f25923..d023590a32 100644 --- a/test/src/runner/testReporter.js +++ b/test/src/runner/testReporter.js @@ -24,13 +24,19 @@ describe('testReporter', function() { if (err) { return done(err); } + mockery.enable({useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false}); done(); }); }); - // afterEach(function(done) { - // rimraf('output', done); - // }); + + afterEach(function(done) { + mockery.deregisterAll(); + mockery.resetCache(); + mockery.disable(); + rimraf('output', done); + }); + after(function(done) { this.server.close(function() { @@ -94,7 +100,6 @@ describe('testReporter', function() { }); it('test with valid reporter from NPM', function() { - mockery.enable({useCleanCache: true, warnOnUnregistered: false}); mockery.registerMock('nightwatch_reporter', { async write(results, options) { @@ -174,4 +179,45 @@ describe('testReporter', function() { assert.strictEqual(possibleError, null); }); + + it('test run tests with default reporters - open the html report', async function () { + let htmlFile; + + mockery.registerMock('open', function(filename) { + htmlFile = filename; + + return Promise.resolve(); + }); + + let possibleError = null; + const testsPath = [path.join(__dirname, '../../sampletests/simple/test/sample.js')]; + + try { + await runTests({ + source: testsPath, + open: true + }, + settings({ + output_folder: 'output', + globals: { + waitForConditionPollInterval: 20, + waitForConditionTimeout: 50, + retryAssertionTimeout: 50, + reporter: function () {} + }, + silent: true, + output: false + })); + + await readFilePromise(`output${path.sep}FIREFOX_TEST_firefox__sample.xml`); + await readFilePromise(`output${path.sep}FIREFOX_TEST_firefox__sample.json`); + await readDirPromise(`output${path.sep}nightwatch-html-report`); + } catch (error) { + possibleError = error; + } + + assert.strictEqual(possibleError, null); + assert.strictEqual(htmlFile, `output${path.sep}nightwatch-html-report${path.sep}index.html`); + + }); });