Add async-safe polyfills, Jest custom config, and improved token validation
- Introduced Web Crypto API polyfills (`@peculiar/webcrypto`) for Node.js to enable SSR-safe cryptography utilities. - Added Jest setup file for global mocks (e.g., `localStorage`, `sessionStorage`, and `TextEncoder/Decoder`). - Enhanced token validation behavior in `storage` tests to reject incomplete tokens. - Replaced runtime configuration validation with clamping using `parseIntSafe` constraints for improved reliability. - Updated `package.json` and `package-lock.json` to include new dependencies (`@peculiar/webcrypto` and related libraries).
This commit is contained in:
@@ -89,8 +89,8 @@ describe('Storage Module', () => {
|
||||
|
||||
const result = await getTokens();
|
||||
|
||||
// Should still return the object (validation is minimal)
|
||||
expect(result).toEqual({ accessToken: 'only_access' });
|
||||
// Should reject incomplete tokens and return null
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,7 +133,8 @@ describe('Storage Module', () => {
|
||||
refreshToken: 'test.refresh.token',
|
||||
};
|
||||
|
||||
await expect(saveTokens(tokens)).rejects.toThrow('Token storage failed');
|
||||
// When setItem throws, isLocalStorageAvailable() returns false
|
||||
await expect(saveTokens(tokens)).rejects.toThrow('localStorage not available - cannot save tokens');
|
||||
|
||||
Storage.prototype.setItem = originalSetItem;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user