Skip to content

Commit 1e75d77

Browse files
committed
Skip installation of certificates if them already esists.
1 parent e6c91c3 commit 1e75d77

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

cert/generate.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ function mkcert(path, exe) {
5454
}
5555

5656
async function main() {
57+
console.info("Generating certificates...")
58+
const path = "cert" + /* istanbul ignore next: cannot be tested */
59+
(process.platform === "win32" ? "\\" : "/")
60+
// Check if files already exists
61+
if (fs.existsSync(path + "localhost.crt") &&
62+
/* istanbul ignore next: not relevant */
63+
fs.existsSync(path + "localhost.key")) {
64+
console.info("Certificates already exists. Skip.")
65+
return
66+
}
5767
const url = "https://github.com/FiloSottile/mkcert/releases/download/" +
5868
MKCERT_VERSION + "/"
5969
const exe = getExe()
60-
const path = "cert" + /* istanbul ignore next: cannot be tested */
61-
(process.platform === "win32" ? "\\" : "/")
6270
// download the executable
6371
await download(url + exe, path + exe)
6472
// make binary executable

test/test.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,28 @@ function makeRequest(path = "/", secure = true, port = HTTPS_PORT) {
3434
})
3535
}
3636

37-
// TESTS
37+
// TESTS INSTALL
38+
describe("Testing the installation script", function() {
39+
// timeout 5 min
40+
this.timeout(300000)
41+
42+
// remove a file, this will force the reinstallation
43+
fs.unlinkSync("cert/localhost.crt")
44+
45+
it("installs correctly", async function() {
46+
await require("../cert/generate.js")()
47+
assert(fs.existsSync("cert/localhost.crt"))
48+
assert(fs.existsSync("cert/localhost.key"))
49+
})
50+
51+
it("skips installation if files exists", async function() {
52+
await require("../cert/generate.js")()
53+
assert(fs.existsSync("cert/localhost.crt"))
54+
assert(fs.existsSync("cert/localhost.key"))
55+
})
56+
})
57+
58+
// TESTS MODULE
3859
describe("Testing https-localhost", () => {
3960
// close the server after each test
4061
afterEach(() => app.server.close())
@@ -120,15 +141,3 @@ describe("Testing https-localhost", () => {
120141
.then(res => assert(res.headers["content-encoding"] === "gzip"))
121142
})
122143
})
123-
124-
// TESTS
125-
describe("Testing the installation script", function() {
126-
// timeout 5 min
127-
this.timeout(300000)
128-
129-
it("installs correctly", async function() {
130-
await require("../cert/generate.js")()
131-
assert(fs.existsSync("cert/localhost.crt"))
132-
assert(fs.existsSync("cert/localhost.key"))
133-
})
134-
})

0 commit comments

Comments
 (0)