diff --git a/integration-tests/test-api/Dockerfile b/integration-tests/test-api/Dockerfile index 23393196..ddd1f15b 100644 --- a/integration-tests/test-api/Dockerfile +++ b/integration-tests/test-api/Dockerfile @@ -1,20 +1,17 @@ # syntax=docker/dockerfile:1 -ARG BUILDPLATFORM=arm64 -FROM --platform=$BUILDPLATFORM node:20-alpine -WORKDIR /app +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM oven/bun:1-alpine +WORKDIR /usr/src/app -ENV NODE_ENV=production +RUN apk update && apk upgrade +RUN apk add --no-cache sqlite COPY . . +RUN bun install --frozen-lockfile -RUN npm install -g pnpm -RUN pnpm install - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 hono - -USER hono +# run the app +USER bun EXPOSE 8000 ENV PORT 8000 - -CMD ["pnpm", "run", "start"] +CMD [ "bun", "run", "src/index.ts" ] diff --git a/integration-tests/test-api/bun.lockb b/integration-tests/test-api/bun.lockb new file mode 100755 index 00000000..7897daca Binary files /dev/null and b/integration-tests/test-api/bun.lockb differ diff --git a/integration-tests/test-api/package.json b/integration-tests/test-api/package.json index eb7018cd..61ce1fcb 100644 --- a/integration-tests/test-api/package.json +++ b/integration-tests/test-api/package.json @@ -10,5 +10,8 @@ }, "volta": { "extends": "../../package.json" + }, + "devDependencies": { + "@types/bun": "^1.0.2" } } diff --git a/integration-tests/test-api/src/index.ts b/integration-tests/test-api/src/index.ts index 2305cf68..301e856a 100644 --- a/integration-tests/test-api/src/index.ts +++ b/integration-tests/test-api/src/index.ts @@ -1,23 +1,38 @@ -import { serve } from "@hono/node-server"; import { Hono } from "hono"; +import { Database } from "bun:sqlite"; +console.log("connecting to sqlite"); +const sqlite = new Database(":memory:", { readwrite: true }); +console.log("connected to sqlite"); + +console.log('creating "stats" table'); +const query = sqlite.query( + "CREATE TABLE `stats` (`id` text, `json_stats` text );", +); +query.run(); +console.log('created "stats" table'); + +console.log("starting api"); const app = new Hono(); +app.all("/ping", (c) => { + return c.text("pong", 200); +}); + app.all( - "/test-url/:status/:badPUT{true|false}/upload/bundle_analysis/v1", + "/test-url/:id/:status/:badPUT{true|false}/upload/bundle_analysis/v1", (c) => { + const id = c.req.param("id"); const status = parseInt(c.req.param("status")); const badPUT = c.req.param("badPUT") === "true"; const url = new URL(c.req.url); - let putURL = `${url.protocol}//${url.host}/file-upload`; + const putURL = `${url.protocol}//${url.host}/file-upload/${id}/${status}`; if (status >= 400 && !badPUT) { return c.text(`Error code: ${status}`, { status }); } - if (badPUT) { - putURL = `${putURL}/${status}`; - } + console.log("PUT URL", putURL); return c.json( { @@ -28,24 +43,42 @@ app.all( }, ); -app.all("/file-upload/:status{[0-9]{3}}", async (c) => { +app.all("/file-upload/:id/:status{[0-9]{3}}", async (c) => { + const id = c.req.param("id"); const status = parseInt(c.req.param("status")); if (status >= 400) { return c.text(`Error code: ${status}`, { status }); } - await c.req.json(); + console.log("uploading file"); + const data: unknown = await c.req.json(); + console.log("finished upload"); + + console.log("inserting stats"); + const insertStats = JSON.stringify(data); + const query = sqlite.query( + `INSERT INTO stats (id, json_stats) VALUES ('${id}', '${insertStats}')`, + ); + query.run(); + query.finalize(); + console.log("inserted stats"); return c.text("File uploaded successfully", { status: 200 }); }); -serve( - { - fetch: app.fetch, - port: 8000, - }, - (info) => { - console.info(`🚀 Server listening on ${info.address}:${info.port}`); - }, -); +app.all("/get-stats/:id", (c) => { + const id = c.req.param("id"); + + const query = sqlite.query("SELECT * FROM stats WHERE id = $id"); + const result = query.get({ $id: id }) as { id: string; json_stats: string }; + query.finalize(); + + if (result) { + return c.json({ stats: result.json_stats }, { status: 200 }); + } + + return c.text("Not found", { status: 404 }); +}); + +export default app; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 90547075..f418fbe0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,18 +245,6 @@ importers: specifier: npm:webpack@5.89.0 version: /webpack@5.89.0(@swc/core@1.3.99) - integration-tests/test-api: - dependencies: - '@hono/node-server': - specifier: ^1.3.1 - version: 1.3.1 - hono: - specifier: ^3.11.2 - version: 3.11.3 - tsx: - specifier: ^3.12.2 - version: 3.14.0 - packages/bundler-plugin-core: dependencies: chalk: @@ -1022,6 +1010,7 @@ packages: cpu: [arm64] os: [android] requiresBuild: true + dev: true optional: true /@esbuild/android-arm64@0.19.4: @@ -1039,6 +1028,7 @@ packages: cpu: [arm] os: [android] requiresBuild: true + dev: true optional: true /@esbuild/android-arm@0.19.4: @@ -1056,6 +1046,7 @@ packages: cpu: [x64] os: [android] requiresBuild: true + dev: true optional: true /@esbuild/android-x64@0.19.4: @@ -1073,6 +1064,7 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true + dev: true optional: true /@esbuild/darwin-arm64@0.19.4: @@ -1090,6 +1082,7 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true + dev: true optional: true /@esbuild/darwin-x64@0.19.4: @@ -1107,6 +1100,7 @@ packages: cpu: [arm64] os: [freebsd] requiresBuild: true + dev: true optional: true /@esbuild/freebsd-arm64@0.19.4: @@ -1124,6 +1118,7 @@ packages: cpu: [x64] os: [freebsd] requiresBuild: true + dev: true optional: true /@esbuild/freebsd-x64@0.19.4: @@ -1141,6 +1136,7 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-arm64@0.19.4: @@ -1158,6 +1154,7 @@ packages: cpu: [arm] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-arm@0.19.4: @@ -1175,6 +1172,7 @@ packages: cpu: [ia32] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-ia32@0.19.4: @@ -1192,6 +1190,7 @@ packages: cpu: [loong64] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-loong64@0.19.4: @@ -1209,6 +1208,7 @@ packages: cpu: [mips64el] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-mips64el@0.19.4: @@ -1226,6 +1226,7 @@ packages: cpu: [ppc64] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-ppc64@0.19.4: @@ -1243,6 +1244,7 @@ packages: cpu: [riscv64] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-riscv64@0.19.4: @@ -1260,6 +1262,7 @@ packages: cpu: [s390x] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-s390x@0.19.4: @@ -1277,6 +1280,7 @@ packages: cpu: [x64] os: [linux] requiresBuild: true + dev: true optional: true /@esbuild/linux-x64@0.19.4: @@ -1294,6 +1298,7 @@ packages: cpu: [x64] os: [netbsd] requiresBuild: true + dev: true optional: true /@esbuild/netbsd-x64@0.19.4: @@ -1311,6 +1316,7 @@ packages: cpu: [x64] os: [openbsd] requiresBuild: true + dev: true optional: true /@esbuild/openbsd-x64@0.19.4: @@ -1328,6 +1334,7 @@ packages: cpu: [x64] os: [sunos] requiresBuild: true + dev: true optional: true /@esbuild/sunos-x64@0.19.4: @@ -1345,6 +1352,7 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true + dev: true optional: true /@esbuild/win32-arm64@0.19.4: @@ -1362,6 +1370,7 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true + dev: true optional: true /@esbuild/win32-ia32@0.19.4: @@ -1379,6 +1388,7 @@ packages: cpu: [x64] os: [win32] requiresBuild: true + dev: true optional: true /@esbuild/win32-x64@0.19.4: @@ -1427,11 +1437,6 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@hono/node-server@1.3.1: - resolution: {integrity: sha512-eQBCDbH1Vv/TiYXNP8aGfJTuXi9xGhEd/EZg9u6dhr7zC5/WKKztcBmbrOTtixVBvvV6bfcay6KEginwiqHyXg==} - engines: {node: '>=18.14.1'} - dev: false - /@humanwhocodes/config-array@0.11.13: resolution: {integrity: sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==} engines: {node: '>=10.10.0'} @@ -4069,6 +4074,7 @@ packages: '@esbuild/win32-arm64': 0.18.20 '@esbuild/win32-ia32': 0.18.20 '@esbuild/win32-x64': 0.18.20 + dev: true /esbuild@0.19.4: resolution: {integrity: sha512-x7jL0tbRRpv4QUyuDMjONtWFciygUxWaUM1kMX2zWxI0X2YWOt7MSA0g4UdeSiHM8fcYVzpQhKYOycZwxTdZkA==} @@ -4824,6 +4830,7 @@ packages: resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} dependencies: resolve-pkg-maps: 1.0.0 + dev: true /glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} @@ -5006,11 +5013,6 @@ packages: resolution: {integrity: sha512-EWGTfnTqAO2L/j5HZgoM/3z82L7necsJ0pO9Tp0X1wil3PDLrkypTBRgVO2ExehEEvUycejZD3FuRaXpZZc3kw==} dev: true - /hono@3.11.3: - resolution: {integrity: sha512-MWYBcIS4dZJo9e/852Zwl+gqBiUSRknMOZ/MbW7kW8JiWixTJ58pzXVIeBq7jnvFq3AZ9uQ35QyVpzV05sdNFw==} - engines: {node: '>=16.0.0'} - dev: false - /hookable@5.5.3: resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==} dev: true @@ -7378,6 +7380,7 @@ packages: /resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: true /resolve.exports@2.0.2: resolution: {integrity: sha512-X2UW6Nw3n/aMgDVy+0rSqgHlv39WZAlZrXCdnbyEiKm17DSqHX4MmQMaST3FbeWR5FTuRcUwYAziZajji0Y7mg==} @@ -7753,6 +7756,7 @@ packages: dependencies: buffer-from: 1.1.2 source-map: 0.6.1 + dev: true /source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} @@ -8328,17 +8332,6 @@ packages: /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} - /tsx@3.14.0: - resolution: {integrity: sha512-xHtFaKtHxM9LOklMmJdI3BEnQq/D5F73Of2E1GDrITi9sgoVkvIsrQUTY1G8FlmGtA+awCI4EBlTRRYxkL2sRg==} - hasBin: true - dependencies: - esbuild: 0.18.20 - get-tsconfig: 4.7.2 - source-map-support: 0.5.21 - optionalDependencies: - fsevents: 2.3.3 - dev: false - /tty-table@4.2.3: resolution: {integrity: sha512-Fs15mu0vGzCrj8fmJNP7Ynxt5J7praPXqFN0leZeZBXJwkMxv9cb2D454k1ltrtUSJbZ4yH4e0CynsHLxmUfFA==} engines: {node: '>=8.0.0'} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 8bbaa5d7..5e98e763 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,4 +2,3 @@ packages: - "examples/*" - "packages/*" - "integration-tests" - - "integration-tests/test-api"