@@ -8,14 +8,31 @@ import {
88 LEGACY_HELLO_COMMAND ,
99 type MongoClient
1010} from '../../mongodb' ;
11+
12+ type EnvironmentVariables = Array < [ string , string ] > ;
13+
14+ function stubEnv ( env : EnvironmentVariables ) {
15+ let cachedEnv : NodeJS . ProcessEnv ;
16+ before ( function ( ) {
17+ cachedEnv = process . env ;
18+ process . env = {
19+ ...process . env ,
20+ ...Object . fromEntries ( env )
21+ } ;
22+ } ) ;
23+
24+ after ( function ( ) {
25+ process . env = cachedEnv ;
26+ } ) ;
27+ }
28+
1129describe ( 'Handshake Prose Tests' , function ( ) {
1230 let client : MongoClient ;
1331
1432 afterEach ( async function ( ) {
1533 await client ?. close ( ) ;
1634 } ) ;
1735
18- type EnvironmentVariables = Array < [ string , string ] > ;
1936 const tests : Array < {
2037 context : string ;
2138 expectedProvider : string | undefined ;
@@ -86,16 +103,7 @@ describe('Handshake Prose Tests', function () {
86103
87104 for ( const { context : name , env, expectedProvider } of tests ) {
88105 context ( name , function ( ) {
89- before ( ( ) => {
90- for ( const [ key , value ] of env ) {
91- process . env [ key ] = value ;
92- }
93- } ) ;
94- after ( ( ) => {
95- for ( const [ key ] of env ) {
96- delete process . env [ key ] ;
97- }
98- } ) ;
106+ stubEnv ( env ) ;
99107
100108 it ( `metadata confirmation test for ${ name } ` , function ( ) {
101109 expect ( getFAASEnv ( ) ?. get ( 'name' ) ) . to . equal (
@@ -117,22 +125,12 @@ describe('Handshake Prose Tests', function () {
117125 }
118126
119127 context ( 'Test 9: Valid container and FaaS provider' , function ( ) {
120- const env = [
128+ stubEnv ( [
121129 [ 'AWS_EXECUTION_ENV' , 'AWS_Lambda_java8' ] ,
122130 [ 'AWS_REGION' , 'us-east-2' ] ,
123131 [ 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' , '1024' ] ,
124132 [ 'KUBERNETES_SERVICE_HOST' , '1' ]
125- ] as EnvironmentVariables ;
126- before ( ( ) => {
127- for ( const [ key , value ] of env ) {
128- process . env [ key ] = value ;
129- }
130- } ) ;
131- after ( ( ) => {
132- for ( const [ key ] of env ) {
133- delete process . env [ key ] ;
134- }
135- } ) ;
133+ ] ) ;
136134
137135 it ( 'runs a hello successfully' , async function ( ) {
138136 client = this . configuration . newClient ( {
0 commit comments