Skip to content

feat(Inso): add an overall run collection test result summary - #8739

Merged
ZxBing0066 merged 5 commits into
developfrom
feat/inso-add-summary-report
May 22, 2025
Merged

feat(Inso): add an overall run collection test result summary#8739
ZxBing0066 merged 5 commits into
developfrom
feat/inso-add-summary-report

Conversation

@ZxBing0066

@ZxBing0066 ZxBing0066 commented May 20, 2025

Copy link
Copy Markdown
Member

Background

INS-5567, part of Kong/insomnia-docs#273

Changes

  • Extract the test reporter-related code to a new file
  • Add an overall test result summary that summarizes all the requests and tests
  • Simplify the current test summary for one request
  • Add tests for the reporter

Before

iShot_2025-05-20_16 21 40

After

iShot_2025-05-20_16 21 06

@ZxBing0066
ZxBing0066 requested review from a team, Copilot and jackkav May 20, 2025 08:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new test-result reporter module and integrates it into the CLI, extracting reporter logic, summarizing results across requests, and covering behaviors with unit tests.

  • Extract reporter logic from cli.ts into reporter/index.ts
  • Introduce logTestResultSummary to aggregate results over multiple requests
  • Update CLI to use the new reporter functions and remove old inline reporter code

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/insomnia-inso/src/reporter/index.ts New module defining reporters and summary logic
packages/insomnia-inso/src/reporter/index.test.ts Tests covering each reporter type and summary
packages/insomnia-inso/src/reporter/snapshots Snapshots validating reporter output formatting
packages/insomnia-inso/src/cli.ts Removed inline reporter code and now calling new reporter functions
packages/insomnia-inso/package.json Added picocolors dependency for colored output
Comments suppressed due to low confidence (1)

packages/insomnia-inso/src/reporter/index.ts:50

  • [nitpick] The name fallbackReporter is somewhat generic. Renaming it to something like listOutput or defaultReporterOutput could make its purpose clearer.
const fallbackReporter = testResults.map(r => `${r.status === 'passed' ? '✅' : '❌'} ${r.testCase}`).join('\n');

Comment thread packages/insomnia-inso/src/reporter/index.ts
Comment thread packages/insomnia-inso/src/cli.ts
@ZxBing0066
ZxBing0066 marked this pull request as draft May 20, 2025 08:31
@ZxBing0066 ZxBing0066 self-assigned this May 20, 2025
@ZxBing0066
ZxBing0066 marked this pull request as ready for review May 20, 2025 09:01
@ZxBing0066
ZxBing0066 requested a review from ihexxa May 22, 2025 06:04
@ZxBing0066 ZxBing0066 changed the title feat(Inso): add test result summary feat(Inso): add an overall run collection test result summary May 22, 2025
"consola": "^2.15.3",
"cosmiconfig": "^9.0.0",
"enquirer": "^2.4.1",
"picocolors": "^1.1.1",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

have you evaluated this dep for maintainability?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jackkav Yes, it has 1.5k stars and fewer than ten issues. Its npm weekly downloads is 84 million. And it's a dependent of mocha, postcss, ...etc.
Compare with chalk, it's much smaller and quicker.

);
let success = true;

const testResultsQueue: RequestTestResult[][] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think queue may be a misleading name here, its an array of test results, test result list is as ambiguous without implying that it has any special queue processing step

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I was thinking about the future reporter design and then named it as queue, didn't notice it. Has been renamed to testResultsList.

Comment on lines +11 to +18
beforeEach(() => {
console.log = mockConsoleLog;
mockConsoleLog.mockClear();
});

afterEach(() => {
console.log = originalConsoleLog;
});

@jackkav jackkav May 22, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I generally consider mocking a code smell, heres how I would address this particular one.
Is it reasonable to modify the function such that it can be responsible for less? In this case generate the output and return a string to test, rather than generate the output and also log it.
This would also improve the quality of the code as it would be a pure function which is more composable and extensible.
Another implementation option would be to pass a log function down rather than returning a string.
Both ways you can avoid managing mock state in your test and eliminate the cruft in your test assertions, which cuts down the amount of code in your tests, and improves readability.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I’ve added a log parameter to accept a logging function and removed the mock.
I'm also considering mocking it globally — otherwise, in some cases, we might have to modify the production code just to make the test work, which is something we should avoid.

@jackkav jackkav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work extending the feature, couple of comments to address but great start.

@ZxBing0066

Copy link
Copy Markdown
Member Author

Hi @jackkav, thanks for the comments. I made some changes based on them. Could you take another look? Thank you. 🙏

@ZxBing0066
ZxBing0066 enabled auto-merge (squash) May 22, 2025 09:51
@ZxBing0066
ZxBing0066 merged commit ce74f30 into develop May 22, 2025
@ZxBing0066
ZxBing0066 deleted the feat/inso-add-summary-report branch May 22, 2025 09:55
RoamingLost pushed a commit to RoamingLost/insomnia that referenced this pull request Aug 6, 2025
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.

3 participants