feat: add button to export test results as json (#4419)
Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user