Skip to content

Commit a756936

Browse files
committed
Edit test to work with Travis
Cannot use port 80 on Travis, using 8080.
1 parent d460fbb commit a756936

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ app.set("json spaces", 0)
3535
/* SETUP USEFUL FUNCTIONS */
3636

3737
// redirect http to https, usage `app.redirect()`
38-
app.redirect = function() {
38+
app.redirect = function(port = 80) {
3939
app.http = http.createServer((req, res) => {
4040
res.writeHead(301, { Location: "https://" + req.headers["host"] + req.url })
4141
res.end()
42-
}).listen(80)
42+
}).listen(port)
4343
console.info("http to https redirection active.")
4444
}
4545

test/test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const PORT = 4443
1+
const HTTPS_PORT = 4443
2+
const HTTP_PORT = 8080
23

34
const assert = require("assert")
45
const fs = require("fs")
@@ -7,7 +8,7 @@ const https = require("https")
78
const app = require("../index.js")
89

910
// make an http request on the specified path
10-
function makeRequest(path = "/", secure = true, port = PORT) {
11+
function makeRequest(path = "/", secure = true, port = HTTPS_PORT) {
1112
const options = {
1213
host: "localhost",
1314
port: port,
@@ -35,23 +36,23 @@ function makeRequest(path = "/", secure = true, port = PORT) {
3536
describe("Testing https-localhost", () => {
3637
it("works as a module", async function() {
3738
app.get("/test/module", (req, res) => res.send("TEST"))
38-
await app.listen(PORT)
39+
await app.listen(HTTPS_PORT)
3940
await makeRequest("/test/module")
4041
.then(res => assert(res.data === "TEST"))
4142
await app.server.close()
4243
})
4344

4445
it("works as a module serving static files", async function() {
45-
app.serve("test", PORT)
46+
app.serve("test", HTTPS_PORT)
4647
await makeRequest("/static.html")
4748
.then(res => assert(
4849
res.data.toString() === fs.readFileSync("test/static.html").toString()))
4950
await app.server.close()
5051
})
5152

5253
it("redirect http to https", async function() {
53-
await app.redirect()
54-
await makeRequest("/", false, 80)
54+
await app.redirect(HTTP_PORT)
55+
await makeRequest("/", false, HTTP_PORT)
5556
.then(res => assert(res.statusCode === 301))
5657
})
5758
})

0 commit comments

Comments
 (0)