Skip to content
Snippets Groups Projects
Unverified Commit 29b78ee6 authored by Guilherme Gazzo's avatar Guilherme Gazzo Committed by GitHub
Browse files

ci: Report Jest coverage (#29848)

parent b31a880a
No related merge requests found
...@@ -31,3 +31,8 @@ jobs: ...@@ -31,3 +31,8 @@ jobs:
- name: Unit Test - name: Unit Test
run: yarn testunit run: yarn testunit
- uses: codecov/codecov-action@v3
with:
flags: unit
verbose: true
...@@ -38,5 +38,9 @@ module.exports = { ...@@ -38,5 +38,9 @@ module.exports = {
'tests/unit/lib/**/*.tests.ts', 'tests/unit/lib/**/*.tests.ts',
'tests/unit/client/**/*.test.ts', 'tests/unit/client/**/*.test.ts',
], ],
exclude: ['client/hooks/*.spec.{ts,tsx}', 'client/sidebar/header/actions/hooks/*.spec.{ts,tsx}'], exclude: [
'client/hooks/*.spec.{ts,tsx}',
'client/sidebar/header/actions/hooks/*.spec.{ts,tsx}',
'client/components/message/content/reactions/**.spec.{ts,tsx}',
],
}; };
import { MockedAuthorizationContext } from '@rocket.chat/mock-providers/src/MockedAuthorizationContext';
import { MockedServerContext } from '@rocket.chat/mock-providers/src/MockedServerContext';
import { MockedSettingsContext } from '@rocket.chat/mock-providers/src/MockedSettingsContext';
import { MockedUserContext } from '@rocket.chat/mock-providers/src/MockedUserContext';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
import { renderHook, act } from '@testing-library/react-hooks';
import React from 'react';
import { useToggleReactionMutation } from './useToggleReactionMutation';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
// ✅ turns retries off
retry: false,
},
},
logger: {
log: (..._) => {
// Log debugging information
},
warn: (..._) => {
// Log warning
},
error: (..._) => {
// Log error
},
},
});
beforeEach(() => {
queryClient.clear();
});
it('should be call rest `POST /v1/chat.react` method', async () => {
const fn = jest.fn();
const { result, waitFor } = renderHook(() => useToggleReactionMutation(), {
wrapper: ({ children }) => (
<QueryClientProvider client={queryClient}>
<MockedServerContext
handleRequest={({ method, pathPattern, params }) => {
if (method === 'POST' && pathPattern === '/v1/chat.react') {
fn(params);
return { success: true } as any;
}
throw new Error(`Endpoint not mocked: ${method} ${pathPattern}`);
}}
>
<MockedSettingsContext settings={{}}>
<MockedUserContext userPreferences={{}}>
<MockedAuthorizationContext permissions={[]}>{children}</MockedAuthorizationContext>
</MockedUserContext>
</MockedSettingsContext>
</MockedServerContext>
</QueryClientProvider>
),
});
act(async () => {
await result.current.mutateAsync({ mid: 'MID', reaction: 'smile' });
});
await waitFor(() => result.current.isLoading === false);
expect(fn).toHaveBeenCalledWith({
messageId: 'MID',
reaction: 'smile',
});
});
it('should not work for non-logged in users', async () => {
const fn = jest.fn();
const { result, waitForValueToChange } = renderHook(() => useToggleReactionMutation(), {
wrapper: ({ children }) => (
<QueryClientProvider client={queryClient}>
<MockedServerContext
handleRequest={({ method, pathPattern, params }) => {
if (method === 'POST' && pathPattern === '/v1/chat.react') {
fn(params);
return { success: true } as any;
}
throw new Error(`Endpoint not mocked: ${method} ${pathPattern}`);
}}
>
<MockedSettingsContext settings={{}}>
<MockedAuthorizationContext permissions={[]}>{children}</MockedAuthorizationContext>
</MockedSettingsContext>
</MockedServerContext>
</QueryClientProvider>
),
});
act(() => {
return result.current.mutate({ mid: 'MID', reaction: 'smile' });
});
await waitForValueToChange(() => result.current.status);
expect(fn).not.toHaveBeenCalled();
expect(result.current.status).toBe('error');
expect(result.current.error).toEqual(new Error('Not logged in'));
});
...@@ -6,6 +6,7 @@ export default { ...@@ -6,6 +6,7 @@ export default {
testMatch: [ testMatch: [
'<rootDir>/client/hooks/**.spec.[jt]s?(x)', '<rootDir>/client/hooks/**.spec.[jt]s?(x)',
'<rootDir>/client/components/**.spec.[jt]s?(x)', '<rootDir>/client/components/**.spec.[jt]s?(x)',
'<rootDir>client/components/message/content/reactions/**.spec.[jt]s?(x)',
'<rootDir>/client/sidebar/header/actions/hooks/**/**.spec.[jt]s?(x)', '<rootDir>/client/sidebar/header/actions/hooks/**/**.spec.[jt]s?(x)',
], ],
transform: { transform: {
...@@ -15,4 +16,5 @@ export default { ...@@ -15,4 +16,5 @@ export default {
'\\.css$': 'identity-obj-proxy', '\\.css$': 'identity-obj-proxy',
'^react($|/.+)': '<rootDir>/node_modules/react$1', '^react($|/.+)': '<rootDir>/node_modules/react$1',
}, },
collectCoverage: true,
}; };
...@@ -5,5 +5,15 @@ coverage: ...@@ -5,5 +5,15 @@ coverage:
default: default:
target: auto target: auto
threshold: 1% threshold: 1%
client:
target: auto
flags:
- client
flags:
client:
paths:
- apps/meteor/client
carryforward: true
comment: comment:
layout: 'reach, diff, flags' layout: 'reach, diff, flags'
...@@ -10,4 +10,5 @@ export default { ...@@ -10,4 +10,5 @@ export default {
moduleNameMapper: { moduleNameMapper: {
'\\.css$': 'identity-obj-proxy', '\\.css$': 'identity-obj-proxy',
}, },
collectCoverage: true,
}; };
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
}, },
"testunit": { "testunit": {
"dependsOn": ["build"], "dependsOn": ["build"],
"outputs": [] "outputs": ["coverage/**"]
}, },
"lint": { "lint": {
"dependsOn": ["build"], "dependsOn": ["build"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment