1
1
'use strict' ;
2
2
3
3
const path = require ( 'path' ) ;
4
+ const http2 = require ( 'http2' ) ;
4
5
const request = require ( 'supertest' ) ;
5
- const semver = require ( 'semver' ) ;
6
6
const testServer = require ( '../helpers/test-server' ) ;
7
7
const config = require ( '../fixtures/contentbase-config/webpack.config' ) ;
8
8
const port = require ( '../ports-map' ) [ 'http2-option' ] ;
@@ -16,60 +16,47 @@ describe('http2 option', () => {
16
16
let server ;
17
17
let req ;
18
18
19
- // HTTP/2 will only work with node versions below 10.0.0
20
- // since spdy is broken past that point, and this test will only
21
- // work above Node 8.8.0, since it is the first version where the
22
- // built-in http2 module is exposed without need for a flag
23
- // (https://nodejs.org/en/blog/release/v8.8.0/)
24
- // if someone is testing below this Node version and breaks this,
25
- // their tests will not catch it, but CI will catch it.
26
- if (
27
- semver . gte ( process . version , '8.8.0' ) &&
28
- semver . lt ( process . version , '10.0.0' )
29
- ) {
30
- const http2 = require ( 'http2' ) ;
31
- describe ( 'http2 works with https' , ( ) => {
32
- beforeAll ( ( done ) => {
33
- server = testServer . start (
34
- config ,
35
- {
36
- contentBase : contentBasePublic ,
37
- https : true ,
38
- http2 : true ,
39
- port,
40
- } ,
41
- done
42
- ) ;
43
- req = request ( server . app ) ;
44
- } ) ;
45
-
46
- it ( 'confirm http2 client can connect' , ( done ) => {
47
- const client = http2 . connect ( `https://localhost:${ port } ` , {
48
- rejectUnauthorized : false ,
49
- } ) ;
50
- client . on ( 'error' , ( err ) => console . error ( err ) ) ;
19
+ describe ( 'http2 works with https' , ( ) => {
20
+ beforeAll ( ( done ) => {
21
+ server = testServer . start (
22
+ config ,
23
+ {
24
+ contentBase : contentBasePublic ,
25
+ https : true ,
26
+ http2 : true ,
27
+ port,
28
+ } ,
29
+ done
30
+ ) ;
31
+ req = request ( server . app ) ;
32
+ } ) ;
51
33
52
- const http2Req = client . request ( { ':path' : '/' } ) ;
34
+ it ( 'confirm http2 client can connect' , ( done ) => {
35
+ const client = http2 . connect ( `https://localhost:${ port } ` , {
36
+ rejectUnauthorized : false ,
37
+ } ) ;
38
+ client . on ( 'error' , ( err ) => console . error ( err ) ) ;
53
39
54
- http2Req . on ( 'response' , ( headers ) => {
55
- expect ( headers [ ':status' ] ) . toEqual ( 200 ) ;
56
- } ) ;
40
+ const http2Req = client . request ( { ':path' : '/' } ) ;
57
41
58
- http2Req . setEncoding ( 'utf8' ) ;
59
- let data = '' ;
60
- http2Req . on ( 'data' , ( chunk ) => {
61
- data += chunk ;
62
- } ) ;
63
- http2Req . on ( 'end' , ( ) => {
64
- expect ( data ) . toEqual ( expect . stringMatching ( / H e y o / ) ) ;
65
- done ( ) ;
66
- } ) ;
67
- http2Req . end ( ) ;
42
+ http2Req . on ( 'response' , ( headers ) => {
43
+ expect ( headers [ ':status' ] ) . toEqual ( 200 ) ;
68
44
} ) ;
69
45
70
- afterAll ( testServer . close ) ;
46
+ http2Req . setEncoding ( 'utf8' ) ;
47
+ let data = '' ;
48
+ http2Req . on ( 'data' , ( chunk ) => {
49
+ data += chunk ;
50
+ } ) ;
51
+ http2Req . on ( 'end' , ( ) => {
52
+ expect ( data ) . toEqual ( expect . stringMatching ( / H e y o / ) ) ;
53
+ done ( ) ;
54
+ } ) ;
55
+ http2Req . end ( ) ;
71
56
} ) ;
72
- }
57
+
58
+ afterAll ( testServer . close ) ;
59
+ } ) ;
73
60
74
61
describe ( 'server works with http2 option, but without https option' , ( ) => {
75
62
beforeAll ( ( done ) => {
0 commit comments