mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-10-20 17:01:24 -07:00
test: cut low-value tests, rewrite the rest around behavior, parallelize lanes (#285)
This commit is contained in:
1 parent
4b6842d034
commit
b48083ddd8
368 files changed
+18045
-60331
No files matched your search
@@ -2,44 +2,49 @@ import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { clearYomitanParserRuntimeState } from './yomitan-extension-runtime-state';
|
||||
|
||||
test('clearYomitanParserRuntimeState destroys parser window and clears parser promises', () => {
|
||||
const calls: string[] = [];
|
||||
const parserWindow = {
|
||||
isDestroyed: () => false,
|
||||
destroy: () => {
|
||||
calls.push('destroy');
|
||||
},
|
||||
};
|
||||
const cases = [
|
||||
{ name: 'a live parser window', window: { destroyed: false }, expectDestroyed: true },
|
||||
{
|
||||
name: 'an already destroyed parser window',
|
||||
window: { destroyed: true },
|
||||
expectDestroyed: false,
|
||||
},
|
||||
{ name: 'no parser window', window: null, expectDestroyed: false },
|
||||
];
|
||||
|
||||
clearYomitanParserRuntimeState({
|
||||
getYomitanParserWindow: () => parserWindow as never,
|
||||
setYomitanParserWindow: (window) => calls.push(`window:${window === null ? 'null' : 'set'}`),
|
||||
setYomitanParserReadyPromise: (promise) =>
|
||||
calls.push(`ready:${promise === null ? 'null' : 'set'}`),
|
||||
setYomitanParserInitPromise: (promise) =>
|
||||
calls.push(`init:${promise === null ? 'null' : 'set'}`),
|
||||
for (const c of cases) {
|
||||
test(`clearYomitanParserRuntimeState clears parser state with ${c.name}`, () => {
|
||||
let destroyCalls = 0;
|
||||
const parserWindow = c.window && {
|
||||
isDestroyed: () => c.window.destroyed,
|
||||
destroy: () => {
|
||||
destroyCalls += 1;
|
||||
},
|
||||
};
|
||||
const state: {
|
||||
window: unknown;
|
||||
ready: Promise<void> | null;
|
||||
init: Promise<boolean> | null;
|
||||
} = {
|
||||
window: parserWindow,
|
||||
ready: Promise.resolve(),
|
||||
init: Promise.resolve(true),
|
||||
};
|
||||
|
||||
clearYomitanParserRuntimeState({
|
||||
getYomitanParserWindow: () => parserWindow,
|
||||
setYomitanParserWindow: (window) => {
|
||||
state.window = window;
|
||||
},
|
||||
setYomitanParserReadyPromise: (promise) => {
|
||||
state.ready = promise;
|
||||
},
|
||||
setYomitanParserInitPromise: (promise) => {
|
||||
state.init = promise;
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(destroyCalls, c.expectDestroyed ? 1 : 0);
|
||||
assert.deepEqual(state, { window: null, ready: null, init: null });
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, ['destroy', 'window:null', 'ready:null', 'init:null']);
|
||||
});
|
||||
|
||||
test('clearYomitanParserRuntimeState skips destroy when parser window is already gone', () => {
|
||||
const calls: string[] = [];
|
||||
const parserWindow = {
|
||||
isDestroyed: () => true,
|
||||
destroy: () => {
|
||||
calls.push('destroy');
|
||||
},
|
||||
};
|
||||
|
||||
clearYomitanParserRuntimeState({
|
||||
getYomitanParserWindow: () => parserWindow as never,
|
||||
setYomitanParserWindow: (window) => calls.push(`window:${window === null ? 'null' : 'set'}`),
|
||||
setYomitanParserReadyPromise: (promise) =>
|
||||
calls.push(`ready:${promise === null ? 'null' : 'set'}`),
|
||||
setYomitanParserInitPromise: (promise) =>
|
||||
calls.push(`init:${promise === null ? 'null' : 'set'}`),
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, ['window:null', 'ready:null', 'init:null']);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user