Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add codecov test analytics for playwright tests #13654

Merged
merged 4 commits into from
Sep 13, 2024

Conversation

AbhiPrasad
Copy link
Member

https://docs.codecov.com/docs/test-result-ingestion-beta

https://playwright.dev/docs/test-reporters

Adds codecov test analytics to the repo, specifically for our playwright tests.

This works by using the junit reporter with playwright, and then uploading that via the codecov/test-results-action@v1 GitHub Action.

@AbhiPrasad AbhiPrasad requested review from mydea, a team and Lms24 and removed request for a team September 10, 2024 15:05
@@ -610,6 +610,13 @@ jobs:
overwrite: true
retention-days: 7

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if: ${{ !cancelled() }}
if: cancelled() == false

I think that's enough here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the snippet from https://docs.codecov.com/docs/test-result-ingestion-beta#2-add-the-script-codecovtest-results-actionv1-to-your-ci-yaml-file

but I think you're right, this feels more correct to me. Will switch!

@AbhiPrasad
Copy link
Member Author

Looks like it works! https://app.codecov.io/gh/getsentry/sentry-javascript/tests/abhi-playwright-codecov-test-analytics (make sure you're logged in)

@AbhiPrasad AbhiPrasad added the ci-codecov-ai-review AI Review by Codecov label Sep 10, 2024
Copy link

@codecov codecov bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code contains Git diff changes which primarily aim at integrating codecov test results actions in GitHub Workflows, and modifying test reporters for CI. The changes are well implemented, but are redundant and hard-coded, which might raise maintenance issues in the future. Moreover, the usage of tokens can be risky and should be carefully verified.

uses: codecov/test-results-action@v1
with:
directory: dev-packages/browser-integration-tests
token: ${{ secrets.CODECOV_TOKEN }}
Copy link

@codecov codecov bot Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code creates a potential problem where if the Codecov token is not set, the action may fail without a clear error. Consider adding error handling to handle the situation when secrets.CODECOV_TOKEN is not available.

- name: Upload test results to Codecov
if: cancelled() == 'false'
uses: codecov/test-results-action@v1
with:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating the same actions in each workflow can be both inefficient and error-prone. Consider creating a reusable workflow to maintain this action in a single place.

@@ -35,7 +35,7 @@ const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

@codecov codecov bot Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same note for the CI environment variable applies here and for all other similar changes.

@@ -35,7 +35,7 @@ const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same reporter switching logic is repeated. You should factor out this piece of code into a reusable function or a separate configuration file.

@@ -23,7 +23,7 @@ const config = {
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar repetition of the reporter assignment based on environment variable 'CI'. This should be refactored into a utility function.

@@ -37,7 +37,7 @@ export function getPlaywrightConfig(
/* In dev mode some apps are flaky, so we allow retry there... */
retries: testEnv === 'development' ? 3 : 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'line' : 'list',
reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, similar repetition of the reporter assignment based on environment variable 'CI' as in line 129. Please consider creating a dedicated function or configurating module for this logic.

@@ -106,7 +106,7 @@
"test:integration:prepare": "(cd test/integration && yarn install)",
"test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)",
"test:integration:client": "yarn playwright install-deps && yarn playwright test test/integration/test/client/ --project='chromium'",
"test:integration:client:ci": "yarn test:integration:client --reporter='line'",
"test:integration:client:ci": "yarn test:integration:client",
Copy link

@codecov codecov bot Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the reporter from the test script has been noted. This is now handled by the test configuration file.

@@ -8,6 +8,7 @@ const config: PlaywrightTestConfig = {
},
// Run tests inside of a single file in parallel
fullyParallel: true,
reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

@codecov codecov bot Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of 'junit' reporter for CI environment is a good addition. It will allow tests to generate JUnit style XML files, which can be used by various CI tools for detailed test reports.

Copy link
Contributor

github-actions bot commented Sep 10, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.52 KB - -
@sentry/browser - with treeshaking flags 21.3 KB - -
@sentry/browser (incl. Tracing) 34.79 KB - -
@sentry/browser (incl. Tracing, Replay) 71.25 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.69 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 75.59 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.32 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.16 KB - -
@sentry/browser (incl. metrics) 26.83 KB - -
@sentry/browser (incl. Feedback) 39.6 KB - -
@sentry/browser (incl. sendFeedback) 27.19 KB - -
@sentry/browser (incl. FeedbackAsync) 31.9 KB - -
@sentry/react 25.28 KB - -
@sentry/react (incl. Tracing) 37.75 KB - -
@sentry/vue 26.72 KB - -
@sentry/vue (incl. Tracing) 36.66 KB - -
@sentry/svelte 22.66 KB - -
CDN Bundle 23.77 KB - -
CDN Bundle (incl. Tracing) 36.49 KB - -
CDN Bundle (incl. Tracing, Replay) 70.95 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.26 KB - -
CDN Bundle - uncompressed 69.65 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.23 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.01 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.21 KB - -
@sentry/nextjs (client) 37.51 KB - -
@sentry/sveltekit (client) 35.36 KB - -
@sentry/node 120.5 KB -0.01% -1 B 🔽
@sentry/node - without tracing 92.78 KB - -
@sentry/aws-serverless 102.49 KB - -

View base workflow run

Copy link

@codecov codecov bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodecovAI submitted a new review for b4228b8

@@ -35,7 +35,7 @@
"test:loader:replay_buffer": "PW_BUNDLE=loader_replay_buffer yarn test:loader",
"test:loader:full": "PW_BUNDLE=loader_tracing_replay yarn test:loader",
"test:loader:debug": "PW_BUNDLE=loader_debug yarn test:loader",
"test:ci": "yarn test:all --reporter='line'",
"test:ci": "yarn test:all",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from specifying the reporter in the test script to be handled by the test configuration file has been noted. Please ensure the 'line' reporter is the intended default for local testing.

@@ -30,6 +30,8 @@ const config: PlaywrightTestConfig = {
},
],

reporter: process.env.CI ? [['line'], ['junit', { outputFile: 'results.junit.xml' }]] : 'list',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the CI environment variable is not set, this will default to 'list' reporter. Is this the intended behavior? If not, consider adding a default reporter.

Copy link

codecov bot commented Sep 13, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
396 1 395 17
View the top 1 failed tests by shortest run time
tracing/metrics/handlers-lcp/test.ts should capture metrics for LCP instrumentation handlers
Stack Traces | 10.6s run time
test.ts:10:11 should capture metrics for LCP instrumentation handlers

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@AbhiPrasad AbhiPrasad merged commit f44785c into develop Sep 13, 2024
130 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-playwright-codecov-test-analytics branch September 13, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-codecov-ai-review AI Review by Codecov
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants