Skip to content

Commit

Permalink
fix browser issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnickii committed Feb 21, 2025
1 parent 77834de commit baf5f23
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
29 changes: 29 additions & 0 deletions __mocks__/@azure/msal-browser
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export class PublicClientApplication {
constructor(configuration: any) {
// Mock constructor
}

initialize() {
// Mock initialize method
}

acquireTokenSilent() {
// Mock acquireTokenSilent method
return Promise.resolve({ accessToken: 'mock-access-token' });
}

acquireTokenPopup() {
// Mock acquireTokenPopup method
return Promise.resolve({ accessToken: 'mock-access-token' });
}

loginPopup() {
// Mock loginPopup method
return Promise.resolve({ account: { username: 'mock-user' } });
}

logout() {
// Mock logout method
return Promise.resolve();
}
}
14 changes: 14 additions & 0 deletions src/modules/authentication/msal-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ export const configuration: Configuration = {
if (containsPii) {
return;
}
switch (level) {
case LogLevel.Error:
console.error(message);
return;
case LogLevel.Info:
console.info(message);
return;
case LogLevel.Verbose:
console.debug(message);
return;
case LogLevel.Warning:
console.warn(message);
return;
}
},
piiLoggingEnabled: false
}
Expand Down
14 changes: 13 additions & 1 deletion src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { GlobalWithFetchMock } from 'jest-fetch-mock';
import 'jest-canvas-mock';
import crypto from 'crypto';

const customGlobal: GlobalWithFetchMock = global as unknown as GlobalWithFetchMock;
customGlobal.fetch = require('jest-fetch-mock'); // tslint:disable-line
customGlobal.fetchMock = customGlobal.fetch;
customGlobal.fetchMock = customGlobal.fetch;

Object.defineProperty(global, 'crypto', {
writable: true,
value: {
getRandomValues: (arr: Uint8Array) => crypto.getRandomValues(arr),
subtle: {}
}
});

// Mock MSAL
jest.mock('@azure/msal-browser');

0 comments on commit baf5f23

Please sign in to comment.