From f4698cc18e130b48ac37772d840deeb16e5fb8c5 Mon Sep 17 00:00:00 2001 From: George He Date: Tue, 26 Nov 2024 10:34:12 +0800 Subject: [PATCH 1/2] fix(cli): should run requests according to the specified order --- packages/insomnia-inso/src/cli.test.ts | 15 ++++++++++++++- packages/insomnia-inso/src/cli.ts | 5 +++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/insomnia-inso/src/cli.test.ts b/packages/insomnia-inso/src/cli.test.ts index a61befd6fb0..4c7804b6b95 100644 --- a/packages/insomnia-inso/src/cli.test.ts +++ b/packages/insomnia-inso/src/cli.test.ts @@ -139,11 +139,24 @@ describe('inso dev bundle', () => { expect(result.stdout).toContain('Adding SSL KEY certificate'); }); - it('send request with settings enabled (followRedirects disabled)', async () => { + it('send request with settings enabled (by testing followRedirects)', async () => { const input = '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withSettings" --verbose "Insomnia Designer"'; const result = await runCliFromRoot(input); expect(result.stdout).not.toContain("Issue another request to this URL: 'https://insomnia.rest/'"); }); + + it('run collection: run requests in specified order', async () => { + const input = '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/three-requests.yml -i req_6063adcdab5b409e9b4f00f47322df4a -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -e env_86e135 --verbose'; + const result = await runCliFromRoot(input); + + expect(result.code).toBe(0); + const firstReqLogPosition = result.stdout.indexOf('Running request: 2 req_6063adcdab5b409e9b4f00f47322df4a'); + const secondReqLogPosition = result.stdout.indexOf('Running request: 1 req_3fd28aabbb18447abab1f45e6ee4bdc1'); + + expect(firstReqLogPosition).toBeGreaterThanOrEqual(0); + expect(secondReqLogPosition).toBeGreaterThanOrEqual(0); + expect(firstReqLogPosition < secondReqLogPosition).toBeGreaterThanOrEqual(0); + }); }); }); diff --git a/packages/insomnia-inso/src/cli.ts b/packages/insomnia-inso/src/cli.ts index 2566297fd2f..ccc78898321 100644 --- a/packages/insomnia-inso/src/cli.ts +++ b/packages/insomnia-inso/src/cli.ts @@ -542,6 +542,11 @@ export const go = (args?: string[]) => { return process.exit(1); } + // sort requests + const requestOrder = new Map(); + requestsToRun.forEach((req: BaseModel, order: number) => requestOrder.set(req._id, order)); + requestsToRun = requestsToRun.sort((a, b) => (requestOrder.get(a._id) || requestsToRun.length) - (requestOrder.get(b._id) || requestsToRun.length)); + try { const iterationCount = parseInt(options.iterationCount, 10); From d035c81fdd2288200202e733a1442b2e2d13f306 Mon Sep 17 00:00:00 2001 From: George He Date: Tue, 26 Nov 2024 14:27:08 +0800 Subject: [PATCH 2/2] fix: integration test failed --- packages/insomnia-inso/src/cli.test.ts | 2 +- packages/insomnia-inso/src/cli.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/insomnia-inso/src/cli.test.ts b/packages/insomnia-inso/src/cli.test.ts index 4c7804b6b95..07d3acc31a8 100644 --- a/packages/insomnia-inso/src/cli.test.ts +++ b/packages/insomnia-inso/src/cli.test.ts @@ -155,7 +155,7 @@ describe('inso dev bundle', () => { expect(firstReqLogPosition).toBeGreaterThanOrEqual(0); expect(secondReqLogPosition).toBeGreaterThanOrEqual(0); - expect(firstReqLogPosition < secondReqLogPosition).toBeGreaterThanOrEqual(0); + expect(firstReqLogPosition < secondReqLogPosition).toBeTruthy; }); }); }); diff --git a/packages/insomnia-inso/src/cli.ts b/packages/insomnia-inso/src/cli.ts index ccc78898321..58e89c3038e 100644 --- a/packages/insomnia-inso/src/cli.ts +++ b/packages/insomnia-inso/src/cli.ts @@ -543,9 +543,11 @@ export const go = (args?: string[]) => { } // sort requests - const requestOrder = new Map(); - requestsToRun.forEach((req: BaseModel, order: number) => requestOrder.set(req._id, order)); - requestsToRun = requestsToRun.sort((a, b) => (requestOrder.get(a._id) || requestsToRun.length) - (requestOrder.get(b._id) || requestsToRun.length)); + if (options.item.length) { + const requestOrder = new Map(); + options.item.forEach((reqId: string, order: number) => requestOrder.set(reqId, order)); + requestsToRun = requestsToRun.sort((a, b) => (requestOrder.get(a._id) || requestsToRun.length) - (requestOrder.get(b._id) || requestsToRun.length)); + } try { const iterationCount = parseInt(options.iterationCount, 10);