From c7c848cde4005d40aab7b49a87389eaa8997883f Mon Sep 17 00:00:00 2001 From: Monty Anderson Date: Sat, 4 Jan 2025 21:29:21 +0000 Subject: [PATCH] `*`: add multi-version node tests --- .github/workflows/validate.yml | 17 +++++++++++++++++ example.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 example.ts diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 7056a57..ad4dff7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -20,3 +20,20 @@ jobs: - run: deno test --allow-env --allow-net env: PRODIA_TOKEN: ${{ secrets.PRODIA_TOKEN }} + + node-test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16, 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 diff --git a/example.ts b/example.ts new file mode 100644 index 0000000..fb45ffb --- /dev/null +++ b/example.ts @@ -0,0 +1,31 @@ +import { createProdia } from "./v2"; + +const token = Deno.env.get("PRODIA_TOKEN"); + +if (typeof token !== "string") { + throw new Error("PRODIA_TOKEN is not set"); +} + +const isJpeg = (image: ArrayBuffer): boolean => { + 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(); + +assertEquals(isJpeg(image), true, "Image should be a JPEG"); \ No newline at end of file