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

Changing the processing of parallel events #353

Merged
merged 3 commits into from
Sep 28, 2021

Conversation

kolbasik
Copy link
Contributor

@kolbasik kolbasik commented Sep 10, 2021

Purposes:

  • to make the same report with parallel mode as the report with sync mode

@juergba suggested to serialize tests in suites and listen to EVENT_SUITE_END event: #331 (comment)
This should allow to calculate the correct amount of SKIPPED tests.

I have tried to set runner.linkPartialObjects(true) and listen the EVENT_SUITE_END to recreate the suite's tree. It does not work for the nested suites if any hooks failed in the parent suite.
Thus, the only solution was to make a full dump of the root suite and listen it in the EVENT_SUITE_END event.
The disadvantage of this is that a full dump is created twice for the EVENT_SUITE_BEGIN and EVENT_SUITE_AND events, which increases data transfer via IPC by 25%. For comparison, I have used test-functional tests, and the data transfer is 27.04 MB, when if a full dump was made once, it would be 22.17 MB.

In additional:

  • fixed the error serialization

Unrelated changes:

  • used npm ci instead of npm install
  • used actions/setup-node@v2 with cache: 'npm' option

@@ -125,74 +116,24 @@ function Mochawesome(runner, options) {

let endCalled = false;

// Add a unique identifier to each suite/test/hook
Copy link
Owner

Choose a reason for hiding this comment

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

Did you intend to remove this block? It is still needed by the reporter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adamgruber, you're right, I have returned it back.
For some reason, I thought it was mine when I did parallel support.

@kolbasik
Copy link
Contributor Author

PS: I have used the following code to cleanup volatile variables from the mochawsome.json with sync and parallel mode.

const fs = require("fs");

const clean = (s) => {
    if (s == null) {
        return
    }
    if (Array.isArray(s)) {
        s.forEach(clean);
    } else if (typeof s === "object") {
        for (let prop of Object.keys(s)) {
            switch (prop) {
                case "estack": {
                    if (typeof s[prop] === "string");
                        s[prop] = s[prop].slice(0, 50);
                    break;
                }
                case "start":
                case "end":
                case "uuid": {
                    if (typeof s[prop] === "string")
                        delete s[prop];
                    continue;
                }
                case "parentUUID": {
                    delete s[prop];
                    continue;
                }
                case "passes":
                case "skipped":
                case "failures": {
                    if (Array.isArray(s[prop]))
                        delete s[prop];
                    continue;
                }
                case "pending": {
                    if (Array.isArray(s[prop]) || s[prop] == null || s[prop] === false) {
                        delete s[prop];
                        continue;
                    }
                    break;
                }
                case "duration":
                case "_timeout":
                case "timedOut": {
                    delete s[prop];
                    continue;
                }
            }
            clean(s[prop])
        }
    }
}

const make = (d) => {
    const path = `mochawesome-report-${d}/mochawesome.json`
    const p = JSON.parse(fs.readFileSync(path, { encoding: "utf8" }))
    clean(p);
    fs.writeFileSync(`mochawesome-${d}.json`, JSON.stringify(p, null, 2), { encoding: "utf8" })
}

make("p")
make("s")

console.log("done.")

@kolbasik
Copy link
Contributor Author

@adamgruber , how much is critical when the mochawesome.json in parallel mode does not contain parentUUID?

@adamgruber
Copy link
Owner

@adamgruber , how much is critical when the mochawesome.json in parallel mode does not contain parentUUID?

parentUUID is not used directly in any of the components that render the report so I think it is ok if the JSON does not have it

@adamgruber
Copy link
Owner

Can you explain more what the code cleanup script does and why you need it?

@kolbasik
Copy link
Contributor Author

Can you explain more what the code cleanup script does and why you need it?

I have tried to compare the 2 mochawesome.json reports generated with parallel flag and without.
Since json contains data depended on time which are not comparable, I have removed it before making diff.

@kolbasik kolbasik marked this pull request as draft September 10, 2021 14:22
@kolbasik
Copy link
Contributor Author

I have marked as draft due to adjusting unit tests according to changes

@kolbasik kolbasik marked this pull request as ready for review September 11, 2021 18:15
@kolbasik
Copy link
Contributor Author

Hi, @adamgruber, could you please take a look at my changes? I have covered everything with unit tests

@adamgruber adamgruber merged commit b853d50 into adamgruber:master Sep 28, 2021
@kolbasik
Copy link
Contributor Author

Hi @adamgruber , thank you very much 🙇🏼

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.

None yet

2 participants