@@ -18,35 +18,26 @@ import {EventEmitter} from 'events';
1818
1919import { hapi_17 } from '../../src/plugins/types' ;
2020
21- import {
22- WebFramework ,
23- WebFrameworkAddHandlerOptions ,
24- WebFrameworkHandlerFunction ,
25- WebFrameworkResponse ,
26- } from './base' ;
21+ import { WebFramework , WebFrameworkAddHandlerOptions } from './base' ;
2722
2823const TAIL_WORK = Symbol ( 'tail work for hapi' ) ;
2924
3025interface AppState {
3126 [ TAIL_WORK ] ?: Array < Promise < void > > ;
3227}
3328
34- export class Hapi17 extends EventEmitter implements WebFramework {
35- static commonName = `hapi@17` ;
36- static expectedTopStackFrame = '_executeWrap' ;
37- static versionRange = '>=7.5' ;
38-
39- private server : hapi_17 . Server ;
29+ class Hapi extends EventEmitter implements WebFramework {
30+ server : hapi_17 . Server ;
4031 // We can't add two routes on the same path.
4132 // So instead of registering a new Hapi plugin per path,
4233 // register only the first time -- passing a function that will iterate
4334 // through a list of routes keyed under the path.
44- private routes = new Map < string , WebFrameworkAddHandlerOptions [ ] > ( ) ;
45- private registering = Promise . resolve ( ) ;
35+ routes = new Map < string , WebFrameworkAddHandlerOptions [ ] > ( ) ;
36+ registering = Promise . resolve ( ) ;
4637
47- constructor ( ) {
38+ constructor ( path : string ) {
4839 super ( ) ;
49- const hapi = require ( '../plugins/fixtures/hapi17' ) as typeof hapi_17 ;
40+ const hapi = require ( path ) as typeof hapi_17 ;
5041 this . server = new hapi . Server ( ) ;
5142 this . server . events . on ( 'response' , ( request : hapi_17 . Request ) => {
5243 Promise . all ( ( request . app as AppState ) [ TAIL_WORK ] || [ ] ) . then (
@@ -116,3 +107,19 @@ export class Hapi17 extends EventEmitter implements WebFramework {
116107 this . server . stop ( ) ;
117108 }
118109}
110+
111+ const makeHapiClass = ( version : number ) =>
112+ class extends Hapi {
113+ static commonName = `hapi@${ version } ` ;
114+ static expectedTopStackFrame = '_executeWrap' ;
115+ static versionRange = '>=7.5' ;
116+
117+ constructor ( ) {
118+ super ( `../plugins/fixtures/hapi${ version } ` ) ;
119+ }
120+ } ;
121+
122+ // tslint:disable:variable-name (Hapi* are class names)
123+ export const Hapi17 = makeHapiClass ( 17 ) ;
124+ export const Hapi18 = makeHapiClass ( 18 ) ;
125+ // tslint:enable:variable-name
0 commit comments