Something went wrong. Try again.
move github sites
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637import { test, afterEach } from 'node:test'import assert from 'node:assert/strict'import { api } from '../src/github.mjs'
// api() reads a token from the gh CLI before its first request.const realFetch = globalThis.fetchafterEach(() => { globalThis.fetch = realFetch})
test('a secondary rate limit with retry-after is waited out and retried', async () => { let calls = 0 globalThis.fetch = async () => { calls++ if (calls === 1) return new Response('{"message":"You have exceeded a secondary rate limit"}', { status: 403, headers: { 'retry-after': '1' }, }) return new Response('{"ok":true}', { status: 200 }) } const res = await api('/rate-limit-test') assert.equal(res.status, 200) assert.equal(calls, 2)})
test('a plain 403 is returned, not retried', async () => { let calls = 0 globalThis.fetch = async () => { calls++ return new Response('{"message":"Resource not accessible"}', { status: 403 }) } const res = await api('/forbidden-test') assert.equal(res.status, 403) assert.equal(calls, 1)})