Skip to content

Commit f2b8a73

Browse files
committed
Improved https testing
1 parent 1c98f19 commit f2b8a73

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
maxWorkers: 1,
33
collectCoverage: true,
4-
collectCoverageFrom: ['lib/*.js', 'lib/middleware/*.js']
4+
collectCoverageFrom: ['lib/*.js', 'lib/utils/*.js', 'lib/middleware/*.js']
55
}

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default class LiveServer {
5151
return this._openURL
5252
}
5353

54+
public get protocol() {
55+
return this._protocol
56+
}
57+
5458
public get isRunning() {
5559
return !!this.httpServer?.listening
5660
}

test/https.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ describe('https tests with external module', () => {
2020
afterEach(async () => {
2121
await liveServer.shutdown()
2222
})
23+
it('protocol should be https', function () {
24+
expect(liveServer.protocol).toBe('https')
25+
})
2326
it('should reply with a correct index file', function (done) {
2427
request(liveServer.httpServer)
2528
.get('/index.html')
@@ -48,6 +51,40 @@ describe('https tests with object', () => {
4851
afterEach(async () => {
4952
await liveServer.shutdown()
5053
})
54+
it('protocol should be https', function () {
55+
expect(liveServer.protocol).toBe('https')
56+
})
57+
it('should reply with a correct index file', function (done) {
58+
request(liveServer.httpServer)
59+
.get('/index.html')
60+
.expect('Content-Type', 'text/html; charset=UTF-8')
61+
.expect(/Hello world/i)
62+
.expect(200, done)
63+
})
64+
it('should support head request', function (done) {
65+
request(liveServer.httpServer)
66+
.head('/index.html')
67+
.expect('Content-Type', 'text/html; charset=UTF-8')
68+
.expect(200, done)
69+
})
70+
})
71+
72+
describe('https tests with the "selfsigned" package', () => {
73+
const opts = {
74+
root: path.join(__dirname, 'data'),
75+
port: 0,
76+
open: false,
77+
https: true
78+
}
79+
beforeEach(async () => {
80+
await liveServer.start(opts)
81+
})
82+
afterEach(async () => {
83+
await liveServer.shutdown()
84+
})
85+
it('protocol should be https', function () {
86+
expect(liveServer.protocol).toBe('https')
87+
})
5188
it('should reply with a correct index file', function (done) {
5289
request(liveServer.httpServer)
5390
.get('/index.html')

0 commit comments

Comments
 (0)