Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test for Bun #220

Merged
merged 10 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,23 +27,51 @@ jobs:
- run: npm run check
- run: npm run lint

integration:

integration-node:
needs: test
runs-on: ubuntu-latest

env:
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}

strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
node-version: [18.x, 20.x]
suite: [commonjs, esm, typescript, cloudflare-worker]
suite: [commonjs, esm, typescript]
exclude:
- suite: cloudflare-worker
node-version: 18.x # Only test Cloudflare suite with the latest Node version
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
# Build a production tarball and run the integration tests against it.
- run: |
PKG_TARBALL=$(npm --loglevel error pack)
npm --prefix integration/${{ matrix.suite }} install
npm --prefix integration/${{ matrix.suite }} install "file:/./$PKG_TARBALL"
npm --prefix integration/${{ matrix.suite }} test


integration-edge:
needs: test
runs-on: ubuntu-latest

env:
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}

strategy:
matrix:
node-version: [20.x]
suite: [cloudflare-worker]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -58,3 +86,35 @@ jobs:
npm --prefix integration/${{ matrix.suite }} install
npm --prefix integration/${{ matrix.suite }} install "file:/./$PKG_TARBALL"
npm --prefix integration/${{ matrix.suite }} test


integration-bun:
needs: test
runs-on: ubuntu-latest

env:
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}

strategy:
matrix:
bun-version: [1.0.11]
node-version: [20.x]
suite: [bun]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Use Bun ${{ matrix.bun-version }}
uses: oven-sh/setup-bun@v1
with:
bun-version: ${{ matrix.bun-version }}
- run: |
PKG_TARBALL=$(npm --loglevel error pack)
cd integration/${{ matrix.suite }}
bun uninstall replicate
bun install "file:../../$PKG_TARBALL"
bun test
1 change: 1 addition & 0 deletions integration/bun/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Binary file added integration/bun/bun.lockb
Binary file not shown.
23 changes: 23 additions & 0 deletions integration/bun/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from "bun:test";
import main from "./index.js";

// Verify exported types.
import type {
Status,
Visibility,
WebhookEventType,
ApiError,
Collection,
Hardware,
Model,
ModelVersion,
Prediction,
Training,
Page,
ServerSentEvent,
} from "replicate";

test("main", async () => {
const output = await main();
expect(output as any).toEqual("hello Brünnhilde Bun");
});
16 changes: 16 additions & 0 deletions integration/bun/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Replicate from "replicate";

const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});

export default async function main() {
return await replicate.run(
"replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
{
input: {
text: "Brünnhilde Bun",
},
}
);
}
14 changes: 14 additions & 0 deletions integration/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "replicate-app-bun",
"version": "0.0.0",
"private": true,
"description": "Bun integration tests",
"main": "index.js",
"type": "module",
"dependencies": {
"replicate": "file:../../"
},
"devDependencies": {
"@types/bun": "latest"
}
}
15 changes: 15 additions & 0 deletions integration/bun/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2018",
"module": "nodenext",
"inlineSourceMap": true,
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true
}
}
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"allowJs": true
},
"exclude": [
"**/node_modules"
"**/node_modules",
"integration/**"
]
}
}

Loading