@@ -9,22 +9,27 @@ import { getLocal, generateCACertificate, Mockttp } from 'mockttp';
99
1010import { buildInterceptors , Interceptor } from '../../src/interceptors' ;
1111
12- const getCertificateDetails = _ . memoize ( ( configPath : string ) => {
12+ const getCertificateDetails = _ . memoize ( async ( configPath : string ) => {
1313 const keyPath = path . join ( configPath , 'ca.key' ) ;
1414 const certPath = path . join ( configPath , 'ca.pem' ) ;
1515
16- const newCertPair = generateCACertificate ( { commonName : 'HTTP Toolkit CA - DO NOT TRUST' } ) ;
16+ const newCertPair = await generateCACertificate ( { commonName : 'HTTP Toolkit CA - DO NOT TRUST' } ) ;
1717
1818 fs . writeFileSync ( keyPath , newCertPair . key ) ;
1919 fs . writeFileSync ( certPath , newCertPair . cert ) ;
2020
2121 return { certPath, keyPath } ;
2222} ) ;
2323
24- export function getInterceptorAndServer ( interceptor : string ) : { server : Mockttp , interceptor : Interceptor } {
24+ type InterceptorSetup = Promise < {
25+ server : Mockttp ,
26+ interceptor : Interceptor
27+ } >
28+
29+ export async function setupInterceptor ( interceptor : string ) : InterceptorSetup {
2530 const configPath = tmp . dirSync ( { unsafeCleanup : true } ) . name ;
2631
27- const { certPath, keyPath } = getCertificateDetails ( configPath ) ;
32+ const { certPath, keyPath } = await getCertificateDetails ( configPath ) ;
2833
2934 const server = getLocal ( { https : { certPath, keyPath } } ) ;
3035 const interceptors = buildInterceptors ( { configPath, https : { certPath, keyPath } } ) ;
@@ -34,14 +39,17 @@ export function getInterceptorAndServer(interceptor: string): { server: Mockttp,
3439
3540// Various tests that we'll want to reuse across interceptors:
3641
37- export function itIsAvailable ( interceptor : Interceptor ) {
42+ export function itIsAvailable ( interceptorSetup : InterceptorSetup ) {
3843 it ( 'is available' , async ( ) => {
44+ const { interceptor } = await interceptorSetup ;
3945 expect ( await interceptor . isActivable ( ) ) . to . equal ( true ) ;
4046 } ) ;
4147}
4248
43- export function itCanBeActivated ( interceptor : Interceptor , server : Mockttp ) {
49+ export function itCanBeActivated ( interceptorSetup : InterceptorSetup ) {
4450 it ( 'can be activated' , async ( ) => {
51+ const { interceptor, server } = await interceptorSetup ;
52+
4553 expect ( interceptor . isActive ( server . port ) ) . to . equal ( false ) ;
4654
4755 await interceptor . activate ( server . port ) ;
0 commit comments