11import request from 'supertest' ;
2- import { beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
2+ import { afterAll , beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
33import { Application } from 'express' ;
44
55import { createApp } from '../../../src/app' ;
@@ -44,9 +44,13 @@ beforeEach(() => {
4444 } ) ;
4545} ) ;
4646
47+ afterAll ( ( ) => {
48+ vi . unstubAllEnvs ( ) ;
49+ } ) ;
50+
4751describe ( 'JWKS - Development Mode' , ( ) => {
4852 it ( 'returns dev jwks' , async ( ) => {
49- process . env . NODE_ENV = 'development' ;
53+ vi . stubEnv ( ' NODE_ENV' , 'development' ) ;
5054
5155 const { readFileSync } = await import ( 'fs' ) ;
5256 const { importSPKI, exportJWK } = await import ( 'jose' ) ;
@@ -70,7 +74,7 @@ describe('JWKS - Development Mode', () => {
7074
7175describe ( 'JWKS - Production Mode' , ( ) => {
7276 it ( 'returns jwks from secrets' , async ( ) => {
73- process . env . NODE_ENV = 'production' ;
77+ vi . stubEnv ( ' NODE_ENV' , 'production' ) ;
7478
7579 const { importSPKI, exportJWK } = await import ( 'jose' ) ;
7680
@@ -103,7 +107,7 @@ describe('JWKS - Production Mode', () => {
103107
104108describe ( 'JWKS - Error Handling' , ( ) => {
105109 it ( 'returns 500 when secrets fail' , async ( ) => {
106- process . env . NODE_ENV = 'production' ;
110+ vi . stubEnv ( ' NODE_ENV' , 'production' ) ;
107111
108112 ( getSecret as any ) . mockRejectedValue ( new Error ( 'boom' ) ) ;
109113
@@ -116,7 +120,7 @@ describe('JWKS - Error Handling', () => {
116120
117121describe ( 'JWKS - Caching' , ( ) => {
118122 it ( 'uses cached jwks on second call' , async ( ) => {
119- process . env . NODE_ENV = 'production' ;
123+ vi . stubEnv ( ' NODE_ENV' , 'production' ) ;
120124
121125 const { importSPKI, exportJWK } = await import ( 'jose' ) ;
122126
0 commit comments