Skip to content

Commit 9667a0b

Browse files
committed
fix: working on jwks test
1 parent e265978 commit 9667a0b

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

tests/integration/jwks/jwks.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import request from 'supertest';
2-
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
33
import { Application } from 'express';
44

55
import { createApp } from '../../../src/app';
@@ -44,9 +44,13 @@ beforeEach(() => {
4444
});
4545
});
4646

47+
afterAll(() => {
48+
vi.unstubAllEnvs();
49+
});
50+
4751
describe('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

7175
describe('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

104108
describe('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

117121
describe('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

Comments
 (0)