Skip to content

Commit

Permalink
continue compat layer
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Nov 9, 2023
1 parent 00f404a commit eda4257
Show file tree
Hide file tree
Showing 14 changed files with 703 additions and 111 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ RUN apk add --no-cache chromium ttf-freefont font-noto-emoji \
# Install deno
ENV DENO_INSTALL /
ENV DENO_NO_UPDATE_CHECK true
ENV DENO_VERSION 1.38.0
ENV GLIBC_VERSION 2.34-r0
RUN apk add --no-cache --virtual .deno curl wget \
RUN apk add --no-cache --virtual .deno curl wget unzip \
&& wget --no-hsts --quiet --output-document /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget --no-hsts --quiet https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \
&& wget --no-hsts --quiet https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk \
Expand All @@ -35,6 +36,7 @@ RUN apk add --no-cache --virtual .deno curl wget \
&& apk del glibc-i18n \
&& (curl -fsSL https://deno.land/x/install/install.sh | sh) \
&& apk del .deno \
&& deno upgrade --version ${DENO_VERSION} \
&& deno --version

# Install lighthouse
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ runs:
cd ${{ github.action_path }}
DOCKER_IMAGE="${{ inputs.docker_image }}"
if [ -f "$DOCKER_IMAGE" ]; then
DOCKER_LOCAL=metrics:local
echo "Using local docker image: $DOCKER_IMAGE"
deno task btr docker:build
DOCKER_IMAGE=metrics:dev
# TODO(@lowlighter): pass the docker file as input
deno task make docker --tag $DOCKER_LOCAL --file $DOCKER_IMAGE
DOCKER_IMAGE=$DOCKER_LOCAL
else
echo "Pulling remote docker image: $DOCKER_IMAGE"
docker pull $DOCKER_IMAGE
Expand Down
16 changes: 10 additions & 6 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@
// processors/render.twemojis
"cdn.jsdelivr.net/gh/jdecked/twemoji@latest/assets",
// Testing
"example.com"
"example.com",
// Browser downloads
"googlechromelabs.github.io/chrome-for-testing",
"edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing"
],
"run": [
"deno",
Expand All @@ -132,6 +135,7 @@
],
"write": [
".test",
".cache",
"$HOME/.config/chromium/SingletonLock"
],
"env": [
Expand Down Expand Up @@ -200,7 +204,7 @@
"task": [
"deno task make docker &&",
"docker run --entrypoint='' metrics:dev sh -c 'deno task make test && deno task make coverage'"
],
]
},
"deploy:deno": {
"description": "🦕 Deploy metrics on https://deno.com/deploy",
Expand Down Expand Up @@ -242,7 +246,7 @@
"deno eval \"console.log($ASTRAL_INSTALL)\""
],
"env": {
"ASTRAL_INSTALL": "await import('@engine/utils/browser.ts').then(({Browser}) => Browser.getBinary('chrome'))"
"ASTRAL_INSTALL": "(Deno.stdout = Deno.stderr, await import('@engine/utils/browser.ts').then(({Browser}) => Browser.getBinary('chrome')))"
},
"deno": {
"eval": {
Expand All @@ -253,14 +257,14 @@
],
"write": [
".cache"
],
"env": [
"CHROME_BIN"
]
}
}
}
},
"xx": {
"task": "export TEST=$(deno task make get:cache) && echo $TEST"
},
"get:cache": {
"description": "🏗️ Get cache path",
"task": [
Expand Down
3 changes: 3 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source/engine/components/tests/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function getPermissions(test: Awaited<ReturnType<typeof Component["
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")],
run: [env.get("CHROME_BIN")],
write: [`${env.get("HOME")}/.config/chromium/SingletonLock`],
}),
)
Expand Down
6 changes: 3 additions & 3 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 }: { log: Logger; endpoint?: null | string; bin?: string }) {
constructor({ log, endpoint = null, bin = env.get("CHROME_BIN") }: { log: Logger; endpoint?: null | string; bin?: string }) {
this.endpoint = endpoint
this.log = log
this.bin = bin || env.get("CHROME_BIN") || undefined
this.bin = bin
this.ready = this.open()
}

Expand All @@ -39,7 +39,7 @@ export class Browser {
} else {
this.#instance = await launch({ args: Browser.flags, path: this.bin, cache: dir.cache })
Object.assign(this, { endpoint: this.#instance.wsEndpoint() })
this.log.io(`using local browser: ${this.endpoint}${this.bin ? ` (from ${this.bin})` : ""}}`)
this.log.io(`using local browser: ${this.endpoint} (from ${this.bin})`)
}
return this
}
Expand Down
13 changes: 13 additions & 0 deletions source/engine/utils/browser_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ const permissions = {
write: [`${env.get("HOME")}/.config/chromium/SingletonLock`],
}

Deno.test(t(import.meta, "`static .getBinary()` returns a path"), {
permissions: {
net: [
"googlechromelabs.github.io/chrome-for-testing",
"edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing",
],
read: [dir.cache],
write: [dir.cache],
},
}, async () => {
await expect(Browser.getBinary("chrome")).to.eventually.be.a("string")
})

for (const mode of ["local", "remote"]) {
const setup = async () => {
const remote = (mode === "remote") ? await new Browser({ log, bin }).ready : null
Expand Down
8 changes: 5 additions & 3 deletions source/engine/utils/deno/command_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { DevNull } from "@engine/utils/log_test.ts"
const stdio = new DevNull()
const log = new Logger(import.meta, { level: Logger.channels.trace, tags: { foo: "bar" }, stdio })

Deno.test.ignore(t(import.meta, "`command()` can execute commands"), { permissions: { run: ["deno"] } }, async () => {
// TODO(@lowlighter): Use `{ permissions: { run: ["deno"] } }` when https://github.com/denoland/deno/issues/21123 fixed

Deno.test(t(import.meta, "`command()` can execute commands"), async () => {
await expect(command("deno --version")).to.be.eventually.containSubset({ success: true, code: 0 })
})

Deno.test.ignore(t(import.meta, "`command()` returns stdio content instead if asked"), { permissions: { run: ["deno"] } }, async () => {
Deno.test(t(import.meta, "`command()` returns stdio content instead if asked"), async () => {
await expect(command("deno --version", { return: "stdout" })).to.eventually.include("deno")
})

Deno.test.ignore(t(import.meta, "`command()` returns stdio content instead if asked"), { permissions: { run: ["deno"] } }, async () => {
Deno.test(t(import.meta, "`command()` returns stdio content instead if asked"), async () => {
stdio.flush()
await expect(command("deno --version", { log })).to.be.fulfilled
expect(stdio.messages).to.not.be.empty
Expand Down
8 changes: 2 additions & 6 deletions source/engine/utils/deno/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@ export async function write(path: string, data: string | Uint8Array | ReadableSt
export async function list(glob: string) {
const files = []
const base = glob.match(/(?<base>.*\/)\*/)?.groups?.base
const prefix = base ? new RegExp(`.*?${base}`) : null
const prefix = new RegExp(`.*?${base}`)
for await (const { path } of expandGlob(glob, { extended: true, globstar: true })) {
let file = path.replaceAll("\\", "/")
if (prefix) {
file = file.replace(prefix, "")
}
files.push(file)
files.push(path.replaceAll("\\", "/").replace(prefix, ""))
}
return files
}
2 changes: 1 addition & 1 deletion source/engine/utils/deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { throws } from "@engine/utils/errors.ts"

/** Port listener */
export function listen(options: Deno.ServeOptions, handler: Deno.ServeHandler) {
return Deno.serve(options, handler)
return Deno.serve({ ...options, onListen: () => void null }, handler)
}

/** KV storage */
Expand Down
4 changes: 4 additions & 0 deletions source/engine/utils/testing_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { expect, is, MetricsValidationError, mock, t } from "@engine/utils/testing.ts"

Deno.test(t(import.meta, "`t()` warns when no tests are present"), { permissions: "none" }, () => {
expect(t(import.meta, null)).to.match(/NO TESTS FOUND/i)
})

Deno.test(t(import.meta, "`mock()` validates inputs and returns mocked data"), { permissions: "none" }, () => {
const mocked = mock({ foo: is.string() }, ({ foo }) => foo)
expect(mocked({ foo: "bar" })).to.equal("bar")
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/rss/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Imports
import { is, parse, Plugin } from "@engine/components/plugin.ts"
import RSS from "y/rss-parser@3.13.0"
import RSS from "y/rss-parser@3.13.0?pin=v133"

/** Plugin */
export default class extends Plugin {
Expand Down
Loading

0 comments on commit eda4257

Please sign in to comment.