/ clis / pixiv / test-utils.js
test-utils.js
 1  import { vi } from 'vitest';
 2  /**
 3   * Create a minimal page mock with only the methods commonly used by Pixiv adapters.
 4   *
 5   * Since all TS adapters now go through `pixivFetch` which calls `page.evaluate`,
 6   * the evaluate results should match the raw Pixiv Ajax response format:
 7   * - Success: `{ body: ... }` (pixivFetch returns the `body` field)
 8   * - HTTP error: `{ __httpError: <status> }` (pixivFetch detects and throws)
 9   *
10   * Additional methods can be overridden via the overrides parameter.
11   */
12  export function createPageMock(evaluateResults, overrides) {
13      const evaluate = vi.fn();
14      for (const result of evaluateResults) {
15          evaluate.mockResolvedValueOnce(result);
16      }
17      return {
18          goto: vi.fn().mockResolvedValue(undefined),
19          evaluate,
20          getCookies: vi.fn().mockResolvedValue([]),
21          ...overrides,
22      };
23  }