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

Browser SDK Integration Tests #3989

Merged
merged 34 commits into from
Dec 14, 2021
Merged

Conversation

onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Sep 19, 2021

Rel: #3841

This PR includes the initial structure of new integration tests for Sentry's Browser SDK.

New integration tests internally use Playwright and run on recent versions of Chromium, Webkit and Firefox linked with the Playwright release.

This new test structure aims to create a modern and intuitive environment to test @sentry/browser and potentially other browser-side SDKs like @sentry/react and @sentry/vue.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2021

size-limit report

Path Base Size (626102f) Current Size Change
@sentry/browser - CDN Bundle (gzipped) 22.45 KB 22.44 KB -0.02% 🔽
@sentry/browser - Webpack 23.29 KB 23.29 KB +0.01% 🔺
@sentry/browser - Webpack - gzip = false 82.73 KB 82.62 KB -0.14% 🔽
@sentry/react - Webpack 23.32 KB 23.32 KB 0%
@sentry/nextjs Client - Webpack 48.07 KB 48.03 KB -0.09% 🔽
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 29.98 KB 29.96 KB -0.07% 🔽

@onurtemizkan onurtemizkan changed the title [WIP] - test(browser): Simple PoC for end-to-end browser tests using Playwright. [WIP] - Playwright E2E Tests. Sep 19, 2021
@onurtemizkan onurtemizkan force-pushed the onur/playwright-browser-tests branch 4 times, most recently from 3abadea to 50e1b56 Compare September 20, 2021 10:59
@onurtemizkan onurtemizkan marked this pull request as ready for review September 22, 2021 13:08
@onurtemizkan onurtemizkan force-pushed the onur/playwright-browser-tests branch 3 times, most recently from 3aaaf76 to c28ceac Compare November 9, 2021 08:57
@AbhiPrasad AbhiPrasad requested review from AbhiPrasad and removed request for kamilogorek November 12, 2021 15:49
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

nice, yeah I think the test setup is good.

packages/browser/test/e2e/server.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/test/breadcrumbs.test.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/test/breadcrumbs.test.js Outdated Show resolved Hide resolved
expect(eventData.message).toBe('test');
expect(eventData.breadcrumbs.length).toBe(1);
expect(eventData.breadcrumbs[0].category).toBe('xhr');
expect(eventData.breadcrumbs[0].type).toBe('http');
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it'll be effective to us to pseudo snapshot test the event instead of these deep assertions.

So we can skip attributes that we know will change, but compare the rest of the event to a json file.

We do something similar in electron:

An event JSON: https://github.com/getsentry/sentry-electron/blob/master/test/e2e/test-apps/javascript/main-error/event.json

and how it's normalized: https://github.com/getsentry/sentry-electron/blob/master/test/e2e/recipe/normalize.ts#L49

We can also try this out after this gets merged in, no rush

packages/browser/test/e2e/server.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/playwright.config.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/test/builtins.test.js Outdated Show resolved Hide resolved
.github/workflows/build.yml Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
packages/browser/package.json Outdated Show resolved Hide resolved
packages/browser/test/e2e/test/config.test.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/test/utils/helpers.js Outdated Show resolved Hide resolved
packages/browser/test/e2e/package.json Outdated Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
@onurtemizkan onurtemizkan force-pushed the onur/playwright-browser-tests branch 3 times, most recently from 195f6e2 to 0a47492 Compare November 23, 2021 12:00
@onurtemizkan onurtemizkan force-pushed the onur/playwright-browser-tests branch 3 times, most recently from 1dcd4e0 to 0e2a049 Compare November 24, 2021 22:59
@onurtemizkan onurtemizkan changed the title [WIP] - Playwright E2E Tests. Browser SDK Integration Tests Nov 30, 2021
@onurtemizkan
Copy link
Collaborator Author

@AbhiPrasad, added a manual about the basic usage and common issues. Will need to be extended further after merging the rest of the tests. The PR is ready to be reviewed again.

Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

Thanks @onurtemizkan! I did a pass at this, trying to help us flush this out.

Most comments are small things we can improve or honest questions to help me understand better and also document decisions for our future selves working with and maintaining the code.

My biggest concern for now is around the ability to run individual tests in a single browser in a local development environment.

And then, next, we can strategize how the migration from old tests to new is going to take place as I can see we all need to be careful to not introduce unintended changes (I've seen some unexpected differences and commented).

packages/browser/test/e2e/README.md Outdated Show resolved Hide resolved
packages/browser/test/e2e/README.md Outdated Show resolved Hide resolved
packages/browser/test/e2e/package.json Outdated Show resolved Hide resolved
packages/browser/test/e2e/package.json Outdated Show resolved Hide resolved
packages/browser/test/e2e/package.json Outdated Show resolved Hide resolved
"main": "index.js",
"license": "MIT",
"engines": {
"node": ">=12"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any advantage in saying >=12 instead of >=16 here? We're configuring the GHA workflow to run on Node 16.x, I don't think we need to declare compatibility with anything else. Thoughts?

packages/browser/test/e2e/utils/helpers.ts Outdated Show resolved Hide resolved
@onurtemizkan
Copy link
Collaborator Author

@rhcarvalho, the summary of the latest updates is below;

  • subject.js is not required / nor the pivot point anymore. We're using test.ts instead, for discovery and building tests.
  • The improved test is now sentryTest.
  • page builds are now made before each test, as another extension of sentryTest, (minimal effect on performance now, we'll see better after porting all remaining tests.)
  • Now we can run individual tests locally on individual browsers. Have access to options in Playwright CLI.
  • Node >=16 is required now, did not integrate volta though, maybe when we make it a lerna package?
  • Could not rename the e2e folder to integration now, it depends on when we delete the old tests.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

One last set of things, and then I think we are good to go!

packages/eslint-config-sdk/src/index.js Show resolved Hide resolved
@@ -0,0 +1,31 @@
{
"name": "sentry-browser-integration-tests",
Copy link
Member

Choose a reason for hiding this comment

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

Can we call the folder name browser-integration-tests then?

packages/integration-tests/package.json Outdated Show resolved Hide resolved
"html-webpack-plugin": "^5.5.0",
"playwright": "^1.17.1",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
Copy link
Member

Choose a reason for hiding this comment

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

We need to stick with 3.7.5 to match with the rest of the codebase. Can we remove this?

Suggested change
"typescript": "^4.5.2",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@AbhiPrasad, @playwright/test uses export type syntax for its types (and we're importing them). It's not a problem while running tests, but addressing #3989 (comment), to run a type check without compiling before tests, we need a newer version of TS. We also no longer need ts-loader as init and subject scripts are not TS. So the only use of TS here will be static type checking. So is that fine to keep this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For ref: c3d35b6

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked with @AbhiPrasad, and we agreed we can address this later in a follow up.

packages/integration-tests/utils/fixtures.ts Outdated Show resolved Hide resolved
packages/integration-tests/utils/generatePage.ts Outdated Show resolved Hide resolved
packages/integration-tests/utils/browserHelpers.ts Outdated Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
packages/integration-tests/utils/browserHelpers.ts Outdated Show resolved Hide resolved
Comment on lines 19 to 20
// This has a big impact on test build speed.
transpileOnly: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this option documented in https://webpack.js.org/guides/build-performance/#typescript-loader

I could not find where we're actually doing the type-checking?

Copy link
Collaborator Author

@onurtemizkan onurtemizkan Dec 14, 2021

Choose a reason for hiding this comment

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

Added a non-compiled type checking script and removed ts-loader from webpack which we don't need anymore. -> c3d35b6

But we need a higher version of TS for this. -> #3989 (comment)

@rhcarvalho
Copy link
Contributor

For our later reference, the last Playwright tests took 1m6s, of which 59s was downloading browsers/system dependencies (and as per #3989 (comment) I think we can get rid of this step and save time).

image

packages/integration-tests/package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@rhcarvalho
Copy link
Contributor

Ok, we got now the test failure in 3 browsers as expected:

https://github.com/getsentry/sentry-javascript/runs/4520662297?check_suite_focus=true

image

However, tests are not running in Webkit due to missing system level dependencies -- we need to apply a fix similar to https://github.com/getsentry/sentry-javascript/pull/4232/files#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721R304

image

@rhcarvalho rhcarvalho dismissed AbhiPrasad’s stale review December 14, 2021 14:02

All feedback has been addressed or will be addressed in a follow up

@rhcarvalho rhcarvalho enabled auto-merge (squash) December 14, 2021 14:07
@rhcarvalho
Copy link
Contributor

Now we have all browsers testing and failing as expected https://github.com/getsentry/sentry-javascript/runs/4521042164?check_suite_focus=true.

Tests flipped to green in 84f529b and we should get it merged as soon as the new run turn green.

Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

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

Thanks @onurtemizkan! Looking forward to what we build on top of this ❤️

@rhcarvalho rhcarvalho merged commit 28dae68 into master Dec 14, 2021
@rhcarvalho rhcarvalho deleted the onur/playwright-browser-tests branch December 14, 2021 14:25
@onurtemizkan
Copy link
Collaborator Author

Thanks everyone for the reviews! ❤️ 🚀

onurtemizkan added a commit that referenced this pull request Dec 19, 2021
Initial structure of new integration tests for Sentry's Browser SDK.

New integration tests internally use Playwright and run on recent
versions of Chromium, Webkit and Firefox linked with the Playwright
release.

This new test structure aims to create a modern and intuitive
environment to test @sentry/browser and potentially other browser-side
SDKs like @sentry/react and @sentry/vue.

Co-authored-by: Rodolfo Carvalho <rodolfo.carvalho@sentry.io>
Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants