Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate images via OpenAI, Google, OpenRouter, DashScope, Jimeng, Seedream, and Replicate APIs with batch support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/providers/jimeng.test.ts
1import assert from "node:assert/strict";2import test, { type TestContext } from "node:test";34import type { CliArgs } from "../types.ts";5import { generateImage } from "./jimeng.ts";67function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {8return {9prompt: null,10promptFiles: [],11imagePath: null,12provider: null,13model: null,14aspectRatio: null,15size: null,16quality: null,17imageSize: null,18referenceImages: [],19n: 1,20batchFile: null,21jobs: null,22json: false,23help: false,24...overrides,25};26}2728function useEnv(29t: TestContext,30values: Record<string, string | null>,31): void {32const previous = new Map<string, string | undefined>();33for (const [key, value] of Object.entries(values)) {34previous.set(key, process.env[key]);35if (value == null) {36delete process.env[key];37} else {38process.env[key] = value;39}40}4142t.after(() => {43for (const [key, value] of previous.entries()) {44if (value == null) {45delete process.env[key];46} else {47process.env[key] = value;48}49}50});51}5253test("Jimeng submit request uses prompt field expected by current API", async (t) => {54useEnv(t, {55JIMENG_ACCESS_KEY_ID: "test-access-key",56JIMENG_SECRET_ACCESS_KEY: "test-secret-key",57JIMENG_BASE_URL: null,58JIMENG_REGION: null,59});6061const originalFetch = globalThis.fetch;62t.after(() => {63globalThis.fetch = originalFetch;64});6566const calls: Array<{67input: string;68init?: RequestInit;69}> = [];7071globalThis.fetch = async (input, init) => {72calls.push({73input: String(input),74init,75});7677if (calls.length === 1) {78return Response.json({79code: 10000,80data: {81task_id: "task-123",82},83});84}8586return Response.json({87code: 10000,88data: {89status: "done",90binary_data_base64: [Buffer.from("jimeng-image").toString("base64")],91},92});93};9495const image = await generateImage(96"A quiet bamboo forest",97"jimeng_t2i_v40",98makeArgs({ quality: "normal" }),99);100101assert.equal(Buffer.from(image).toString("utf8"), "jimeng-image");102assert.equal(calls.length, 2);103assert.equal(104calls[0]?.input,105"https://visual.volcengineapi.com/?Action=CVSync2AsyncSubmitTask&Version=2022-08-31",106);107108const submitBody = JSON.parse(String(calls[0]?.init?.body)) as Record<string, unknown>;109assert.equal(submitBody.req_key, "jimeng_t2i_v40");110assert.equal(submitBody.prompt, "A quiet bamboo forest");111assert.ok(!("prompt_text" in submitBody));112assert.equal(submitBody.width, 1024);113assert.equal(submitBody.height, 1024);114});115