|
1 | 1 | import type { ExecException } from 'node:child_process'; |
2 | 2 | import { exec } from 'node:child_process'; |
| 3 | +import fs from 'node:fs'; |
| 4 | +import { tmpdir } from 'node:os'; |
3 | 5 | import path from 'node:path'; |
4 | 6 |
|
5 | 7 | import { beforeAll, describe, expect, it } from 'vitest'; |
@@ -144,8 +146,7 @@ describe('inso dev bundle', () => { |
144 | 146 | }); |
145 | 147 |
|
146 | 148 | it('send request with client cert and key', async () => { |
147 | | - const input = |
148 | | - `$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withCertAndCA" --verbose "Insomnia Designer" wrk_0b96eff -f $PWD/packages`; |
| 149 | + const input = `$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withCertAndCA" --verbose "Insomnia Designer" wrk_0b96eff -f $PWD/packages`; |
149 | 150 | const result = await runCliFromRoot(input); |
150 | 151 | if (result.code !== 0) { |
151 | 152 | console.log(result); |
@@ -186,6 +187,69 @@ describe('inso dev bundle', () => { |
186 | 187 | expect(result.stdout).toContain('updated value from folder: 666'); |
187 | 188 | }); |
188 | 189 | }); |
| 190 | + |
| 191 | + describe('run collection report generation', () => { |
| 192 | + it.each([ |
| 193 | + { |
| 194 | + name: 'default report', |
| 195 | + input: |
| 196 | + '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/run-collection-result-report.yml wrk_c5d5b5 -e env_1072af', |
| 197 | + expectedReportFile: './fixtures/run-collection-report/default-report.json', |
| 198 | + }, |
| 199 | + { |
| 200 | + name: 'redact report', |
| 201 | + input: |
| 202 | + '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/run-collection-result-report.yml wrk_c5d5b5 -e env_1072af --includeFullData=redact --acceptRisk', |
| 203 | + expectedReportFile: './fixtures/run-collection-report/redact-report.json', |
| 204 | + }, |
| 205 | + { |
| 206 | + name: 'plaintext report', |
| 207 | + input: |
| 208 | + '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/run-collection-result-report.yml wrk_c5d5b5 -e env_1072af --includeFullData=plaintext --acceptRisk', |
| 209 | + expectedReportFile: './fixtures/run-collection-report/plaintext-report.json', |
| 210 | + }, |
| 211 | + ])('generate report: $name', async ({ input, expectedReportFile }) => { |
| 212 | + const root = path.join(tmpdir(), 'insomnia-cli-test-output'); |
| 213 | + const outputFilePath = path.resolve(root, 'run-collection-report-output.json'); |
| 214 | + |
| 215 | + const result = await runCliFromRoot(`${input} --output ${outputFilePath}`); |
| 216 | + expect(result.code).toBe(0); |
| 217 | + |
| 218 | + const expectedReport = JSON.parse(fs.readFileSync(path.resolve(__dirname, expectedReportFile), 'utf8')); |
| 219 | + expect(fs.existsSync(outputFilePath)).toBe(true); |
| 220 | + const report = JSON.parse(fs.readFileSync(outputFilePath, 'utf8')); |
| 221 | + |
| 222 | + // Some fields are dynamic so we use expect.any to validate their types/ existence |
| 223 | + expect(report).toEqual({ |
| 224 | + ...expectedReport, |
| 225 | + executions: expectedReport.executions.map((exec: any) => ({ |
| 226 | + ...exec, |
| 227 | + response: { |
| 228 | + ...exec.response, |
| 229 | + // executionTime can vary so just check it's a number |
| 230 | + responseTime: expect.any(Number), |
| 231 | + headers: exec.response.headers |
| 232 | + ? { |
| 233 | + ...exec.response.headers, |
| 234 | + date: expect.any(String), |
| 235 | + } |
| 236 | + : undefined, |
| 237 | + }, |
| 238 | + tests: exec.tests.map((test: any) => ({ |
| 239 | + ...test, |
| 240 | + executionTime: expect.any(Number), |
| 241 | + })), |
| 242 | + })), |
| 243 | + timing: { |
| 244 | + started: expect.any(Number), |
| 245 | + completed: expect.any(Number), |
| 246 | + responseAverage: expect.any(Number), |
| 247 | + responseMin: expect.any(Number), |
| 248 | + responseMax: expect.any(Number), |
| 249 | + }, |
| 250 | + }); |
| 251 | + }); |
| 252 | + }); |
189 | 253 | }); |
190 | 254 |
|
191 | 255 | const packagedSuccessCodes = shouldReturnSuccessCode.map(x => |
|
0 commit comments