From 8d8e59914b59410c39d82483968d1e3d806e7a08 Mon Sep 17 00:00:00 2001 From: Mattt Date: Fri, 5 Jul 2024 05:57:56 -0700 Subject: [PATCH] Run integration tests with `replicate/canary` model (#283) * Run integration tests with replicate/canary model * Update expected output * Add test matrix for Next.js * Reorder test matrix configurations * Add test matrix for build step --- .github/workflows/ci.yml | 29 +++++++++++++++++++--------- integration/bun/index.test.ts | 2 +- integration/commonjs/index.js | 5 +++-- integration/commonjs/index.test.js | 2 +- integration/deno/index.test.ts | 2 +- integration/deno/index.ts | 7 ++++--- integration/esm/index.js | 5 +++-- integration/esm/index.test.js | 2 +- integration/typescript/index.test.ts | 2 +- integration/typescript/index.ts | 7 ++++--- 10 files changed, 39 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87b1f75..27a982c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ jobs: strategy: matrix: + suite: [node] # See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases node-version: [18.x, 20.x, 22.x] @@ -32,15 +33,20 @@ jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + # See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases + node-version: [20.x] + outputs: tarball-name: ${{ steps.pack.outputs.tarball-name }} steps: - uses: actions/checkout@v4 - - name: Use Node.js + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: ${{ matrix.node-version }} cache: "npm" - name: Build tarball id: pack @@ -61,9 +67,9 @@ jobs: strategy: matrix: + suite: [commonjs, esm, typescript] # See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases node-version: [18.x, 20.x] - suite: [commonjs, esm, typescript] fail-fast: false steps: @@ -90,9 +96,9 @@ jobs: strategy: matrix: - node-version: [20.x] - browser: ["chromium", "firefox", "webkit"] suite: ["browser"] + browser: ["chromium", "firefox", "webkit"] + node-version: [20.x] fail-fast: false steps: @@ -122,8 +128,8 @@ jobs: strategy: matrix: - node-version: [20.x] suite: [cloudflare-worker] + node-version: [20.x] steps: - uses: actions/checkout@v4 @@ -150,8 +156,8 @@ jobs: strategy: matrix: - bun-version: [1.0.11] suite: [bun] + bun-version: [1.0.11] steps: - uses: actions/checkout@v4 @@ -180,8 +186,8 @@ jobs: strategy: matrix: - deno-version: [v1.x] suite: [deno] + deno-version: [v1.x] steps: - uses: actions/checkout@v4 @@ -202,6 +208,11 @@ jobs: needs: [test, build] runs-on: ubuntu-latest + strategy: + matrix: + suite: [nextjs] + node-version: [20.x] + env: REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }} @@ -213,7 +224,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: ${{ matrix.node-version }} cache: "npm" - run: | npm --prefix integration/next install diff --git a/integration/bun/index.test.ts b/integration/bun/index.test.ts index 1357e5b..f0665a6 100644 --- a/integration/bun/index.test.ts +++ b/integration/bun/index.test.ts @@ -19,5 +19,5 @@ import type { test("main", async () => { const output = await main(); - expect(output).toContain("Brünnhilde Bun"); + expect(output).toEqual("hello there, Brünnhilde Bun"); }); diff --git a/integration/commonjs/index.js b/integration/commonjs/index.js index 40f00cd..6d8c436 100644 --- a/integration/commonjs/index.js +++ b/integration/commonjs/index.js @@ -5,12 +5,13 @@ const replicate = new Replicate({ }); module.exports = async function main() { - return await replicate.run( - "replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", + const output = await replicate.run( + "replicate/canary:30e22229542eb3f79d4f945dacb58d32001b02cc313ae6f54eef27904edf3272", { input: { text: "Claire CommonJS", }, } ); + return output.join("").trim(); }; diff --git a/integration/commonjs/index.test.js b/integration/commonjs/index.test.js index 6e0f8b2..afc3c01 100644 --- a/integration/commonjs/index.test.js +++ b/integration/commonjs/index.test.js @@ -4,5 +4,5 @@ const main = require("./index"); test("main", async () => { const output = await main(); - assert.equal(output, "hello Claire CommonJS"); + assert.equal(output, "hello there, Claire CommonJS"); }); diff --git a/integration/deno/index.test.ts b/integration/deno/index.test.ts index 28965d5..e944d77 100644 --- a/integration/deno/index.test.ts +++ b/integration/deno/index.test.ts @@ -21,6 +21,6 @@ Deno.test({ name: "main", async fn() { const output = await main(); - assertEquals({ output }, { output: "hello Deno the dinosaur" }); + assertEquals({ output }, { output: "hello there, Deno the dinosaur" }); }, }); diff --git a/integration/deno/index.ts b/integration/deno/index.ts index 069e28a..a235699 100644 --- a/integration/deno/index.ts +++ b/integration/deno/index.ts @@ -5,12 +5,13 @@ const replicate = new Replicate({ }); export default async function main() { - return await replicate.run( - "replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", + const output = (await replicate.run( + "replicate/canary:30e22229542eb3f79d4f945dacb58d32001b02cc313ae6f54eef27904edf3272", { input: { text: "Deno the dinosaur", }, } - ); + )) as string[]; + return output.join("").trim(); } diff --git a/integration/esm/index.js b/integration/esm/index.js index 9264f3c..48feccb 100644 --- a/integration/esm/index.js +++ b/integration/esm/index.js @@ -5,12 +5,13 @@ const replicate = new Replicate({ }); export default async function main() { - return await replicate.run( - "replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", + const output = await replicate.run( + "replicate/canary:30e22229542eb3f79d4f945dacb58d32001b02cc313ae6f54eef27904edf3272", { input: { text: "Evelyn ESM", }, } ); + return Array.isArray(output) ? output.join("").trim() : String(output).trim(); } diff --git a/integration/esm/index.test.js b/integration/esm/index.test.js index 7549e90..c95ab8b 100644 --- a/integration/esm/index.test.js +++ b/integration/esm/index.test.js @@ -4,5 +4,5 @@ import main from "./index.js"; test("main", async () => { const output = await main(); - assert.equal(output, "hello Evelyn ESM"); + assert.equal(output, "hello there, Evelyn ESM"); }); diff --git a/integration/typescript/index.test.ts b/integration/typescript/index.test.ts index b7928c5..0f0f356 100644 --- a/integration/typescript/index.test.ts +++ b/integration/typescript/index.test.ts @@ -20,5 +20,5 @@ import type { test("main", async () => { const output = await main(); - assert.equal(output, "hello Tracy TypeScript"); + assert.equal(output, "hello there, Tracy TypeScript"); }); diff --git a/integration/typescript/index.ts b/integration/typescript/index.ts index e49f75c..1b276bc 100644 --- a/integration/typescript/index.ts +++ b/integration/typescript/index.ts @@ -5,12 +5,13 @@ const replicate = new Replicate({ }); export default async function main() { - return await replicate.run( - "replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa", + const output = (await replicate.run( + "replicate/canary:30e22229542eb3f79d4f945dacb58d32001b02cc313ae6f54eef27904edf3272", { input: { text: "Tracy TypeScript", }, } - ); + )) as string[]; + return output.join("").trim(); }