test fixes to support Jest 29
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -15,3 +15,7 @@
|
||||
*/
|
||||
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
Object.defineProperty(global, 'TextDecoder', {
|
||||
value: require('util').TextDecoder,
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ jest.mock('@google-cloud/firestore', () => ({
|
||||
Firestore: jest.fn().mockImplementation(() => firestoreMock),
|
||||
}));
|
||||
|
||||
jest.useFakeTimers('legacy');
|
||||
jest.useFakeTimers({ legacyFakeTimers: true });
|
||||
|
||||
describe('FirestoreKeyStore', () => {
|
||||
const key = {
|
||||
|
||||
@@ -18,7 +18,7 @@ import { getDurationFromDates } from './getDurationFromDates';
|
||||
|
||||
describe('getDurationFromDates', () => {
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers('modern');
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(new Date('2021-10-15T09:45:25.0000000Z'));
|
||||
});
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ describe('GitlabDiscoveryProcessor', () => {
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers('modern');
|
||||
jest.useFakeTimers();
|
||||
jest.setSystemTime(new Date(SERVER_TIME));
|
||||
});
|
||||
|
||||
|
||||
-1
@@ -87,7 +87,6 @@ describe('<PreparePullRequestForm />', () => {
|
||||
<TextField
|
||||
{...asInputRef(register('main', { required: true }))}
|
||||
name="main"
|
||||
required
|
||||
/>
|
||||
{formState.errors.main && (
|
||||
<FormHelperText error>
|
||||
|
||||
+15
-5
@@ -46,6 +46,10 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
url: 'mycluster.privatelink.westeurope.azmk8s.io',
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should decorate cluster with Azure token', async () => {
|
||||
const authTranslator = new AzureIdentityKubernetesAuthTranslator(
|
||||
logger,
|
||||
@@ -70,6 +74,8 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
});
|
||||
|
||||
it('should issue new token 15 minutes befory expiry', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const authTranslator = new AzureIdentityKubernetesAuthTranslator(
|
||||
logger,
|
||||
new StaticTokenCredential(16 * 60 * 1000), // token expires in 16min
|
||||
@@ -78,13 +84,15 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
const response = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response.serviceAccountToken).toEqual('MY_TOKEN_1');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2mins
|
||||
jest.setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2mins
|
||||
|
||||
const response2 = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response2.serviceAccountToken).toEqual('MY_TOKEN_2');
|
||||
});
|
||||
|
||||
it('should re-use existing token if there is afailure', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const authTranslator = new AzureIdentityKubernetesAuthTranslator(
|
||||
logger,
|
||||
new StaticTokenCredential(16 * 60 * 1000), // new tokens expires in 16min
|
||||
@@ -93,12 +101,12 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
const response = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response.serviceAccountToken).toEqual('MY_TOKEN_1');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
jest.setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
|
||||
const response2 = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response2.serviceAccountToken).toEqual('MY_TOKEN_2');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
jest.setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
|
||||
const response3 = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response3.serviceAccountToken).toEqual('MY_TOKEN_2');
|
||||
@@ -108,6 +116,8 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
});
|
||||
|
||||
it('should throw if existing token expired and failed to fetch a new one', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const authTranslator = new AzureIdentityKubernetesAuthTranslator(
|
||||
logger,
|
||||
new StaticTokenCredential(16 * 60 * 1000), // new tokens expires in 16min
|
||||
@@ -116,12 +126,12 @@ describe('AzureIdentityKubernetesAuthTranslator tests', () => {
|
||||
const response = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response.serviceAccountToken).toEqual('MY_TOKEN_1');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
jest.setSystemTime(Date.now() + 2 * 60 * 1000); // advance time by 2min
|
||||
|
||||
const response2 = await authTranslator.decorateClusterDetailsWithAuth(cd);
|
||||
expect(response2.serviceAccountToken).toEqual('MY_TOKEN_2');
|
||||
|
||||
jest.useFakeTimers().setSystemTime(Date.now() + 17 * 60 * 1000); // advance time by 17min
|
||||
jest.setSystemTime(Date.now() + 17 * 60 * 1000); // advance time by 17min
|
||||
|
||||
await expect(
|
||||
authTranslator.decorateClusterDetailsWithAuth(cd),
|
||||
|
||||
@@ -124,8 +124,8 @@ describe('RadarComponent', () => {
|
||||
);
|
||||
}).toThrow();
|
||||
}).error[0],
|
||||
).toMatch(
|
||||
/^Error: Uncaught \[Error: No implementation available for apiRef{core.error}\]/,
|
||||
);
|
||||
).toMatchObject({
|
||||
detail: new Error('No implementation available for apiRef{core.error}'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user