fix(runtime): remove stale aksrt namespace dependency

This commit is contained in:
2026-09-03 13:24:51 +08:00
parent 03dd4ea707
commit 9d458dd99a
4 changed files with 51 additions and 12 deletions
@@ -4,6 +4,7 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const vm = require('node:vm');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
@@ -44,6 +45,52 @@ test('main owns the one global auto_fun boot', () => {
assert.match(main, /jQuery\(document\)\.trigger\(['"]auto_fun['"]\)/);
});
test('theme and comments do not depend on the removed aksrt namespace APIs', () => {
const theme = read('assets/js/core/theme.js');
const comments = read('assets/js/comment-ajax.js');
const runtime = read('assets/js/runtime/main.min.js');
assert.match(theme, /window\.aksrtData\.themeMode/);
assert.doesNotMatch(theme, /(?:window\.)?aksrt\.toggleTheme/);
assert.doesNotMatch(comments, /(?:window\.)?aksrt\.(?:__|confirm)/);
assert.doesNotMatch(runtime, /(?:window\.)?aksrt\.(?:toggleTheme|__|confirm)/);
});
test('theme initializes when the removed aksrt namespace is absent', () => {
const classList = { toggle() {}, contains() { return false; } };
const document = {
readyState: 'complete',
cookie: '',
body: { classList, setAttribute() {} },
documentElement: { classList, setAttribute() {} },
head: { appendChild() {} },
querySelector() { return null; },
querySelectorAll() { return []; },
getElementById() { return null; },
createElement() { return { setAttribute() {} }; },
dispatchEvent() {},
};
const window = {
document,
location: { protocol: 'https:' },
localStorage: { getItem() { return null; }, setItem() {} },
matchMedia() { return { matches: false }; },
setTimeout,
innerWidth: 1280,
innerHeight: 720,
};
assert.doesNotThrow(() => vm.runInNewContext(read('assets/js/core/theme.js'), {
window,
document,
localStorage: window.localStorage,
CustomEvent: class {},
Date,
Math,
}));
assert.equal(window.aksrt, undefined);
});
test('routed modules use one namespaced auto_fun owner and no registry', () => {
for (const file of routed) {
const source = read(file);