Skip to content

Commit a4d019a

Browse files
committed
Integration tests for common runtimes
This commit adds some basic integration tests and a new ci workflow for our three common runtimes, nodejs with commonjs and esm as well as TypeScript. The aim here is to ensure that the interface is consistent even if we refactor/restructure the package. The change does require a REPLICATE_API_TOKEN to be available in the CI environment.
1 parent a9e4326 commit a4d019a

File tree

15 files changed

+419
-0
lines changed

15 files changed

+419
-0
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,26 @@ jobs:
2626
- run: npm run test
2727
- run: npm run check
2828
- run: npm run lint
29+
30+
integration:
31+
needs: test
32+
runs-on: ubuntu-latest
33+
34+
strategy:
35+
matrix:
36+
node-version: [18.x, 20.x]
37+
suite: [commonjs, esm, typescript]
38+
# See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
39+
40+
env:
41+
REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }}
42+
43+
steps:
44+
- uses: actions/checkout@v3
45+
- name: Use Node.js ${{ matrix.node-version }}
46+
uses: actions/setup-node@v3
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
cache: "npm"
50+
- run: npm --prefix integration/${{ matrix.suite }} ci --omit=dev
51+
- run: npm --prefix integration/${{ matrix.suite }} test

integration/commonjs/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const Replicate = require("replicate");
2+
3+
const replicate = new Replicate({
4+
auth: process.env.REPLICATE_API_TOKEN,
5+
});
6+
7+
module.exports = async function main() {
8+
return await replicate.run(
9+
"replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
10+
{
11+
input: {
12+
text: "Alice"
13+
}
14+
}
15+
);
16+
};

integration/commonjs/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { test } = require('node:test');
2+
const assert = require('node:assert');
3+
const main = require('./index');
4+
5+
test('main', async () => {
6+
const output = await main();
7+
assert.equal(output, "hello Alice");
8+
});

integration/commonjs/package-lock.json

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/commonjs/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "replicate-app-commonjs",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "node --test ./index.test.js"
9+
},
10+
"dependencies": {
11+
"replicate": "file:../../"
12+
}
13+
}

integration/esm/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Replicate from "replicate";
2+
3+
const replicate = new Replicate({
4+
auth: process.env.REPLICATE_API_TOKEN,
5+
});
6+
7+
export default async function main() {
8+
return await replicate.run(
9+
"replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
10+
{
11+
input: {
12+
text: "Alice"
13+
}
14+
}
15+
);
16+
};

integration/esm/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from 'node:test';
2+
import assert from 'node:assert';
3+
import main from './index.js';
4+
5+
test('main', async () => {
6+
const output = await main();
7+
assert.equal(output, "hello Alice");
8+
});

integration/esm/package-lock.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/esm/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "replicate-app-esm",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "",
6+
"main": "index.js",
7+
"type": "module",
8+
"scripts": {
9+
"test": "node --test ./index.test.js"
10+
},
11+
"dependencies": {
12+
"replicate": "file:../../"
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { test } from 'node:test';
2+
import assert from 'node:assert';
3+
import main from './index.js';
4+
5+
// Verify exported types.
6+
import type {
7+
Status,
8+
Visibility,
9+
WebhookEventType,
10+
ApiError,
11+
Collection,
12+
Hardware,
13+
Model,
14+
ModelVersion,
15+
Prediction,
16+
Training,
17+
Page,
18+
ServerSentEvent,
19+
} from "replicate";
20+
21+
test('main', async () => {
22+
const output = await main();
23+
assert.equal(output, "hello Alice");
24+
});

0 commit comments

Comments
 (0)