-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge test changes to main - v0.41.0-pre.ca23c2e (#128)
Automatically created pull-request in order to merge changes that were recently pushed to the test branch, back to main
- Loading branch information
Showing
14 changed files
with
1,396 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ inputs: | |
required: false | ||
description: npm|yarn | ||
default: "yarn" | ||
run_tests: | ||
required: false | ||
description: true|false | ||
default: "false" | ||
|
||
runs: | ||
using: "composite" | ||
|
@@ -148,3 +152,53 @@ runs: | |
github-token: ${{ env.GH_TOKEN }} | ||
review-message: "Please take a look :eyes:" | ||
tags: "TODO:,FIXME:,BUG:" | ||
|
||
- name: vitest | ||
if: ${{ env.run_tests == 'true' }} | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} | ||
run: yarn coverage | ||
|
||
- name: Test reporter | ||
uses: dorny/test-reporter@v1 | ||
id: test-reporter | ||
if: ${{ env.run_tests == 'true' }} | ||
with: | ||
name: "Frontend Tests" | ||
working-directory: ${{ inputs.working_directory }} | ||
path: "coverage/junit-report.xml" | ||
reporter: jest-junit | ||
fail-on-error: false | ||
|
||
- name: Code Coverage Report | ||
uses: irongut/[email protected] | ||
if: ${{ env.run_tests == 'true' }} | ||
with: | ||
filename: "src/frontend/coverage/cobertura-coverage.xml" | ||
badge: true | ||
fail_below_min: false | ||
format: markdown | ||
hide_branch_rate: false | ||
hide_complexity: true | ||
indicators: true | ||
output: both | ||
thresholds: "60 80" | ||
|
||
- name: Create output variable | ||
id: code-coverage-summary | ||
shell: bash | ||
working-directory: ${{ inputs.working_directory }} | ||
if: ${{ env.run_tests == 'true' }} | ||
run: | | ||
cat ../../code-coverage-results.md >> $GITHUB_STEP_SUMMARY | ||
echo "markdown<<EOF" >> $GITHUB_OUTPUT | ||
cat ../../code-coverage-results.md >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
- name: "Create or Update PR Comment" | ||
uses: im-open/[email protected] | ||
if: ${{ env.run_tests == 'true' && always() && github.event_name == 'pull_request' }} | ||
with: | ||
github-token: ${{ env.GH_TOKEN }} | ||
comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-CodeCoverageSummary" | ||
comment-content: ${{ steps.code-coverage-summary.outputs.markdown }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ jobs: | |
contents: read | ||
pull-requests: write | ||
steps: | ||
- uses: toshimaru/[email protected].0 | ||
- uses: toshimaru/[email protected].1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["vitest.explorer", "ryanluker.vscode-coverage-gutters"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
/* TODO: can be used to mock the API during development | ||
import { setupWorker } from 'msw/browser' | ||
import { getWeatherForecastMock } from './api/endpoints/weather-forecast/weather-forecast.msw' | ||
import { getBloggingMock } from '~/api/endpoints/blogging/blogging.msw' | ||
import { getSendMessageMock } from '~/api/endpoints/send-message/send-message.msw' | ||
import { getServiceMock } from '~/api/endpoints/service/service.msw' | ||
import { getWeatherForecastMock } from '~/api/endpoints/weather-forecast/weather-forecast.msw' | ||
const worker = setupWorker(...getWeatherForecastMock()) | ||
const worker = setupWorker( | ||
...getBloggingMock(), | ||
...getSendMessageMock(), | ||
...getServiceMock(), | ||
...getWeatherForecastMock(), | ||
) | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
worker.start() | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect, it } from 'vitest' | ||
|
||
import { render, screen } from '~/test/testUtils' | ||
|
||
import Page from '../+Page' | ||
|
||
it('renders welcome message', () => { | ||
render(<Page />, { mockAuthContext: true, withQueryProvider: true }) | ||
expect(screen.getByText('Vite + React')).toBeInTheDocument() | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type matchers from '@testing-library/jest-dom/matchers' | ||
|
||
import '@testing-library/jest-dom/vitest' | ||
import { cleanup } from '@testing-library/react' | ||
import { setupServer } from 'msw/node' | ||
import { afterAll, afterEach, beforeAll } from 'vitest' | ||
|
||
import { getBloggingMock } from '~/api/endpoints/blogging/blogging.msw' | ||
import { getSendMessageMock } from '~/api/endpoints/send-message/send-message.msw' | ||
import { getServiceMock } from '~/api/endpoints/service/service.msw' | ||
import { getWeatherForecastMock } from '~/api/endpoints/weather-forecast/weather-forecast.msw' | ||
|
||
const server = setupServer( | ||
...getBloggingMock(), | ||
...getSendMessageMock(), | ||
...getServiceMock(), | ||
...getWeatherForecastMock(), | ||
) | ||
|
||
// Start server before all tests | ||
beforeAll(() => { | ||
server.listen({ onUnhandledRequest: 'error' }) | ||
}) | ||
|
||
// Close server after all tests | ||
afterAll(() => { | ||
server.close() | ||
}) | ||
|
||
// Reset handlers after each test `important for test isolation` | ||
afterEach(() => { | ||
cleanup() | ||
server.resetHandlers() | ||
}) | ||
|
||
declare module 'vitest' { | ||
interface Assertion<T = any> extends jest.Matchers<void, T>, matchers.TestingLibraryMatchers<T, void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { type RenderOptions, render } from '@testing-library/react' | ||
import { vi } from 'vitest' | ||
|
||
interface IExtendedRenderOptions extends RenderOptions { | ||
//withRouter?: boolean | ||
//routerHistory?: string[] | ||
//withRedux?: boolean | ||
//mockAxiosCalls?: any | ||
mockAuthContext?: boolean | null | ||
//mockInitialState?: any | ||
withQueryProvider?: boolean | null | ||
} | ||
|
||
const createTestQueryClient = (): QueryClient => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
// logger: { | ||
// error: () => {}, | ||
// log: console.log, | ||
// warn: console.warn, | ||
// }, | ||
}) | ||
|
||
const wrapInQueryProvider = (componentTree: React.JSX.Element): React.JSX.Element => { | ||
const testQueryClient = createTestQueryClient() | ||
return <QueryClientProvider client={testQueryClient}>{componentTree}</QueryClientProvider> | ||
} | ||
|
||
const setupComponent = (ui: React.JSX.Element, renderOptions?: IExtendedRenderOptions): React.JSX.Element => { | ||
if (renderOptions == null) return ui | ||
let componentTree = <>{ui}</> | ||
//if (renderOptions.withRouter) componentTree = wrapInRouter(componentTree, renderOptions.routerHistory); | ||
//if (renderOptions.withRedux) componentTree = wrapInRedux(componentTree, renderOptions); | ||
if (renderOptions.withQueryProvider !== false) componentTree = wrapInQueryProvider(componentTree) | ||
if (renderOptions?.mockAuthContext !== false) { | ||
// TODO: also remove it afterAll | ||
vi.mock('~/auth.context', () => ({ | ||
useAuthDispatch: () => { | ||
return vi.fn() | ||
}, | ||
})) | ||
} | ||
return componentTree | ||
} | ||
|
||
const customRender = (ui: React.JSX.Element, renderOptions?: IExtendedRenderOptions): ReturnType<typeof render> => { | ||
try { | ||
// mockAxiosCallResponsesIfAny(renderOptions) | ||
const componentTree = setupComponent(ui, renderOptions) | ||
return render(componentTree) | ||
} catch (error) { | ||
console.log(error) | ||
// eslint-disable-next-line @typescript-eslint/only-throw-error | ||
throw error | ||
} | ||
} | ||
|
||
// eslint-disable-next-line import/export | ||
export * from '@testing-library/react' | ||
//export { default as userEvent } from '@testing-library/user-event' | ||
// override render export | ||
export { type IExtendedRenderOptions, customRender as render } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.