feat: add button to export test results as json (#4419)

Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
Pranay Pandey
2024-10-28 21:23:21 +05:30
committed by GitHub
parent 20c4767dce
commit 936c97b53a
3 changed files with 51 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
import { HoppTestResult } from "~/helpers/types/HoppTestResult"
import { platform } from "~/platform"
import * as E from "fp-ts/Either"
export const exportTestResults = async (testResults: HoppTestResult) => {
const contentsJSON = JSON.stringify(testResults, null, 2)
const file = new Blob([contentsJSON], { type: "application/json" })
const url = URL.createObjectURL(file)
const fileName = url.split("/").pop()!.split("#")[0].split("?")[0]
const result = await platform.io.saveFileWithDialog({
data: contentsJSON,
contentType: "application/json",
suggestedFilename: `${fileName}.json`,
filters: [
{
name: "Hoppscotch Test Results JSON file",
extensions: ["json"],
},
],
})
if (result.type === "unknown" || result.type === "saved") {
return E.right("state.download_started")
}
return E.left("state.download_failed")
}