mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 01:06:00 +03:00
[PR #4189] [MERGED] feat(cli): add support for JUnit reporter #4692
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4692
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/4189
Author: @jamesgeorge007
Created: 7/16/2024
Status: ✅ Merged
Merged: 7/26/2024
Merged by: @jamesgeorge007
Base:
next← Head:feat/cli-junit-reporter📝 Commits (5)
11d1ab9feat: add support for JUnit reporter in the CLI7e2cbfftest: increase coverage241b859chore: bump CLI version5c4db95chore: update report export formatc75cca5chore: cleanup📊 Changes
15 files changed (+1197 additions, -64 deletions)
View changed files
📝
packages/hoppscotch-cli/package.json(+6 -3)➕
packages/hoppscotch-cli/src/__tests__/e2e/commands/__snapshots__/test.spec.ts.snap(+529 -0)📝
packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts(+163 -2)➕
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/test-junit-report-export-coll.json(+150 -0)📝
packages/hoppscotch-cli/src/commands/test.ts(+2 -2)📝
packages/hoppscotch-cli/src/handlers/error.ts(+4 -0)📝
packages/hoppscotch-cli/src/index.ts(+16 -1)📝
packages/hoppscotch-cli/src/types/commands.ts(+1 -0)📝
packages/hoppscotch-cli/src/types/errors.ts(+1 -0)📝
packages/hoppscotch-cli/src/utils/collections.ts(+76 -37)📝
packages/hoppscotch-cli/src/utils/pre-request.ts(+4 -1)➕
packages/hoppscotch-cli/src/utils/reporters/junit.ts(+178 -0)📝
packages/hoppscotch-cli/src/utils/request.ts(+7 -6)📝
packages/hoppscotch-cli/tsconfig.json(+2 -1)📝
pnpm-lock.yaml(+58 -11)📄 Description
Closes HFE-536, #4085.
Description
This PR adds the ability to create JUnit report export for collection runs in the CLI via a newly added
--reporter-junit [path]flag. The report gets generated under the namehopp-junit-report.xmlin the current path if the path is not specified.Report format
Consider a collection with two requests:
req1Sends a
postrequest toecho.hoppscotch.io.Content type set to
application/json.Raw body specified as
req2Invalid endpoint.
Reference error within the test script.
The JUnit XML report contents generated are:
<parent-collection-name</<child-collection-name>/<request-name>. The name combines all the collection names till the request.pw.test()scripting API method with nested test cases. In JUnit reports, nested test suites are flattened, so the test cases corresponding topw.expect()invocations appear as direct children to the request-level test suite, with names prefixed with the respective test suite description. In the generated report,req1has three test suites, each containing different test cases. These test cases are all represented through thetestcaseelements, with the test suite descriptions serving as prefixes.failureelement nested under thetestcaseelement, while errors during assertions via theerrorelement.classnameattribute at eachtestcaselevel is set to the same value as thenameattribute at thetestsuitelevel.system-errelement with the specifics underCDATA. It is to be noted that the report follows a convention where errors reported at the request level are compiled in a singleCDATAelement separated by newlines.timeattribute and the total time is recorded at the top-level test suite.timestampattribute set at all request-level test suite elements indicating the date in ISO string format.tests,failuresanderrorsattributes respectively at all the request-level test suite elements and the effective count at the root test suite. When errors are reported at the request level, all the above attributes will be set to0since the test suite halts and no further test cases get executed.Note to reviewers
We evaluated both junit-report-builder and xmlbuilder2 libraries and decided to go ahead with the latter, since it offers more fine-grained control, being a generic XML document builder catering to our requirements.
To verify the behaviour:
pnpm iat the project root (CLI now includes apostinstallscript that runs thebuildscript) and navigate to the CLI package path./src/__tests__/e2e/fixtures/collections/.....🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.