From 725ac242daf0744cfbb6f304965f0109519be783 Mon Sep 17 00:00:00 2001 From: George He Date: Thu, 5 Dec 2024 14:18:01 +0800 Subject: [PATCH] fix(cli): failed to run script in cli if timeline dir is not inited --- packages/insomnia-smoke-test/fixtures/simple.yaml | 6 ++++++ packages/insomnia/src/common/send-request.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/packages/insomnia-smoke-test/fixtures/simple.yaml b/packages/insomnia-smoke-test/fixtures/simple.yaml index 068f71ae297..4f6fbb2367b 100644 --- a/packages/insomnia-smoke-test/fixtures/simple.yaml +++ b/packages/insomnia-smoke-test/fixtures/simple.yaml @@ -24,6 +24,8 @@ resources: settingRebuildPath: true settingFollowRedirects: global _type: request + preRequestScript: |- + console.log('executing pre-request script'); - _id: fld_01de564274824ecaad272330339ea6b2 parentId: wrk_0702a57d75d44255a8cecd2c5fa87809 modified: 1668533312225 @@ -101,6 +103,8 @@ resources: settingRebuildPath: true settingFollowRedirects: global _type: request + preRequestScript: |- + console.log('executing pre-request script'); - _id: req_579daeabc7534a52b242bdaaaf6ca4dc parentId: wrk_0702a57d75d44255a8cecd2c5fa87809 modified: 1666867670885 @@ -122,6 +126,8 @@ resources: settingRebuildPath: true settingFollowRedirects: global _type: request + preRequestScript: |- + console.log('executing pre-request script'); - _id: env_42a94488fcd6106a75fb3ededd6bb4fbd267aa95 parentId: wrk_0702a57d75d44255a8cecd2c5fa87809 modified: 1666867924188 diff --git a/packages/insomnia/src/common/send-request.ts b/packages/insomnia/src/common/send-request.ts index 9f2e7329d3f..d6ae1755f54 100644 --- a/packages/insomnia/src/common/send-request.ts +++ b/packages/insomnia/src/common/send-request.ts @@ -1,3 +1,4 @@ +import fs from 'fs/promises'; import path from 'path'; import { type BaseModel, types as modelTypes } from '../models'; @@ -122,6 +123,7 @@ export async function getSendRequestCallbackMemDb(environmentId: string, memDB: return async function sendRequest(requestId: string, iteration?: number) { const requestData = await fetchInsoRequestData(requestId, environmentId); const getCurrentRowOfIterationData = wrapAroundIterationOverIterationData(iterationData, iteration); + await fs.mkdir(path.dirname(requestData.timelinePath), { recursive: true }); const mutatedContext = await tryToExecutePreRequestScript(requestData, transientVariables, getCurrentRowOfIterationData, iteration, iterationCount); if (mutatedContext === null) {