Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: event setup for nightwatch hooks #3706

Merged
merged 106 commits into from
Sep 26, 2023

Conversation

harshit-bs
Copy link
Member

@harshit-bs harshit-bs commented Apr 21, 2023

Supported Events

Default Nightwatch Runner Events

  1. GlobalBeforeStarted
  2. GlobalBeforeFinished
  3. GlobalBeforeChildProcessStarted
  4. GlobalBeforeChildProcessFinished
  5. GlobalBeforeEachStarted
  6. GlobalBeforeEachFinished
  7. GlobalAfterEachStarted
  8. GlobalAfterEachFinished
  9. GlobalAfterChildProcessStarted
  10. GlobalAfterChildProcessFinished
  11. GlobalAfterStarted
  12. GlobalAfterFinished
  13. TestSuiteStarted
  14. TestSuiteFinished
  15. BeforeStarted
  16. BeforeFinished
  17. BeforeEachStarted
  18. BeforeEachFinished
  19. TestRunStarted
  20. TestRunFinished
  21. AfterEachStarted
  22. AfterEachFinished
  23. AfterStarted
  24. AfterFinished
  25. LogCreated

Cucumber Runner Events

  1. TestStarted
  2. TestFinished
  3. TestCaseStarted
  4. TestCaseFinished
  5. TestStepStarted
  6. TestStepFinished

Common Events

  1. ScreenshotCreated

Subscribing to Events

In order to subscribe to the events, the user has the option to define an registerEventHandlers function within the globals of either NightwatchJS or plugins.

Here's how you could define an registerEventHandlers function to handle these events:

module.exports = {
  // Custom reporter
  reporter: function(results, done) {
    // do something with the results
    done(results);
  },
  
  registerEventHandlers(eventBroadcaster) {
    eventBroadcaster.on('TestRunStarted', (args) => console.log('test run started'));
    eventBroadcaster.on('TestRunFinished', (args) => console.log('test run finished'))
  };
}

@harshit-bs harshit-bs changed the title Feat: event setup for nightwatch hooks [WIP] Feat: event setup for nightwatch hooks Apr 21, 2023
lib/runner/cli/cli.js Outdated Show resolved Hide resolved
lib/runner/cli/cli.js Outdated Show resolved Hide resolved
@harshit-bs harshit-bs force-pushed the feat/TO-integration branch from f99ac04 to cc27a54 Compare May 9, 2023 10:58
@harshit-bs harshit-bs marked this pull request as ready for review May 22, 2023 14:37
lib/runner/cli/cli.js Outdated Show resolved Hide resolved
lib/runner/eventHub.js Outdated Show resolved Hide resolved
@gravityvi
Copy link
Member

is it possible to give out instance of event emitter to plugins and globals? In this approach we are iterating over plugins for each event emission which I don't think is optimally correct. Also why can't we emit specific events instead of emitting one global event and running all the functions on each plugin.

Example:
at plugin level the implementation wuold look like

onEvent(eventBroadcaster) {
    eventBroadcaster.on('TestRunStarted', () => consol.log('test run started'))
  // ....
}

@swrdfish
Copy link
Member

swrdfish commented May 26, 2023

is it possible to give out instance of event emitter to plugins and globals? In this approach we are iterating over plugins for each event emission which I don't think is optimally correct. Also why can't we emit specific events instead of emitting one global event and running all the functions on each plugin.

Example: at plugin level the implementation wuold look like

onEvent(eventBroadcaster) {
    eventBroadcaster.on('TestRunStarted', () => consol.log('test run started'))
  // ....
}

@gravityvi It possible to pass in the event emitter. I came up with this approach because the api looked a bit strange to me (onEvent gives the notion that the function will be called on some event). But since you have pointed it out, this approach IS less efficient. Thinking about it again I guess something like this should be good. What do you think?

 setEventHandlers(eventBroadcaster) {
     eventBroadcaster.on('TestRunStarted', () => consol.log('test run started'))
   // ....
 }

@beatfactor What are your thoughts? How should the API look?

@github-actions
Copy link

Status

  • ❌ No modified files found in the types directory.
    Please make sure to include types for any changes you have made. Thank you!.

harshit-bs and others added 19 commits July 17, 2023 21:30
bug fix: require cucumber only when needed
(cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8)
* session capabilities fix for parallel in cucumber

(cherry picked from commit a787b37b37307d8e30ce2539721697c611235bb8)

* code refactoring
(cherry picked from commit 9842ff7)
(cherry picked from commit be6a6ec)
(cherry picked from commit 323c3940b9a57a6c750bc1ffc168de1cca711c1a)
(cherry picked from commit 370c01e)
(cherry picked from commit 0c2e119)
@gravityvi gravityvi marked this pull request as draft September 22, 2023 09:36
@gravityvi gravityvi marked this pull request as ready for review September 22, 2023 11:05
@AutomatedTester AutomatedTester merged commit 460d28a into nightwatchjs:main Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants