test-refactor.js
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 测试重构后的代码功能
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);