Skip to content

Commit

Permalink
fix issue with chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Oct 31, 2023
1 parent b550e07 commit 0ac4242
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"test": {
"task": [
"rm .coverage -rf",
"deno test source/metrics"
"deno test source"
],
"description": "🧪 Run tests and collect coverage",
"seed": 0,
Expand Down Expand Up @@ -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 =======================================================
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions source/engine/components/tests/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -67,8 +68,16 @@ export async function getPermissions(test: Awaited<ReturnType<typeof Component["
net: [...requested].filter((permission) => 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] }))
Expand Down
4 changes: 2 additions & 2 deletions source/engine/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
6 changes: 4 additions & 2 deletions source/engine/utils/browser_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) {
Expand Down
6 changes: 3 additions & 3 deletions source/run/cli/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0ac4242

Please sign in to comment.