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

Filename inheritance option #380

Open
ittaibaratz opened this issue Aug 24, 2022 · 0 comments
Open

Filename inheritance option #380

ittaibaratz opened this issue Aug 24, 2022 · 0 comments

Comments

@ittaibaratz
Copy link

ittaibaratz commented Aug 24, 2022

Is your feature request related to a problem? Please describe.

We noticed that for Cypress based reports, the spec filename does not show up as shown on your example:
image

Our tests:
image

As shown above, the spec name does not show up for Cypress. When I inspected the generated Mochawesome JSON, I found that the file and fullFile fields are populated at the very top level, but not in the levels below, i.e.:

  "results": [
    {
      "uuid": "c9b3f06c-e9f9-4630-bce6-2f67334403eb",
      "title": "",
      "fullFile": "cypress/integration/ajo/dashboards.spec.ts",
      "file": "cypress/integration/ajo/dashboards.spec.ts",
      "beforeHooks": [],
      "afterHooks": [],
      "tests": [],
      "suites": [
        {
          "uuid": "132ab838-79ba-4f2f-a6b1-86a96d848810",
          "title": "Dashboards",
          "fullFile": "",
          "file": "",
          "beforeHooks": [],
          "afterHooks": [],
          "tests": [
            {
              "title": "shows a welcome message",
              "fullTitle": "Dashboards shows a welcome message",
              "timedOut": null,
              "duration": 4367,

To resolve, I've written the following workaround using recursive code in Cypress: (Not great, but works well)

    Cypress.on('test:before:run', (test: Cypress.ObjectLike, runnable: Mocha.Test) => {
      const getFile = (runner: Suite): string|undefined => {
        if (runner.file) {
          return runner.file;
        }

        if (runner.parent) {
          return getFile(runner.parent);
        }
        return undefined;
      };
      
      if (runnable.parent && !runnable.parent.file) {
        runnable.parent.file = getFile(runnable.parent);
      }
    });

image

Describe the solution you'd like

First, I am wondering if there's anything super obvious that I am missing here.

If there isn't, I wonder if it would make sense to add a configuration to mochawesome that allows inheriting the filename from the parent - Similar to what I did above, but when generating the JSON or HTML.

Describe alternatives you've considered

The alternative is the code I have above which works well. This is not urgent for me but I think it would be a nice addition for the Cypress community using Mochawesome. When testing 100s of specs, its extremely useful to have the spec filename in the report.

Additional context
Add any other context or screenshots about the feature request here.

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

No branches or pull requests

1 participant