forked from netptop/siteproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudflare.test.js
48 lines (44 loc) · 1.53 KB
/
cloudflare.test.js
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
42
43
44
45
46
47
48
/**
* @jest-environment node
*/
const axios = require('axios');
const httpprefix = 'http'
const serverName = '127.0.0.1'
const port = '8787'
test('return a string instead of Uint8Array', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.msn.com/en-us/news`
const response = await axios({
method: 'get',
url,
})
// console.log(`${JSON.stringify(response.data)}`)
// expect(sum(1, 2)).toBe(3);
expect(response.data.indexOf(`http://127.0.0.1:8787/https`)).not.toBe(-1)
}, 30000);
test('post operation', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/postman-echo.com/post`
const response = await axios({
method: 'post',
headers: {
},
url,
data: 'test data123',
})
// console.log(`${JSON.stringify(response.headers)}`)
//console.log(`${JSON.stringify(response.data)}`)
expect(JSON.stringify(response.data).indexOf(`test data123`)).not.toBe(-1)
}, 15000); // should be done within 3 seconds.
test('youtube redirect 302', async () => {
const url = `${httpprefix}://${serverName}:${port}/http/www.youtube.com/channel/UCAq_xQV8pJ2Q_KOszzaYPBg/feed?disable_polymer=1`
const response = await axios({
method: 'get',
maxRedirects: 0,
validateStatus: null, // important for status 302
headers: {
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
//console.log(`${JSON.stringify(response.data)}`)
expect(response.headers['location'].indexOf(`/https/www.youtube`)).not.toBe(-1)
}, 15000); // should be done within 3 seconds.