Skip to content

Commit c71a3b2

Browse files
committed
Fix test for travis ci (cannot use sudo to launch node)
1 parent 197a581 commit c71a3b2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const certOptions = {
1515
cert: fs.readFileSync(path.resolve(__dirname, "cert/server.crt"))
1616
}
1717

18-
const port = process.env.PORT || 443
18+
const port = process.env.PORT ||
19+
/* istanbul ignore next: impossible to test */ 443
1920

2021
// run express
2122
const app = express()
@@ -26,18 +27,19 @@ app.use(compression())
2627
app.set("json spaces", 0)
2728

2829
// redirect http to https
29-
/* istanbul ignore else */ // useless to test
30-
if (port === 443)
30+
/* istanbul ignore else: useless to test */
31+
if (port === 443 || process.env.HTTP_PORT)
3132
app.http = http.createServer((req, res) => {
3233
res.writeHead(301, { Location: "https://" + req.headers["host"] + req.url })
3334
res.end()
34-
}).listen(80)
35+
}).listen(process.env.HTTP_PORT ||
36+
/* istanbul ignore next: impossible to test */ 80)
3537

3638
// serve static files, if launched as: "node index.js <static-path>"
37-
/* istanbul ignore else */ // useless to test
39+
/* istanbul ignore else: useless to test */
3840
if (require.main === module || process.env.USE_STATIC) {
3941
let staticPath = process.cwd()
40-
/* istanbul ignore if */ // impossible to test
42+
/* istanbul ignore if: impossible to test */
4143
if (process.argv.join().includes("serve"))
4244
staticPath = process.argv.join().replace("sudo", "")
4345
.replace("serve", "").replace(" ", "")

test/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
process.env.USE_STATIC = true
2+
process.env.PORT = 4443
3+
process.env.HTTP_PORT = 8080
24

35
const assert = require("assert")
46
const fs = require("fs")
@@ -16,7 +18,7 @@ function makeRequest(path = "/", secure = false) {
1618
}
1719
const options = {
1820
host: "localhost",
19-
port: 80,
21+
port: process.env.HTTP_PORT || 80,
2022
path: path,
2123
method: "GET",
2224
headers: { }

0 commit comments

Comments
 (0)