feat: added support for passing env.json file to test cmd (#2373)

This commit is contained in:
Deepanshu Dhruw
2022-06-15 23:53:24 +05:30
committed by GitHub
parent 2d0bd48e00
commit 0244b941b3
20 changed files with 309 additions and 96 deletions

View File

@@ -6,7 +6,7 @@ import * as J from "fp-ts/Json";
import { pipe } from "fp-ts/function";
import { FormDataEntry } from "../types/request";
import { error, HoppCLIError } from "../types/errors";
import { isRESTCollection, isHoppErrnoException } from "./checks";
import { isRESTCollection, isHoppErrnoException, checkFile } from "./checks";
import { HoppCollection, HoppRESTRequest } from "@hoppscotch/data";
/**
@@ -49,10 +49,17 @@ export const parseCollectionData = (
path: string
): TE.TaskEither<HoppCLIError, HoppCollection<HoppRESTRequest>[]> =>
pipe(
TE.of(path),
// Checking if given file path exists or not.
TE.chain(checkFile),
// Trying to read give collection json path.
TE.tryCatch(
() => pipe(path, fs.readFile),
(reason) => error({ code: "UNKNOWN_ERROR", data: E.toError(reason) })
TE.chainW((checkedPath) =>
TE.tryCatch(
() => fs.readFile(checkedPath),
(reason) => error({ code: "UNKNOWN_ERROR", data: E.toError(reason) })
)
),
// Checking if parsed file data is array.