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

Add mocha reporter #6

Merged
merged 8 commits into from
Dec 14, 2023
Merged

Add mocha reporter #6

merged 8 commits into from
Dec 14, 2023

Conversation

devpow112
Copy link
Contributor

@devpow112 devpow112 commented Dec 13, 2023

Adds a reporter for mocha. Doesn't output anything related to lms stuff or for each test tool, experience, type or browser. Coming soon. Covers all the require fields. Eventually will move the mocha report out into it's own repo/package (probably test-reporting-node/@d2l/test-reporting or @brightspace/test-reporting). Looking at adding a d2l-test-reporting.config.json type of file to help with the missing elements. LMS stuff will probably have to be from environment variables or set directly on the action upload stuff.

@devpow112 devpow112 added the enhancement New feature or request label Dec 13, 2023
@devpow112 devpow112 force-pushed the depowell/mocha-reporter branch from 0997a9a to feb89d6 Compare December 13, 2023 21:27
@devpow112 devpow112 force-pushed the depowell/mocha-reporter branch from feb89d6 to cba2ad5 Compare December 13, 2023 21:30
@devpow112

This comment was marked as outdated.

@devpow112
Copy link
Contributor Author

devpow112 commented Dec 13, 2023

I'm starting to wonder if I should have the reporter itself output the github/git fields if it can detect if it's in github and only have the action add them if they aren't present. Would allow you to do something like generate a report in 1 job and upload in another without misreporting the data. There could be issues with this though since the data is all gleaned from environment variables. My tests for example override some of those environment variables in order to run the test correctly. Something I can look at in a future PR. Just rambling.

@devpow112 devpow112 marked this pull request as ready for review December 13, 2023 22:08
@devpow112 devpow112 requested a review from a team December 13, 2023 22:08
@devpow112 devpow112 enabled auto-merge (squash) December 13, 2023 22:10
Comment on lines +38 to +43
const makeLocation = (filePath) => {
const path = relative(process.cwd(), filePath);
const pathParts = path.split(platformSeparator);

return join(...pathParts);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be something I can pull out into a common helper for reporters.

Comment on lines +21 to +32
const getOperatingSystem = () => {
switch (type()) {
case 'Linux':
return 'linux';
case 'Darwin':
return 'macos';
case 'Windows_NT':
return 'windows';
default:
throw new Error('Unknown operating system');
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be something I can pull out into a common helper for reporters.

@devpow112
Copy link
Contributor Author

Added flaky stuff. Report now looks like this

{
  "reportId": "4c5a0e8f-8294-4104-a159-ba39c34694a9",
  "reportVersion": 1,
  "summary": {
    "operatingSystem": "windows",
    "framework": "mocha",
    "started": "2023-12-13T22:27:16.865Z",
    "totalDuration": 2025,
    "state": "passed",
    "countPassed": 8,
    "countFailed": 0,
    "countSkipped": 1,
    "countFlaky": 1
  },
  "details": [
    {
      "name": "github > logger logs",
      "started": "2023-12-13T22:27:16.869Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 1,
      "status": "passed",
      "duration": 1
    },
    {
      "name": "github > get context > pull request",
      "started": "2023-12-13T22:27:16.871Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 3,
      "status": "passed",
      "duration": 3
    },
    {
      "name": "github > get context > branch",
      "started": "2023-12-13T22:27:16.876Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 1,
      "status": "passed",
      "duration": 1
    },
    {
      "name": "github > get context > fails > missing input",
      "started": "2023-12-13T22:27:16.877Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 0,
      "status": "passed",
      "duration": 0
    },
    {
      "name": "github > get inputs > succeeds",
      "started": "2023-12-13T22:27:16.879Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 1,
      "status": "passed",
      "duration": 1
    },
    {
      "name": "github > get inputs > fails > empty input",
      "started": "2023-12-13T22:27:16.881Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 1,
      "status": "passed",
      "duration": 1
    },
    {
      "name": "github > get inputs > fails > non-existent report path",
      "started": "2023-12-13T22:27:16.882Z",
      "location": "test/github.test.js",
      "retries": 0,
      "totalDuration": 1,
      "status": "passed",
      "duration": 1
    },
    {
      "name": "reporter > skipped test",
      "started": "2023-12-13T22:27:16.884Z",
      "location": "test/reporter.test.js",
      "retries": 0,
      "totalDuration": 0,
      "status": "skipped",
      "duration": 0
    },
    {
      "name": "reporter > flaky test",
      "started": "2023-12-13T22:27:16.884Z",
      "location": "test/reporter.test.js",
      "retries": 2,
      "totalDuration": 2003,
      "status": "passed",
      "duration": 0
    }
  ]
}

sarahboyd
sarahboyd previously approved these changes Dec 14, 2023
@devpow112
Copy link
Contributor Author

Had to merge main and resolve some conflicts. No other changes.

@amommersteeg-d2l
Copy link

To get lms information it maybe a mix of the output from the framework reporter and the github runner. For example in playwright-ui repo the base url is set in a config file so it would be best to get it from the report. But things like lms version with have to come from the runner. If needed Sam figured out how to use this API in a github workflow, https://instance-metadata.d2l.dev/

@devpow112

This comment was marked as resolved.

@devpow112 devpow112 disabled auto-merge December 14, 2023 14:44
@devpow112 devpow112 merged commit 330c52c into main Dec 14, 2023
3 checks passed
@devpow112 devpow112 deleted the depowell/mocha-reporter branch December 14, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants