91 lines
3.8 KiB
JavaScript
91 lines
3.8 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const root = path.resolve(__dirname, '..', '..');
|
|
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
|
|
|
test('front submit enqueues the WordPress editor before wp_head is rendered', () => {
|
|
const source = read('templates/pages/page-submit.php');
|
|
const enqueueAt = source.indexOf('wp_enqueue_editor();');
|
|
const headerAt = source.indexOf('\nget_header();');
|
|
|
|
assert.notEqual(enqueueAt, -1, 'front submit must explicitly enqueue the editor runtime');
|
|
assert.notEqual(headerAt, -1, 'front submit must render the theme header');
|
|
assert.ok(enqueueAt < headerAt, 'editor assets must be queued before get_header()/wp_head');
|
|
});
|
|
|
|
test('published post content reaches the front submit editor unchanged', () => {
|
|
const context = read('templates/parts/submit/context.php');
|
|
const editor = read('templates/parts/submit/editor-main.php');
|
|
|
|
assert.match(context, /\$current_content\s*=\s*\$edit_post\s*\?\s*\$edit_post->post_content\s*:\s*'';/);
|
|
assert.match(editor, /wp_editor\(\(string\) \$ctx\['current_content'\], 'post_content', \$editor_settings\);/);
|
|
});
|
|
|
|
test('front submit uses the WordPress registered jQuery runtime', () => {
|
|
const source = read('src/Core/ScriptsPart1b.php');
|
|
|
|
assert.match(source, /wp_enqueue_script\('jquery'\);/);
|
|
assert.match(source, /registered\['jquery'\]->deps\s*=\s*\['jquery-core'\]/);
|
|
assert.doesNotMatch(source, /wp_deregister_script\('jquery'\)/);
|
|
assert.doesNotMatch(source, /wp_register_script\(\s*'jquery'/);
|
|
assert.doesNotMatch(source, /jquery-migrate/);
|
|
assert.doesNotMatch(source, /runtime\/libs\/jquery\.min\.js|['"]1\.9\.1['"]/);
|
|
});
|
|
|
|
test('legacy runtime modules use jQuery explicitly without a dollar alias', () => {
|
|
const modules = [
|
|
'main',
|
|
'captcha',
|
|
'comment',
|
|
'input-expand',
|
|
'mini-touch',
|
|
'mini-upload',
|
|
'page-edit',
|
|
'page-navs',
|
|
'page-template',
|
|
'poster-share',
|
|
'section-navs',
|
|
'svg-icon',
|
|
'waterfall',
|
|
'weixin-share',
|
|
];
|
|
|
|
for (const module of modules) {
|
|
for (const suffix of ['.js', '.min.js']) {
|
|
const relative = `assets/js/runtime/${module}${suffix}`;
|
|
const absolute = path.join(root, relative);
|
|
if (!fs.existsSync(absolute) || fs.statSync(absolute).size === 0) continue;
|
|
const source = fs.readFileSync(absolute, 'utf8');
|
|
assert.doesNotMatch(source, /(^|[^\w$])\$(?:\(|\.)/, `${relative} must use jQuery explicitly`);
|
|
assert.doesNotMatch(source, /(?:window\.)?\$\s*=/, `${relative} must not create a dollar alias`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('theme runtime never changes native listener passivity for third-party editors', () => {
|
|
const scripts = read('src/Core/Scripts.php');
|
|
const scriptsPart2 = read('src/Core/ScriptsPart2.php');
|
|
const buildTool = read('tools/build-public-assets.mjs');
|
|
const publicRuntime = read('assets/js/build/public.js');
|
|
|
|
assert.doesNotMatch(scripts, /enqueue_passive_polyfill|aksrt-passive-events/);
|
|
assert.doesNotMatch(scriptsPart2, /enqueue_passive_polyfill|aksrt-passive-events/);
|
|
assert.doesNotMatch(buildTool, /passive-events\.js/);
|
|
assert.doesNotMatch(publicRuntime, /EventTarget\.prototype\.addEventListener|__passiveSupported/);
|
|
assert.equal(fs.existsSync(path.join(root, 'assets/js/passive-events.js')), false);
|
|
});
|
|
|
|
test('public theme does not inject a global focus-visible ring', () => {
|
|
const globalFocusRule = /(^|})\s*:focus-visible\s*\{/m;
|
|
const reset = read('assets/css/core/reset.css');
|
|
const publicCss = read('assets/css/build/public.css');
|
|
const publicMinCss = read('assets/css/build/public.min.css');
|
|
|
|
assert.doesNotMatch(reset, globalFocusRule);
|
|
assert.doesNotMatch(publicCss, globalFocusRule);
|
|
assert.doesNotMatch(publicMinCss, globalFocusRule);
|
|
});
|