index.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { pipe } from "fp-ts/function"
  2. import * as TE from "fp-ts/TaskEither"
  3. import { execPreRequestScript } from "./preRequest"
  4. import {
  5. execTestScript,
  6. TestResponse as _TestResponse,
  7. TestDescriptor as _TestDescriptor,
  8. TestResult,
  9. } from "./test-runner"
  10. export * from "./test-runner"
  11. export type TestResponse = _TestResponse
  12. export type TestDescriptor = _TestDescriptor
  13. export type SandboxTestResult = TestResult & { tests: TestDescriptor }
  14. /**
  15. * Executes a given test script on the test-runner sandbox
  16. * @param testScript The string of the script to run
  17. * @returns A TaskEither with an error message or a TestDescriptor with the final status
  18. */
  19. export const runTestScript = (
  20. testScript: string,
  21. envs: TestResult["envs"],
  22. response: TestResponse
  23. ) =>
  24. pipe(
  25. execTestScript(testScript, envs, response),
  26. TE.chain((results) =>
  27. TE.right(<SandboxTestResult>{
  28. envs: results.envs,
  29. tests: results.tests[0],
  30. })
  31. ) // execTestScript returns an array of descriptors with a single element (extract that)
  32. )
  33. /**
  34. * Executes a given pre-request script on the sandbox
  35. * @param preRequestScript The script to run
  36. * @param env The environment variables active
  37. * @returns A TaskEither with an error message or an array of the final environments with the all the script values applied
  38. */
  39. export const runPreRequestScript = execPreRequestScript