52 lines
2.3 KiB
JavaScript
52 lines
2.3 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, '..');
|
|
|
|
function read(relativePath) {
|
|
return fs.readFileSync(path.join(root, relativePath), 'utf8');
|
|
}
|
|
|
|
test('配置始终使用后端提供的 PC 接口地址', () => {
|
|
const createConfig = require('../config.js');
|
|
const development = createConfig({ location: { hostname: 'localhost', port: '5500' } });
|
|
const production = createConfig({ location: { hostname: 'genealogy.example.test', port: '' } });
|
|
|
|
assert.equal(development.getEnvironment(), 'development');
|
|
assert.equal(production.getEnvironment(), 'production');
|
|
assert.equal(development.getApiBaseUrl(), 'https://backend-api.ddxcjp.cn/');
|
|
assert.equal(production.getApiBaseUrl(), 'https://backend-api.ddxcjp.cn/');
|
|
});
|
|
|
|
test('PC 对接规划明确以 Apifox 目录而非导出快照为契约源', () => {
|
|
const plan = read('docs/PC接口对接规划.md');
|
|
|
|
assert.match(plan, /Apifox 的 PC 目录是 PC 前端接口的唯一正式契约源/);
|
|
assert.match(plan, /旧 OpenAPI 文件不再作为新增功能依据/);
|
|
});
|
|
|
|
test('pages do not load scripts for unavailable business APIs', () => {
|
|
const removedScripts = [
|
|
'album-pages.js', 'article-pages.js', 'ceremony-pages.js',
|
|
'feedback-pages.js', 'genealogy-pages.js', 'growth-pages.js',
|
|
'help-pages.js', 'join-apply-pages.js', 'member-admin-pages.js',
|
|
'memo-pages.js', 'notification-pages.js', 'promotion-pages.js', 'vip-pages.js'
|
|
];
|
|
const retainedPages = fs.readdirSync(root).filter((entry) => entry.endsWith('.html'));
|
|
|
|
retainedPages.forEach((page) => {
|
|
const source = read(page);
|
|
removedScripts.forEach((script) => {
|
|
assert.equal(source.includes('src="public/js/' + script + '"'), false, `${page} still loads ${script}`);
|
|
});
|
|
});
|
|
|
|
['profile-feed.html', 'profile-feed-edit.html'].forEach((page) => {
|
|
assert.equal(read(page).includes('src="public/js/feed-pages.js"'), true, `${page} must load feed-pages.js`);
|
|
});
|
|
assert.equal(read('profile-generation.html').includes('src="public/js/generation-pages.js"'), true, 'profile-generation.html must load generation-pages.js');
|
|
assert.equal(read('profile-tree.html').includes('src="public/js/lineage-pages.js"'), true, 'profile-tree.html must load lineage-pages.js');
|
|
});
|