diff --git a/Dockerfile b/Dockerfile index 10a12f71acf..c821c5d99ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN apk add --no-cache ruby \ # Install chromium ENV CHROME_BIN /usr/bin/chromium-browser +ENV CHROME_PATH /usr/lib/chromium/ ENV CHROME_EXTRA_FLAGS "--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage" RUN apk add --no-cache chromium ttf-freefont font-noto-emoji \ && apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing font-wqy-zenhei \ diff --git a/deno.jsonc b/deno.jsonc index 6c9225d73a0..de18bfa9aa6 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -89,7 +89,7 @@ "test": { "task": [ "rm .coverage -rf", - "deno test source/metrics" + "deno test source" ], "description": "๐Ÿงช Run tests and collect coverage", "seed": 0, @@ -179,7 +179,7 @@ "description": "๐Ÿ”Ž Lint and format code" }, "coverage": { - "task": "deno coverage .coverage", + "task": "deno coverage .coverage --exclude='/dom/'", "description": "๐Ÿ”ฌ Print coverage report (require `test` task to be run first)" }, // Continuous integration tasks ======================================================= @@ -194,7 +194,7 @@ "ci:test": { "task": [ "deno task btr docker:build", - "docker run metrics:dev sh -c 'deno task btr test && deno task btr coverage'" + "docker run --entrypoint='' metrics:dev sh -c 'deno task btr test && deno task btr coverage'" ], "description": "๐Ÿค– Build container and run tests and coverage inside the image (CI)", "lock": false diff --git a/source/engine/components/tests/context.ts b/source/engine/components/tests/context.ts index 454e0e717d5..e2cb9f826c0 100644 --- a/source/engine/components/tests/context.ts +++ b/source/engine/components/tests/context.ts @@ -6,6 +6,7 @@ import { Component } from "@engine/components/component.ts" import { Plugin } from "@engine/components/plugin.ts" import { Processor } from "@engine/components/processor.ts" import { sugar } from "@engine/config.ts" +import { env } from "@engine/utils/deno/env.ts" /** Default config for components testing */ export const config = { @@ -67,8 +68,16 @@ export async function getPermissions(test: Awaited permission.startsWith("net:")).map((permission) => permission.replace("net:", "")), } as test if (requested.has("run:chrome")) { - const bin = await Browser.getBinary("chrome", { cache: dir.cache }) - Object.assign(permissions, deepMerge(permissions, { read: [dir.cache], net: ["127.0.0.1", "localhost"], env: ["CHROME_EXTRA_FLAGS"], run: [bin] })) + Object.assign( + permissions, + deepMerge(permissions, { + read: [dir.cache], + net: ["127.0.0.1", "localhost"], + env: ["CHROME_BIN", "CHROME_PATH", "CHROME_EXTRA_FLAGS"], + run: [env.get("CHROME_BIN") || await Browser.getBinary("chrome", { cache: dir.cache })], + write: [`${env.get("HOME")}/.config/chromium/SingletonLock`], + }), + ) } if (requested.has("write")) { Object.assign(permissions, deepMerge(permissions, { write: [dir.test] })) diff --git a/source/engine/utils/browser.ts b/source/engine/utils/browser.ts index 4e2b8b747b0..a1050de8495 100644 --- a/source/engine/utils/browser.ts +++ b/source/engine/utils/browser.ts @@ -9,10 +9,10 @@ import { delay } from "std/async/delay.ts" /** Browser */ export class Browser { /** Constructor */ - constructor({ log, endpoint = null, bin = env.get("CHROME_BIN") || undefined }: { log: Logger; endpoint?: null | string; bin?: string }) { + constructor({ log, endpoint = null, bin }: { log: Logger; endpoint?: null | string; bin?: string }) { this.endpoint = endpoint this.log = log - this.bin = bin + this.bin = bin || env.get("CHROME_BIN") || undefined this.ready = this.open() } diff --git a/source/engine/utils/browser_test.ts b/source/engine/utils/browser_test.ts index 1abd2651490..85541c496f6 100644 --- a/source/engine/utils/browser_test.ts +++ b/source/engine/utils/browser_test.ts @@ -3,15 +3,17 @@ import { Browser } from "@engine/utils/browser.ts" import { dir, expect, MetricsError, t } from "@engine/utils/testing.ts" import { Logger } from "@engine/utils/log.ts" import { Format } from "@engine/utils/format.ts" +import { env } from "@engine/utils/deno/env.ts" const log = new Logger(import.meta) const cache = `${dir.cache}/browser.test` -const bin = await Browser.getBinary("chrome", { cache }) +const bin = env.get("CHROME_BIN") || await Browser.getBinary("chrome", { cache: dir.cache }) const permissions = { read: [cache], net: ["127.0.0.1", "localhost"], - env: ["CHROME_EXTRA_FLAGS"], + env: ["CHROME_BIN", "CHROME_PATH", "CHROME_EXTRA_FLAGS"], run: [bin], + write: [`${env.get("HOME")}/.config/chromium/SingletonLock`], } for (const mode of ["local", "remote"]) { diff --git a/source/run/cli/mod.ts b/source/run/cli/mod.ts index e4166813d48..626a481b3d9 100644 --- a/source/run/cli/mod.ts +++ b/source/run/cli/mod.ts @@ -6,7 +6,7 @@ import { latest, version } from "@engine/version.ts" import core from "y/@actions/core@1.10.1" import { process } from "@engine/process.ts" import { parse as parseFlags } from "std/flags/mod.ts" -import { cyan, gray } from "std/fmt/colors.ts" +import { brightRed, cyan, gray } from "std/fmt/colors.ts" import { env } from "@engine/utils/deno/env.ts" import { compat } from "./compat.ts" import { parse } from "@engine/utils/validation.ts" @@ -65,11 +65,11 @@ if (import.meta.main) { break } default: - console.log(`Unknown action: ${action}`) + console.log(brightRed(`Unknown action: ${action}`)) /* falls through */ case "help": { console.log([ - cyan(`Metrics ${version}`), + cyan(`Metrics ${version.number}`), "", "Usage is:", " help Show this help message",