27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { candidates } = require('./prewarm-next.js');
|
|
|
|
const q = ['a', 'b', 'c', 'd'].map(id => ({ id }));
|
|
|
|
test('returns the next n queue ids in existing order', () => {
|
|
assert.deepEqual(candidates(q, 0, {}, 2), ['b', 'c']);
|
|
});
|
|
test('repeat all wraps and does not duplicate ids', () => {
|
|
assert.deepEqual(candidates(q, 3, { repeatMode: 'all' }, 2), ['a', 'b']);
|
|
assert.deepEqual(candidates([{ id: 'x' }, { id: 'x' }], 0, { repeatMode: 'all' }, 3), []);
|
|
});
|
|
test('repeat off stops at the end and loop one has no candidates', () => {
|
|
assert.deepEqual(candidates(q, 3, {}, 2), []);
|
|
assert.deepEqual(candidates(q, 0, { loopOne: true, repeatMode: 'all' }, 2), []);
|
|
});
|
|
test('skips offline and known server cached ids and deduplicates', () => {
|
|
assert.deepEqual(candidates(q, 0, {}, 3, { offline: ['b'], serverCached: ['c'] }), ['d']);
|
|
assert.deepEqual(candidates([{ id: 'a' }, { id: 'b', serverCached: true }, { id: 'c' }], 0, {}, 2), ['c']);
|
|
});
|
|
test('shuffle follows the queue order selected before advance', () => {
|
|
const shuffled = ['a', 'd', 'b', 'c'].map(id => ({ id }));
|
|
assert.deepEqual(candidates(shuffled, 0, { shuffle: true }, 2), ['d', 'b']);
|
|
});
|