Skip to content

Commit

Permalink
*: add multi-version node test matrix (#22)
Browse files Browse the repository at this point in the history
* `*`: add multi-version node tests

* `*`: use `example.mjs`

* `*`: use `blob.arrayBuffer()` instead of `FileReader`

* `.github/workflows/validate.yml`: use latest deno version
  • Loading branch information
montyanderson authored Jan 4, 2025
1 parent b0a7943 commit 8f768bd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

- uses: denoland/setup-deno@v1
with:
deno-version: v2.x
deno-version: vx.x.x

- run: deno fmt --check

Expand All @@ -20,3 +20,24 @@ jobs:
- run: deno test --allow-env --allow-net
env:
PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }}

node-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run prepublish

- run: node example.mjs
env:
PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }}
32 changes: 32 additions & 0 deletions example.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createProdia } from "./dist/v2/index.js";
import { strictEqual } from "assert";

const token = process.env.PRODIA_TOKEN;

if (typeof token !== "string") {
throw new Error("PRODIA_TOKEN is not set");
}

const isJpeg = (image) => {
const view = new Uint8Array(image);

return view[0] === 0xff && view[1] === 0xd8;
};

const client = createProdia({
token,
});

const job = await client.job({
type: "inference.flux.dev.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k",
steps: 1,
width: 1024,
height: 1024,
},
});

const image = await job.arrayBuffer();

strictEqual(isJpeg(image), true, "Image should be a JPEG");
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
},
"author": "Monty Anderson <[email protected]>",
"license": "ISC",
"engines": {
"node": ">=18.0.0"
},
"devDependencies": {
"prettier": "^3.0.0",
"typescript": "^5.1.6"
Expand Down
8 changes: 1 addition & 7 deletions v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,7 @@ export const createProdia = ({
);
}

const buffer = await new Promise<ArrayBuffer>((resolve, reject) => {
const output = body.get("output") as File;
const reader = new FileReader();
reader.readAsArrayBuffer(output);
reader.onload = () => resolve(reader.result as ArrayBuffer);
reader.onerror = () => reject(new Error("Failed to read output"));
});
const buffer = await (body.get("output") as Blob).arrayBuffer();

return {
job: job,
Expand Down

0 comments on commit 8f768bd

Please sign in to comment.