From 0bfcae2659f2034088465fd73775e251d1c910b6 Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:48:54 +0200 Subject: [PATCH] [E2E] Use NodeJS `http` module for Cypress backend (#25952) --- .../test/__runner__/cypress-runner-backend.js | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/frontend/test/__runner__/cypress-runner-backend.js b/frontend/test/__runner__/cypress-runner-backend.js index 454e06c0a7e..9b8d9ced8dc 100644 --- a/frontend/test/__runner__/cypress-runner-backend.js +++ b/frontend/test/__runner__/cypress-runner-backend.js @@ -5,7 +5,7 @@ const { spawn } = require("child_process"); const os = require("os"); const path = require("path"); -const fetch = require("isomorphic-fetch"); +const http = require("http"); const CypressBackend = { createServer(port = 4000) { @@ -107,9 +107,30 @@ const CypressBackend = { } async function isReady(host) { + // This is needed until we can use NodeJS native `fetch`. + function request(url) { + return new Promise((resolve, reject) => { + const req = http.get(url, res => { + let body = ""; + + res.on("data", chunk => { + body += chunk; + }); + + res.on("end", () => { + resolve(JSON.parse(body)); + }); + }); + + req.on("error", e => { + reject(e); + }); + }); + } + try { - const { status } = await fetch(`${host}/api/health`); - if (status === 200) { + const { status } = await request(`${host}/api/health`); + if (status === "ok") { return true; } } catch (e) {} -- GitLab