Commit 5cf95535 by liimin

chore: 清理测试文件并更新tsconfig配置

删除不再需要的测试文件以保持项目整洁
添加ignoreDeprecations配置以忽略TypeScript 6.0的废弃警告
1 parent c078e635
// 测试 Defaults 类的功能
const { Defaults } = require('./dist/index');
// 创建默认配置实例
const defaultConfig = new Defaults();
console.log('默认配置:', defaultConfig);
// 创建自定义配置实例
const customConfig = new Defaults({
baseURL: 'https://api.example.com',
timeout: 10000,
headers: {
'Authorization': 'Bearer token123',
'X-Custom-Header': 'CustomValue'
},
appId: 'test-app-id',
appSecret: 'test-app-secret',
retries: 3,
customField: 'customValue' // 测试自定义字段
});
console.log('自定义配置:', customConfig);
// 测试合并配置
const mergedConfig = customConfig.merge({
timeout: 15000,
headers: {
'X-Another-Header': 'AnotherValue'
},
params: {
page: 1,
limit: 10
}
});
console.log('合并后的配置:', mergedConfig);
// 验证合并是否正确保留了原始值和新值
console.log('验证合并结果:');
console.log('baseURL 保持不变:', mergedConfig.baseURL === customConfig.baseURL);
console.log('timeout 已更新:', mergedConfig.timeout === 15000);
console.log('原始 headers 保留:', mergedConfig.headers['Authorization'] === 'Bearer token123');
console.log('新 headers 添加:', mergedConfig.headers['X-Another-Header'] === 'AnotherValue');
console.log('params 已添加:', mergedConfig.params.page === 1 && mergedConfig.params.limit === 10);
console.log('自定义字段保留:', mergedConfig.customField === 'customValue');
\ No newline at end of file
// 完整测试 Defaults 类与请求功能
const Request = require('./dist/index').default;
const { Defaults } = require('./dist/index');
// 创建默认配置
const defaults = new Defaults({
baseURL: 'https://jsonplaceholder.typicode.com',
timeout: 10000,
headers: {
'X-Custom-Header': 'TestValue'
}
});
console.log('创建的默认配置:', defaults);
// 使用默认配置创建请求实例
const request = new Request(defaults);
// 测试 GET 请求
console.log('\n发送 GET 请求...');
request.get('/posts/1')
.then(response => {
console.log('GET 请求成功,状态码:', response.status);
console.log('响应数据:', response.data);
// 测试使用 merge 方法创建特定配置
console.log('\n使用 merge 方法创建特定配置...');
const specificConfig = request.defaults.merge({
params: {
_limit: 3
},
headers: {
'X-Test-Header': 'SpecificValue'
}
});
console.log('特定配置:', specificConfig);
// 使用特定配置发送请求
console.log('\n使用特定配置发送 GET 请求...');
return request.get('/posts', specificConfig);
})
.then(response => {
console.log('使用特定配置的 GET 请求成功,状态码:', response.status);
console.log('响应数据长度:', response.data.length);
console.log('第一条数据:', response.data[0]);
})
.catch(error => {
console.error('请求失败:', error.message);
});
\ No newline at end of file
// 测试重构后的代码功能
const Request = require('./dist/index.js');
// 创建请求实例
const request = new Request({
baseURL: 'https://httpbin.org',
appId: 'test-app-id',
appSecret: 'test-app-secret',
timeout: 5000,
events: {
request: (data) => {
console.log('请求事件触发:', data.url);
},
response: (data) => {
console.log('响应事件触发:', data.status);
}
}
});
// 测试GET请求
console.log('测试GET请求...');
request.get('/get', { params: { test: 'value' } })
.then(response => {
console.log('GET请求成功:', response.status);
})
.catch(error => {
console.error('GET请求失败:', error);
});
// 测试POST请求
console.log('测试POST请求...');
request.post('/post', { data: 'test-data' })
.then(response => {
console.log('POST请求成功:', response.status);
})
.catch(error => {
console.error('POST请求失败:', error);
});
// 测试白名单功能
console.log('白名单预加载状态:', Request.isWhitelistPreloaded);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test UMD Module</title>
</head>
<body>
<h1>Testing UMD Module</h1>
<div id="result"></div>
<script src="./dist/index.umd.js"></script>
<script>
try {
// 尝试访问库
console.log('Library loaded:', window.glskFetch);
document.getElementById('result').innerHTML = 'Library loaded successfully!';
} catch (error) {
console.error('Error loading library:', error);
document.getElementById('result').innerHTML = 'Error: ' + error.message;
}
</script>
</body>
</html>
\ No newline at end of file
......@@ -3,6 +3,7 @@
"target": "ES2015",
"module": "ES2015",
"moduleResolution": "node",
"ignoreDeprecations": "6.0",
"declaration": true,
"outDir": "./dist",
"strict": true,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!