统一全系统资源加载、轻量趋势与缓存恢复
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import ts from 'typescript';
|
||||
|
||||
const source = ts.transpileModule(readFileSync(new URL('../src/importLifecycleGuards.ts', import.meta.url), 'utf8'), {
|
||||
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
|
||||
}).outputText.replace(/export /g, '');
|
||||
const guards = new Function(`${source};return { importIssuePageKey, matchesImportIssuePage, runImportPollFollowup };`)();
|
||||
|
||||
test('import issue page identity includes both run and page', () => {
|
||||
assert.equal(guards.importIssuePageKey('run-a', 2), 'run-a:2');
|
||||
assert.notEqual(guards.importIssuePageKey('run-a', 2), guards.importIssuePageKey('run-a', 3));
|
||||
assert.notEqual(guards.importIssuePageKey('run-a', 2), guards.importIssuePageKey('run-b', 2));
|
||||
assert.equal(guards.matchesImportIssuePage('run-a', 2, 'run-a', 2), true);
|
||||
assert.equal(guards.matchesImportIssuePage('run-a', 2, 'run-a', 3), false);
|
||||
assert.equal(guards.matchesImportIssuePage('run-a', 2, 'run-b', 2), false);
|
||||
});
|
||||
|
||||
test('an import poll does not start candidate or issue follow-up reads after the view becomes inactive', async () => {
|
||||
let active = false;
|
||||
let followupCalls = 0;
|
||||
const skipped = await guards.runImportPollFollowup('run-a', () => active, async () => { followupCalls++; });
|
||||
assert.deepEqual(skipped, { started: false, current: false });
|
||||
assert.equal(followupCalls, 0);
|
||||
|
||||
active = true;
|
||||
let resolveRead;
|
||||
const pending = guards.runImportPollFollowup('run-a', () => active, () => {
|
||||
followupCalls++;
|
||||
return new Promise(resolve => { resolveRead = resolve; });
|
||||
});
|
||||
active = false;
|
||||
resolveRead({ items: [] });
|
||||
const stale = await pending;
|
||||
assert.deepEqual(stale, { started: true, current: false, value: { items: [] } });
|
||||
assert.equal(followupCalls, 1);
|
||||
});
|
||||
Reference in New Issue
Block a user