Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/BuildJobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ jobs:
- name: Install dependencies
run: pnpm install
- name: "Executing E2E tests"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
node
./automation/run-e2e/bin/run-e2e-in-chunks.mjs
Expand Down
8 changes: 4 additions & 4 deletions automation/run-e2e/lib/ci.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import c from "ansi-colors";
import findFreePort from "find-free-port";
import nodeIp from "ip";
import fetch from "node-fetch";
import { execSync } from "node:child_process";
import sh from "shelljs";
import parseArgs from "yargs-parser";
import { createDeploymentBundle, prepareImage, startCypress, startRuntime } from "./docker-utils.mjs";
import { setupTestProject } from "./setup-test-project.mjs";
import { updateWidget } from "./utils.mjs";
import { fetchWithReport, updateWidget } from "./utils.mjs";

const MX_VERSION_MAP_URL = "https://raw.githubusercontent.com/mendix/web-widgets/main/automation/run-e2e/mendix-versions.json";
const MX_VERSION_MAP_URL =
"https://raw.githubusercontent.com/mendix/web-widgets/main/automation/run-e2e/mendix-versions.json";

const { ls, cat } = sh;

Expand Down Expand Up @@ -89,7 +89,7 @@ async function getMendixVersion(options) {
return process.env.MENDIX_VERSION;
}

const versionMapResponse = await fetch(MX_VERSION_MAP_URL);
const versionMapResponse = await fetchWithReport(MX_VERSION_MAP_URL);
if (versionMapResponse.ok) {
const { mxVersion } = options;
const versionMap = await versionMapResponse.json();
Expand Down
11 changes: 6 additions & 5 deletions automation/run-e2e/lib/setup-test-project.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { mkdtemp } from "node:fs/promises";
import { pipeline } from "node:stream";
import { promisify } from "node:util";
import { join } from "node:path";
import fetch from "node-fetch";
import sh from "shelljs";
import crossZip from "cross-zip";
import { packageMeta } from "./utils.mjs";
import { packageMeta, fetchGithubRestAPI, fetchWithReport } from "./utils.mjs";

const { cp, ls, mkdir, rm, mv } = sh;
const streamPipe = promisify(pipeline);
Expand Down Expand Up @@ -58,7 +57,7 @@ async function downloadTestProject(repository, branch) {
try {
await streamPipe(
(
await fetch(`${repository}/archive/refs/heads/${branch}.zip`)
await fetchWithReport(`${repository}/archive/refs/heads/${branch}.zip`)
).body,
createWriteStream(downloadedArchivePath)
);
Expand All @@ -81,14 +80,16 @@ async function updateAtlas() {
"tests/testProject/themesource/datawidgets"
);

const releasesResponse = await fetch("https://api.github.com/repos/mendix/StarterApp_Blank/releases/latest");
const releasesResponse = await fetchGithubRestAPI(
"https://api.github.com/repos/mendix/StarterApp_Blank/releases/latest"
);
if (releasesResponse.ok) {
const release = await releasesResponse.json();
const [{ browser_download_url }] = release.assets;
const downloadedPath = join(await usetmp(), `StarterAppRelease.zip`);
const outPath = await usetmp();
try {
await streamPipe((await fetch(browser_download_url)).body, createWriteStream(downloadedPath));
await streamPipe((await fetchWithReport(browser_download_url)).body, createWriteStream(downloadedPath));
crossZip.unzipSync(downloadedPath, outPath);
cp("-r", join(outPath, "theme"), "tests/testProject");
cp("-r", join(outPath, "themesource"), "tests/testProject");
Expand Down
38 changes: 29 additions & 9 deletions automation/run-e2e/lib/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,38 @@ export async function updateWidget() {
cp("-f", mpkPath, outDir);
}

export async function await200(url = "http://localhost:8080", attempts = 50) {
export async function fetchWithReport(url, init) {
const response = await fetch(url, init);
if (response.ok) {
return response;
}
console.error(`HTTP Error Response: ${response.status} ${response.statusText}`);
const errorBody = await response.text();
console.error(`Error body: ${errorBody}`);
throw new Error("HTTP Error");
}

export async function fetchGithubRestAPI(url, init = {}) {
const token = process.env.GITHUB_TOKEN;
assert.ok(typeof token === "string" && token.length > 0, "GITHUB_TOKEN is missing");

return fetchWithReport(url, {
...init,
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28",
...init.headers
}
});
}

export async function await200(url = "http://127.0.0.1:8080", attempts = 50) {
let n = 0;
while (++n <= attempts) {
console.log(c.cyan(`GET ${url} ${n}`));
let response;
try {
response = await fetch(url);
} catch {
// ignore
}

const { ok, status } = response ?? {};
const response = await fetch(url);
const { ok, status } = response;

if (ok && status === 200) {
console.log(c.green(`200 OK, continue`));
Expand Down