Skip to content

fix(workers): event improvements - #3953

Merged
kobenguyent merged 33 commits into
3.xfrom
worker-event-improvements
Dec 5, 2023
Merged

fix(workers): event improvements#3953
kobenguyent merged 33 commits into
3.xfrom
worker-event-improvements

Conversation

@kobenguyent

@kobenguyent kobenguyent commented Oct 26, 2023

Copy link
Copy Markdown
Collaborator

Motivation/Description of the PR

  • Emit the workers.result event
You could get test stats when running with workers

const { event } = require('codeceptjs');

module.exports = function() {

  event.dispatcher.on(event.workers.result, function (result) {

    console.log(result);

  });
}

// in console log
FAIL  | 7 passed, 1 failed, 1 skipped   // 2s
{
    "tests": {
        "passed": [
            {
                "type": "test",
                "title": "Assert @C3",
                "body": "() => { }",
                "async": 0,
                "sync": true,
                "_timeout": 2000,
                "_slow": 75,
                "_retries": -1,
                "timedOut": false,
                "_currentRetry": 0,
                "pending": false,
                "opts": {},
                "tags": [
                    "@C3"
                ],
                "uid": "xe4q1HdqpRrZG5dPe0JG+A",
                "workerIndex": 3,
                "retries": -1,
                "duration": 493,
                "err": null,
                "parent": {
                    "title": "My",
                    "ctx": {},
                    "suites": [],
                    "tests": [],
                    "root": false,
                    "pending": false,
                    "_retries": -1,
                    "_beforeEach": [],
                    "_beforeAll": [],
                    "_afterEach": [],
                    "_afterAll": [],
                    "_timeout": 2000,
                    "_slow": 75,
                    "_bail": false,
                    "_onlyTests": [],
                    "_onlySuites": [],
                    "delayed": false
                },
                "steps": [
                    {
                        "actor": "I",
                        "name": "amOnPage",
                        "status": "success",
                        "agrs": [
                            "https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST"
                        ],
                        "startedAt": 1698760652610,
                        "startTime": 1698760652611,
                        "endTime": 1698760653098,
                        "finishedAt": 1698760653098,
                        "duration": 488
                    },
                    {
                        "actor": "I",
                        "name": "grabCurrentUrl",
                        "status": "success",
                        "agrs": [],
                        "startedAt": 1698760653098,
                        "startTime": 1698760653098,
                        "endTime": 1698760653099,
                        "finishedAt": 1698760653099,
                        "duration": 1
                    }
                ]
            }
        ],
        "failed": [],
        "skipped": []
    }
}

CodeceptJS also exposes the env var process.env.RUNS_WITH_WORKERS when running tests with run-workers command so that you could handle the events better in your plugins/helpers

const { event } = require('codeceptjs');

module.exports = function() {
    // this event would trigger the  `_publishResultsToTestrail` when running `run-workers` command
  event.dispatcher.on(event.workers.result, async () => {
    await _publishResultsToTestrail();
  });
  
  // this event would not trigger the  `_publishResultsToTestrail` multiple times when running `run-workers` command
  event.dispatcher.on(event.all.result, async () => {
      // when running `run` command, this env var is undefined
    if (!process.env.RUNS_WITH_WORKERS) await _publishResultsToTestrail();
  });
}

Type of change

  • 🐛 Bug fix

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@DavertMik DavertMik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't think we can accept this implementation
This will cause extra side effects from main thread like starting/closing browsers, which is not required there

Comment thread docs/internal-api.md Outdated
Comment thread lib/workers.js Outdated
@kobenguyent
kobenguyent force-pushed the worker-event-improvements branch from d063310 to 8c2212b Compare November 7, 2023 09:04
@exotlv

exotlv commented Nov 15, 2023

Copy link
Copy Markdown

@DavertMik can you please re-check changes ?

@exotlv

exotlv commented Nov 28, 2023

Copy link
Copy Markdown

@DavertMik can you please review? Need this changes/fixes

Comment thread docs/internal-api.md Outdated
@kobenguyent
kobenguyent merged commit 8926f9c into 3.x Dec 5, 2023
@kobenguyent
kobenguyent deleted the worker-event-improvements branch December 5, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants