-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: event setup for nightwatch hooks (#3706)
* test observability event handling * added support of onEvent in plugins * event data * code refactoring * lint fixes * Added LogCreated and ScreenshotCreated events * cucumber event initial commit * code refactoring and httpoutput added * Added httpoutput at step finished level as well * event refactoring and added writeReportFile function for cucumber * changed 2 events name in cucumber to avoid conflicts * test fix * setup default formatter for cucumber * rename eventHubSetup to `setupEventHub` * onevent optimization * test case fix and added shouldUseNightwatchFormatter * added tests * screenshot event test added * function name changed and test updated * test case fix and added shouldUseNightwatchFormatter * added tests * screenshot event test added * Update test/src/runner/testEventReporter.js * Update test/cucumber-integration-tests/testCucumberTestsWithExpect.js * Update test/extra/cucumber-config-events.js * test observability event handling * Added LogCreated and ScreenshotCreated events * events name code refactoring * code refactoring and merge issues fix * cucumber report compatibilty with TO * beforeEach, afterEach data added inside the test * fixed pickle data and step data * function name refactoring * added try catch to escape terminating the nightwatch server * emiiting only required data * removed unneccessary state file * test fixes * test case * cucumber rerun functinality fix * src_folders error fix * src_folders error fix * rerurn failed file fix for cucumber * rerun fix * added a check if NightwatchEventHub present already * small refactoring * removed unnecessary import * multiple gherkinDocument envelope fix * paased nightwatch formatter as array * moving nightwatch format to last * sessionid and capabilities setup if auto_start_session set as false * small fix for hooks * added deepcopy of envelope * added lodash deepcopy package * refactor cucumber to work with typescript changes * package.json changes to make this repo installable * fix missing tsc * fix missing tsc * fix missing tsc * fix missing tsc * added support for parallelism * write report error fix in cucumber parallelism * write report error fix in cucumber parallelism * adding host, port in cucumber report * session capabilities for parallel tests * merge require cli and config options * lint fix * test fixes * removing not necessary only * removing clonedeep * SessionCapabilities handling in parallel mode * bug fix: require cucumber only when needed * session capabilities fix for parallel in cucumber (cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8) * code refactoring * Feat/to integration (#18) * session capabilities fix for parallel in cucumber (cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8) * code refactoring * logs session capability logs * logs session capability logs (cherry picked from commit 9842ff7) * capabilities session issue fix * capabilities session issue fix (cherry picked from commit be6a6ec) * capabilities issue fix (cherry picked from commit 323c3940b9a57a6c750bc1ffc168de1cca711c1a) * handling the case when auto_start_session will be false * code refactoring for capabilities issue (cherry picked from commit 370c01e) (cherry picked from commit 0c2e119) * fix tests * fix few tests * remove color param from mocha cli runner tests --------- Co-authored-by: Binayak Ghosh <ghoshbinayak@gmail.com> Co-authored-by: Ravi Sawlani <ravisawlani04@gmail.com>
- Loading branch information
1 parent
917fc7d
commit 460d28a
Showing
35 changed files
with
1,152 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const EventEmitter = require('events'); | ||
const {Logger, createFolder} = require('../utils'); | ||
|
||
class NightwatchEventHub extends EventEmitter { | ||
emit(eventName, data) { | ||
if (this.isAvailable) { | ||
try { | ||
super.emit(eventName, data); | ||
} catch (err) { | ||
Logger.error(err); | ||
} | ||
} | ||
|
||
if (eventName === 'TestFinished' && this.output_folder && this.runner === 'cucumber') { | ||
let {output_folder} = this; | ||
output_folder = path.join(output_folder, 'cucumber'); | ||
const filename = path.join(output_folder, 'cucumber-report.json'); | ||
|
||
this.writeReportFile(filename, JSON.stringify(data.report, null, 2), true, output_folder) | ||
.then(_ => { | ||
Logger.info(Logger.colors.stack_trace(`Wrote JSON report file to: ${path.resolve(filename)}`)); | ||
}); | ||
} | ||
} | ||
|
||
get isAvailable() { | ||
return this.eventFnExist; | ||
} | ||
|
||
set isAvailable(eventFnExist) { | ||
this.eventFnExist = eventFnExist; | ||
} | ||
|
||
set runner(type) { | ||
this.runnerType = type; | ||
} | ||
|
||
get runner() { | ||
return this.runnerType; | ||
} | ||
|
||
writeReportFile(filename, rendered, shouldCreateFolder, output_folder) { | ||
return (shouldCreateFolder ? createFolder(output_folder) : Promise.resolve()) | ||
.then(() => { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(filename, rendered, function(err) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
const instance = new NightwatchEventHub(); | ||
|
||
module.exports = { | ||
NightwatchEventHub: instance, | ||
COMMON_EVENTS: { | ||
ScreenshotCreated: 'ScreenshotCreated' | ||
}, | ||
DEFAULT_RUNNER_EVENTS: { | ||
GlobalHook: { | ||
before: { | ||
started: 'GlobalBeforeStarted', | ||
finished: 'GlobalBeforeFinished' | ||
}, | ||
|
||
beforeChildProcess: { | ||
started: 'GlobalBeforeChildProcessStarted', | ||
finished: 'GlobalBeforeChildProcessFinished' | ||
}, | ||
|
||
beforeEach: { | ||
started: 'GlobalBeforeEachStarted', | ||
finished: 'GlobalBeforeEachFinished' | ||
}, | ||
|
||
afterEach: { | ||
started: 'GlobalAfterEachStarted', | ||
finished: 'GlobalAfterEachFinished' | ||
}, | ||
|
||
afterChildProcess: { | ||
started: 'GlobalAfterChildProcessStarted', | ||
finished: 'GlobalAfterChildProcessFinished' | ||
}, | ||
|
||
after: { | ||
started: 'GlobalAfterStarted', | ||
finished: 'GlobalAfterFinished' | ||
} | ||
}, | ||
|
||
TestSuiteHook: { | ||
started: 'TestSuiteStarted', | ||
finished: 'TestSuiteFinished', | ||
|
||
before: { | ||
started: 'BeforeStarted', | ||
finished: 'BeforeFinished' | ||
}, | ||
|
||
beforeEach: { | ||
started: 'BeforeEachStarted', | ||
finished: 'BeforeEachFinished' | ||
}, | ||
|
||
test: { | ||
started: 'TestRunStarted', | ||
finished: 'TestRunFinished' | ||
}, | ||
|
||
afterEach: { | ||
started: 'AfterEachStarted', | ||
finished: 'AfterEachFinished' | ||
}, | ||
|
||
after: { | ||
started: 'AfterStarted', | ||
finished: 'AfterFinished' | ||
} | ||
}, | ||
|
||
LogCreated: 'LogCreated' | ||
}, | ||
CUCUMBER_RUNNER_EVENTS: { | ||
TestStarted: 'TestStarted', | ||
TestFinished: 'TestFinished', | ||
TestCaseStarted: 'TestCaseStarted', | ||
TestCaseFinished: 'TestCaseFinished', | ||
TestStepStarted: 'TestStepStarted', | ||
TestStepFinished: 'TestStepFinished' | ||
} | ||
}; |
Oops, something went wrong.