51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {navigateBrandDocument} from './brand-navigation.mjs';
|
|
const response = status => ({ok: () => status === 200, status: () => status});
|
|
|
|
test('successful documents are fetched once', async () => {
|
|
let calls = 0;
|
|
await navigateBrandDocument(async () => { calls++; return response(200); }, '/canvas');
|
|
assert.equal(calls, 1);
|
|
});
|
|
test('one proxy failure can recover within the original deadline', async () => {
|
|
const timeouts = []; let elapsed = 0;
|
|
await navigateBrandDocument(async timeout => {
|
|
timeouts.push(timeout); elapsed = 15000;
|
|
return response(timeouts.length === 1 ? 500 : 200);
|
|
}, '/canvas', () => elapsed);
|
|
assert.deepEqual(timeouts, [60000, 45000]);
|
|
});
|
|
test('connection reset and interrupted bootstrap scripts can recover once', async () => {
|
|
for(const failure of ['net::ERR_CONNECTION_RESET','Document bootstrap script request failed: net::ERR_ABORTED']){
|
|
let calls = 0;
|
|
await navigateBrandDocument(async () => {
|
|
if (++calls === 1) throw new Error(failure);
|
|
return response(200);
|
|
}, '/canvas');
|
|
assert.equal(calls, 2);
|
|
}
|
|
});
|
|
test('persistent server failure is not hidden', async () => {
|
|
let calls = 0;
|
|
await assert.rejects(navigateBrandDocument(async () => { calls++; return response(502); }, '/canvas'), /HTTP 502/);
|
|
assert.equal(calls, 2);
|
|
});
|
|
test('missing routes, authentication failures and ordinary timeouts are not retried', async () => {
|
|
for (const status of [401, 403, 404]) {
|
|
let calls = 0;
|
|
await assert.rejects(navigateBrandDocument(async () => { calls++; return response(status); }, '/canvas'), /HTTP/);
|
|
assert.equal(calls, 1);
|
|
}
|
|
let calls = 0;
|
|
await assert.rejects(navigateBrandDocument(async () => { calls++; throw new Error('Timeout 60000ms exceeded'); }, '/canvas'), /Timeout/);
|
|
assert.equal(calls, 1);
|
|
});
|
|
test('recovery cannot extend the total navigation budget', async () => {
|
|
let calls = 0, elapsed = 0;
|
|
await assert.rejects(navigateBrandDocument(async () => {
|
|
calls++; elapsed = 60000; return response(503);
|
|
}, '/canvas', () => elapsed), /budget exhausted/);
|
|
assert.equal(calls, 1);
|
|
});
|