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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workers): event improvements #3953

Merged
merged 33 commits into from Dec 5, 2023
Merged

fix(workers): event improvements #3953

merged 33 commits into from Dec 5, 2023

Conversation

kobenguyent
Copy link
Collaborator

@kobenguyent kobenguyent commented Oct 26, 2023

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)

Copy link
Contributor

@DavertMik DavertMik left a comment

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

docs/internal-api.md Outdated Show resolved Hide resolved
lib/workers.js Outdated Show resolved Hide resolved
@exotlv
Copy link

exotlv commented Nov 15, 2023

@DavertMik can you please re-check changes ?

@exotlv
Copy link

exotlv commented Nov 28, 2023

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

docs/internal-api.md Outdated Show resolved Hide resolved
@kobenguyent kobenguyent merged commit 8926f9c into 3.x Dec 5, 2023
12 checks passed
@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.

None yet

4 participants