-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use aegir for testing js-libp2p (#104)
* Browser testing with aegir * Support onlyDial * Bump timeout for browser tests * Support webtransport browser test * PR comments * Tweak * Handle cases where the listener exits before dialer * Remove debug code * Bump node version * Prewarm with playwright install * Support extra timeouts when running against node or browser * Add timeout option to rust and js
- Loading branch information
Showing
19 changed files
with
40,126 additions
and
8,612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { spawn, exec } from "child_process"; | ||
import { existsSync } from "fs"; | ||
import { createClient } from 'redis' | ||
import http from "http" | ||
|
||
const isDialer = process.env.is_dialer === "true" | ||
const REDIS_ADDR = process.env.REDIS_ADDR || 'redis:6379' | ||
|
||
// Used to preinstall the browsers in the docker image | ||
const initialSetup = process.env.initial_setup === "true" | ||
|
||
/** @type {import('aegir/types').PartialOptions} */ | ||
export default { | ||
test: { | ||
async before() { | ||
if (initialSetup) { | ||
return {} | ||
} | ||
|
||
const redisClient = createClient({ | ||
url: `redis://${REDIS_ADDR}` | ||
}) | ||
redisClient.on('error', (err) => console.error(`Redis Client Error: ${err}`)) | ||
await redisClient.connect() | ||
|
||
const requestListener = async function (req, res) { | ||
const requestJSON = await new Promise(resolve => { | ||
let body = "" | ||
req.on('data', function (data) { | ||
body += data; | ||
}); | ||
|
||
req.on('end', function () { | ||
resolve(JSON.parse(body)) | ||
}); | ||
}) | ||
|
||
try { | ||
const redisRes = await redisClient.sendCommand(requestJSON) | ||
if (redisRes === null) { | ||
throw new Error("redis sent back null") | ||
} | ||
|
||
res.writeHead(200, { | ||
'Access-Control-Allow-Origin': '*' | ||
}) | ||
res.end(JSON.stringify(redisRes)) | ||
} catch (err) { | ||
console.error("Error in redis command:", err) | ||
res.writeHead(500, { | ||
'Access-Control-Allow-Origin': '*' | ||
}) | ||
res.end(err.toString()) | ||
return | ||
} | ||
|
||
|
||
}; | ||
|
||
const proxyServer = http.createServer(requestListener); | ||
await new Promise(resolve => { proxyServer.listen(0, "localhost", () => { resolve() }); }) | ||
|
||
return { | ||
redisClient, | ||
proxyServer: proxyServer, | ||
env: { | ||
...process.env, | ||
proxyPort: proxyServer.address().port | ||
} | ||
} | ||
}, | ||
async after(_, { proxyServer, redisClient }) { | ||
if (initialSetup) { | ||
return | ||
} | ||
|
||
await new Promise(resolve => { | ||
proxyServer.close(() => resolve()); | ||
}) | ||
|
||
try { | ||
// We don't care if this fails | ||
await redisClient.disconnect() | ||
} catch { } | ||
} | ||
}, | ||
build: { | ||
bundlesizeMax: '18kB' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
node-image.json | ||
chromium-image.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM mcr.microsoft.com/playwright | ||
|
||
WORKDIR /app | ||
|
||
|
||
COPY package*.json . | ||
|
||
RUN npm ci | ||
|
||
# Install browsers | ||
RUN ./node_modules/.bin/playwright install | ||
|
||
COPY tsconfig.json . | ||
COPY .aegir.js . | ||
COPY test ./test | ||
COPY src ./src | ||
|
||
RUN npm run build | ||
|
||
ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM node:17 | ||
FROM node:18 | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json . | ||
|
||
RUN npm ci | ||
|
||
COPY *.js /app/ | ||
COPY tsconfig.json . | ||
COPY .aegir.js . | ||
COPY test ./test | ||
COPY src ./src | ||
|
||
RUN npm run build | ||
|
||
ENTRYPOINT [ "npm", "run", "start" ] | ||
ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
image_name := js-v0.21 | ||
TEST_SOURCES := $(wildcard test/*.ts) | ||
|
||
image.json: Dockerfile index.js package.json package-lock.json | ||
IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh . | ||
docker image inspect ${image_name} -f "{{.Id}}" | \ | ||
all: chromium-image.json node-image.json | ||
|
||
chromium-image.json: ChromiumDockerfile $(TEST_SOURCES) package.json package-lock.json | ||
IMAGE_NAME=chromium-${image_name} ../../dockerBuildWrapper.sh -f ChromiumDockerfile . | ||
docker image inspect chromium-${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
node-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json | ||
IMAGE_NAME=node-${image_name} ../../dockerBuildWrapper.sh -f Dockerfile . | ||
docker image inspect node-${image_name} -f "{{.Id}}" | \ | ||
xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
rm image.json | ||
rm *image.json |
Oops, something went wrong.