fix: updated env entries having incorrect values

This commit is contained in:
Andrew Bastin
2022-02-19 13:14:50 +05:30
parent d246cf53d4
commit f4a126d31a
2 changed files with 12 additions and 5 deletions

View File

@@ -5,7 +5,11 @@ import { flow, pipe } from "fp-ts/function"
import * as O from "fp-ts/Option" import * as O from "fp-ts/Option"
import * as A from "fp-ts/Array" import * as A from "fp-ts/Array"
import { Environment } from "@hoppscotch/data" import { Environment } from "@hoppscotch/data"
import { runTestScript, TestDescriptor } from "@hoppscotch/js-sandbox" import {
SandboxTestResult,
runTestScript,
TestDescriptor,
} from "@hoppscotch/js-sandbox"
import { isRight } from "fp-ts/Either" import { isRight } from "fp-ts/Either"
import { import {
getCombinedEnvVariables, getCombinedEnvVariables,
@@ -25,7 +29,6 @@ import {
setGlobalEnvVariables, setGlobalEnvVariables,
updateEnvironment, updateEnvironment,
} from "~/newstore/environments" } from "~/newstore/environments"
import { TestResult } from "~/../hoppscotch-js-sandbox/lib/test-runner"
const getTestableBody = ( const getTestableBody = (
res: HoppRESTResponse & { type: "success" | "fail" } res: HoppRESTResponse & { type: "success" | "fail" }
@@ -151,7 +154,9 @@ const getUpdatedEnvVariables = (
A.filterMap( A.filterMap(
flow( flow(
O.fromPredicate( O.fromPredicate(
(x) => current.findIndex((y) => y.key === x.key) !== -1 (x) =>
current.findIndex((y) => x.key === y.key && x.value !== y.value) ===
-1
), ),
O.map((x) => ({ O.map((x) => ({
...x, ...x,
@@ -162,7 +167,7 @@ const getUpdatedEnvVariables = (
) )
function translateToSandboxTestResults( function translateToSandboxTestResults(
testDesc: TestResult & { tests: TestDescriptor } testDesc: SandboxTestResult
): HoppTestResult { ): HoppTestResult {
const translateChildTests = (child: TestDescriptor): HoppTestData => { const translateChildTests = (child: TestDescriptor): HoppTestData => {
return { return {

View File

@@ -9,6 +9,8 @@ import {
} from "./test-runner" } from "./test-runner"
export type TestDescriptor = _TestDescriptor export type TestDescriptor = _TestDescriptor
export type SandboxTestResult = TestResult & { tests: TestDescriptor }
/** /**
* Executes a given test script on the test-runner sandbox * Executes a given test script on the test-runner sandbox
* @param testScript The string of the script to run * @param testScript The string of the script to run
@@ -22,7 +24,7 @@ export const runTestScript = (
pipe( pipe(
execTestScript(testScript, envs, response), execTestScript(testScript, envs, response),
TE.chain((results) => TE.chain((results) =>
TE.right(<TestResult & { tests: TestDescriptor }>{ TE.right(<SandboxTestResult>{
envs: results.envs, envs: results.envs,
tests: results.tests[0], tests: results.tests[0],
}) })