From 77d1596bffbd27f15ea4bb93148dcfb0dd56cce5 Mon Sep 17 00:00:00 2001 From: George He Date: Thu, 9 May 2024 11:43:49 +0800 Subject: [PATCH] feat: add snippets for post-request scripting --- .../editors/request-script-editor.tsx | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/packages/insomnia/src/ui/components/editors/request-script-editor.tsx b/packages/insomnia/src/ui/components/editors/request-script-editor.tsx index ec515287a01..eecf021d952 100644 --- a/packages/insomnia/src/ui/components/editors/request-script-editor.tsx +++ b/packages/insomnia/src/ui/components/editors/request-script-editor.tsx @@ -58,6 +58,18 @@ const updateRequestAuth = );`; const requireAModule = "const atob = require('atob');"; +const getStatusCode = 'const statusCode = insomnia.response.code;'; +const getStatusMsg = 'const status = insomnia.response.status;'; +const getRespTime = 'const responseTime = insomnia.response.responseTime;'; +const getJsonBody = 'const jsonBody = insomnia.response.json();'; +const getTextBody = 'const textBody = insomnia.response.text();'; +const findHeader = + `const header = insomnia.response.headers.find( + header => header.key === 'Content-Type', + {}, +);`; +const getCookies = 'const cookies = insomnia.response.cookies.toObject();'; + const lintOptions = { globals: { // https://jshint.com/docs/options/ @@ -380,6 +392,70 @@ export const RequestScriptEditor: FC = ({ /> + + + + + } + > + + addSnippet(getStatusCode)} + /> + + + addSnippet(getStatusMsg)} + /> + + + addSnippet(getRespTime)} + /> + + + addSnippet(getJsonBody)} + /> + + + addSnippet(getTextBody)} + /> + + + addSnippet(findHeader)} + /> + + + addSnippet(getCookies)} + /> + + +