Skip to content

Commit

Permalink
added integration test for siteproxylocal
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed Feb 24, 2020
1 parent 2eaf9e1 commit 656bd60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const pathReplace = ({host, httpType, body}) => {
let myRe = new RegExp('href="[.]?/([-a-z0-9]+?[.][-a-z0-9]+?)', 'g')
body = body.replace(myRe, `href="/${httpType}/${host}/$1`)

myRe = new RegExp('href="[.]?/([-a-z0-9]+?)/', 'g')
body = body.replace(myRe, `href="/${httpType}/${host}/$1/`)

myRe = new RegExp(' src=(["\'])/([-a-z0-9]+?)', 'g')
body = body.replace(myRe, ` src=$1/${httpType}/${host}/$2`)

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "site proxy, zero configuration from client side. reverse proxy to all internet",
"main": "index.js",
"scripts": {
"test": "jest",
"start": "node --tls-min-v1.0 index.js",
"localstart": "localFlag=true node --tls-min-v1.0 index.js"
},
Expand All @@ -15,5 +16,9 @@
"express": "^4.17.1",
"http-proxy-middleware": "^0.20.0",
"iconv-lite": "^0.5.1"
},
"devDependencies": {
"axios": "^0.19.2",
"jest": "^25.1.0"
}
}
19 changes: 19 additions & 0 deletions test/siteproxylocal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @jest-environment node
*/
const axios = require('axios');

const httpprefix = 'https'
const serverName = `siteproxylocal.now.sh`
const port = '443'

test('search wikipedia, open it, then click link', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/zh.wikipedia.org/wiki/%E6%B5%8B%E8%AF%95`
const response = await axios({
method: 'get',
url,
})
// console.log(`${JSON.stringify(response)}`)
// expect(sum(1, 2)).toBe(3);
expect(response.data.indexOf(`/https/zh.wikipedia.org/wiki/%E6%B5%8B%E8%AF%95`)).not.toBe(-1)
}, 30000);

0 comments on commit 656bd60

Please sign in to comment.