test fixes to support Jest 29
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -27,7 +27,6 @@ const envOptions = {
|
||||
|
||||
const transformIgnorePattern = [
|
||||
'@material-ui',
|
||||
'@rjsf',
|
||||
'ajv',
|
||||
'core-js',
|
||||
'jest-.*',
|
||||
|
||||
@@ -118,9 +118,10 @@ describe('ApiProvider', () => {
|
||||
}).toThrow(/^API context is not available/);
|
||||
}).error,
|
||||
).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Error: Uncaught \[Error: API context is not available/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error('API context is not available'),
|
||||
type: 'unhandled exception',
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/^The above error occurred in the <MyHookConsumer> component/,
|
||||
),
|
||||
@@ -133,9 +134,10 @@ describe('ApiProvider', () => {
|
||||
}).toThrow(/^API context is not available/);
|
||||
}).error,
|
||||
).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Error: Uncaught \[Error: API context is not available/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error('API context is not available'),
|
||||
type: 'unhandled exception',
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/^The above error occurred in the <withApis\(Component\)> component/,
|
||||
),
|
||||
@@ -154,9 +156,10 @@ describe('ApiProvider', () => {
|
||||
}).toThrow('No implementation available for apiRef{x}');
|
||||
}).error,
|
||||
).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Error: Uncaught \[Error: No implementation available for apiRef{x}\]/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error('No implementation available for apiRef{x}'),
|
||||
type: 'unhandled exception',
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/^The above error occurred in the <MyHookConsumer> component/,
|
||||
),
|
||||
@@ -173,9 +176,10 @@ describe('ApiProvider', () => {
|
||||
}).toThrow('No implementation available for apiRef{x}');
|
||||
}).error,
|
||||
).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Error: Uncaught \[Error: No implementation available for apiRef{x}\]/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error('No implementation available for apiRef{x}'),
|
||||
type: 'unhandled exception',
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/^The above error occurred in the <withApis\(Component\)> component/,
|
||||
),
|
||||
|
||||
@@ -47,9 +47,11 @@ describe('TabbedLayout', () => {
|
||||
});
|
||||
|
||||
expect(error).toEqual([
|
||||
expect.stringMatching(
|
||||
/Child of TabbedLayout must be an TabbedLayout.Route/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error(
|
||||
'Child of TabbedLayout must be an TabbedLayout.Route',
|
||||
),
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/The above error occurred in the <TabbedLayout> component/,
|
||||
),
|
||||
|
||||
@@ -67,7 +67,9 @@ describe('<ErrorBoundary/>', () => {
|
||||
});
|
||||
|
||||
expect(error).toEqual([
|
||||
expect.stringMatching(/^Error: Uncaught \[Error: Bomb\]/),
|
||||
expect.objectContaining({
|
||||
detail: new Error('Bomb'),
|
||||
}),
|
||||
expect.stringMatching(
|
||||
/^The above error occurred in the <Bomb> component:/,
|
||||
),
|
||||
|
||||
@@ -29,7 +29,7 @@ const validBackstageToken =
|
||||
|
||||
describe('ProxiedSignInIdentity', () => {
|
||||
describe('tokenToExpiry', () => {
|
||||
beforeEach(() => jest.useFakeTimers('modern'));
|
||||
beforeEach(() => jest.useFakeTimers());
|
||||
afterEach(() => jest.useRealTimers());
|
||||
|
||||
it('handles undefined', async () => {
|
||||
@@ -56,7 +56,7 @@ describe('ProxiedSignInIdentity', () => {
|
||||
});
|
||||
|
||||
describe('ProxiedSignInIdentity', () => {
|
||||
beforeEach(() => jest.useFakeTimers('modern'));
|
||||
beforeEach(() => jest.useFakeTimers());
|
||||
afterEach(() => jest.useRealTimers());
|
||||
|
||||
const worker = setupServer();
|
||||
|
||||
@@ -117,7 +117,7 @@ describe('extensions', () => {
|
||||
render(<BrokenComponent />);
|
||||
});
|
||||
screen.getByText('Error in my-plugin');
|
||||
expect(errors[0]).toMatch('Test error');
|
||||
expect(errors[0]).toMatchObject({ detail: new Error('Test error') });
|
||||
});
|
||||
|
||||
it('should wrap extended component with analytics context', async () => {
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('isValidHost', () => {
|
||||
['[::]', true],
|
||||
['[::1]', true],
|
||||
['[1:2:3:4:5:6:7:8]', true],
|
||||
['1.2.3.4.5.6.7.8', true],
|
||||
['1.2.3.4.5.6.7.8', false],
|
||||
['https://example.com', false],
|
||||
['foo:100000', false],
|
||||
['FOO', false],
|
||||
|
||||
@@ -92,9 +92,11 @@ describe('wrapInTestApp', () => {
|
||||
});
|
||||
|
||||
expect(error).toEqual([
|
||||
expect.stringMatching(
|
||||
/^Error: Uncaught \[Error: MockErrorApi received unexpected error, Error: NOPE\]/,
|
||||
),
|
||||
expect.objectContaining({
|
||||
detail: new Error(
|
||||
'MockErrorApi received unexpected error, Error: NOPE',
|
||||
),
|
||||
}),
|
||||
expect.stringMatching(/^The above error occurred in the <A> component:/),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -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