修改底层请求逻辑,封装请求方法
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const rootDirectory = path.join(__dirname, '..');
|
||||
|
||||
function scriptIndex(html, source) {
|
||||
return html.indexOf(`src="${source}"`);
|
||||
}
|
||||
|
||||
function run() {
|
||||
const pages = fs.readdirSync(rootDirectory).filter((fileName) => {
|
||||
if (!fileName.endsWith('.html')) return false;
|
||||
|
||||
const html = fs.readFileSync(path.join(rootDirectory, fileName), 'utf8');
|
||||
return html.includes('public/js/api-client.js') || html.includes('utils/ApiClient.js');
|
||||
});
|
||||
|
||||
assert.strictEqual(pages.length, 45, '接口客户端加载页面数量应保持为 45 页');
|
||||
|
||||
pages.forEach((fileName) => {
|
||||
const html = fs.readFileSync(path.join(rootDirectory, fileName), 'utf8');
|
||||
const configIndex = scriptIndex(html, 'config.js');
|
||||
const storageIndex = scriptIndex(html, 'utils/StorageUtil.js');
|
||||
const axiosIndex = scriptIndex(html, 'utils/axios.js');
|
||||
const requestIndex = scriptIndex(html, 'utils/AxiosRequestUtil.js');
|
||||
const apiIndex = scriptIndex(html, 'utils/ApiClient.js');
|
||||
|
||||
assert.notStrictEqual(configIndex, -1, `${fileName} 应加载环境配置`);
|
||||
assert.notStrictEqual(storageIndex, -1, `${fileName} 应加载 token 存储工具`);
|
||||
assert.notStrictEqual(axiosIndex, -1, `${fileName} 应加载本地 Axios`);
|
||||
assert.notStrictEqual(requestIndex, -1, `${fileName} 应加载 AxiosRequestUtil`);
|
||||
assert.notStrictEqual(apiIndex, -1, `${fileName} 应加载 ApiClient`);
|
||||
assert.ok(configIndex < storageIndex, `${fileName} 应先加载环境配置再加载存储工具`);
|
||||
assert.ok(storageIndex < axiosIndex, `${fileName} 应先加载存储工具再加载 Axios`);
|
||||
assert.ok(axiosIndex < requestIndex, `${fileName} 应先加载 Axios 再加载请求封装`);
|
||||
assert.ok(requestIndex < apiIndex, `${fileName} 应先加载请求封装再加载接口客户端`);
|
||||
assert.strictEqual(html.includes('utils/RequestUtil.js'), false, `${fileName} 不应继续加载旧 RequestUtil`);
|
||||
assert.strictEqual(html.includes('public/js/api-client.js'), false, `${fileName} 不应继续加载旧 ApiClient`);
|
||||
});
|
||||
|
||||
console.log('api-script-order tests passed');
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user