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

fix(cli): should run requests according to the specified order #8200

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/insomnia-inso/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).toBeTruthy;
});
});
});

Expand Down
7 changes: 7 additions & 0 deletions packages/insomnia-inso/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,13 @@ export const go = (args?: string[]) => {
return process.exit(1);
}

// sort requests
if (options.item.length) {
const requestOrder = new Map<string, number>();
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);

Expand Down
Loading