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

feature (reporter): issue #1814 Add json reporter #2601

Closed
wants to merge 1 commit into from
Closed

feature (reporter): issue #1814 Add json reporter #2601

wants to merge 1 commit into from

Conversation

dance-cmdr
Copy link

This is a solution for issue #1814 that I opened ages ago! This is my second attempt!

I used HTML reporter as the guideline and tried to keep the code as faithfully to current code style as possible.

It is a very simple solution. I just dump the report: MutationTestResult POJO that is generated onMutationTestReportReady in a JSON file.

json-reporter-util.ts is almost the same as html-reporter-util.ts but I decided to go with it because I didn't know if you'd like to generalise and move file handling util functions outside reporters.

Please drop me a line If I've done something wrong!!!

@dance-cmdr dance-cmdr changed the title issue #1814 (feature): Add json reporter feature (reporter): issue #1814 Add json reporter Oct 30, 2020
Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

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

Thanks @dance-cmdr for this PR. I've got some remarks. Do you still have time to fix them? If not, we can merge it in and I can change it before we release 4.2.

@@ -0,0 +1,19 @@
import * as path from 'path';
Copy link
Member

Choose a reason for hiding this comment

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

This is actually a duplication of the code in html-reporter-util.ts. Can we rename that file to reporter-util and reuse the writeFile implementation from that file?

"baseDir": {
"description": "The output folder for the json report.",
"type": "string",
"default": "reports/mutation/json"
Copy link
Member

Choose a reason for hiding this comment

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

Since the JSON report will be a single file, I think it makes sense to default to reports/mutation here. So

@@ -349,6 +361,10 @@
"description": "The options for the html reporter",
"$ref": "#/definitions/htmlReporterOptions"
},
"jsonReporter": {
"description": "The options for the json reporter",
"$ref": "#/definitions/jsonReporterOptions"
Copy link
Member

Choose a reason for hiding this comment

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

Please fill the default here with {}. That way, you don't need to check if options.jsonReporter` is null later, or duplicate the default value of "jsonReporterOptions.baseDir".

this.log.info(`Your report can be found at: ${fileUrl(indexFileName)}`);
}

private get baseDir(): string {
Copy link
Member

Choose a reason for hiding this comment

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

As stated earlier, this null check is no longer needed if you use "default": {} for the jsonReporter option. The base dir inside the StrykerOptions will always be filled with a string.

}

private async cleanBaseFolder(): Promise<void> {
await deleteDir(this.baseDir);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to delete the baseDir, since it is a single file report. We will just override this file whenever onMutationTestingReportReady is called.

@@ -102,7 +102,8 @@
"preprocessors",
"serializable",
"surrialize"
]
],
"compile-hero.disable-compile-files-on-did-save-code": false
Copy link
Member

Choose a reason for hiding this comment

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

What is this?

Copy link
Author

Choose a reason for hiding this comment

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

That went in by mistake. It's a markdown plugin I have.

@Tummerhore Tummerhore mentioned this pull request Nov 5, 2020
@Tummerhore
Copy link
Contributor

@dance-cmdr Nice to see that you are back and gave this another shot :)
But why exactly did you open a new PR which is mostly the same as mine already created before (see #2582)? I've also read the remarks from @nicojs here and incorporated them into my PR if applicable, namely renaming the html util file.

@dance-cmdr
Copy link
Author

@dance-cmdr Nice to see that you are back and gave this another shot :)

But why exactly did you open a new PR which is mostly the same as mine already created before (see #2582)? I've also read the remarks from @nicojs here and incorporated them into my PR if applicable, namely renaming the html util file.

Hey, this is part of a project I'm doing and I didn't know if your PR is still active and I didn't feel confident to check out your branch.

@nicojs
Copy link
Member

nicojs commented Nov 6, 2020

Thanks for the help, but since then merged with #2582

@nicojs nicojs closed this Nov 6, 2020
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

3 participants