Admin: add games from any list or itch.io collection (Check first, batches of 200, per-game ingest tracking from scripts/state/ingest_outcomes.json), followed collections and auto-approve run by the cron in one [auto] commit, bulk remove/edit up to 100 games in one commit, New games, Activity and Settings pages. D1 migration 0002 (applied to production before this merge). Policies (ToS, Privacy, Disclaimer, EN + VI) cover approval by the maintainer's rules; LEGAL_VERSION 2026-10-13. Web: the theme button shows the theme in use, no dark-mode flash (pre-paint script, hash in three CSPs), Charts tabs stay mounted (no rebuilt charts or replayed animations), 300 ms entrances, scrollbar gutter on mouse devices. Release 4.4.0 (changelog also covers #130). [skip-discuss] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
953 B
TypeScript
28 lines
953 B
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { chunk, runBatches } from './batch'
|
|
|
|
describe('batches', () => {
|
|
it('splits a list into batches of a given size', () => {
|
|
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]])
|
|
expect(chunk([], 200)).toEqual([])
|
|
})
|
|
|
|
it('sends batches one at a time and stops at the first error, keeping the rest', async () => {
|
|
const progress = vi.fn()
|
|
const send = vi.fn(async (batch: number[]) => {
|
|
if (batch[0] === 3) throw new Error('down')
|
|
return batch.length
|
|
})
|
|
const run = await runBatches([[1, 2], [3], [4]], send, progress)
|
|
expect(run.results).toEqual([2])
|
|
expect(run.failed?.batch).toEqual([3])
|
|
expect(run.remaining).toEqual([[3], [4]])
|
|
expect(send).toHaveBeenCalledTimes(2)
|
|
expect(progress.mock.calls).toEqual([
|
|
[0, 3],
|
|
[1, 3],
|
|
])
|
|
expect((await runBatches([[1]], async () => 'ok')).failed).toBeNull()
|
|
})
|
|
})
|