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

Only save test data for tests run with Replay browser #586

Merged
merged 3 commits into from
Jul 3, 2024
Merged

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jul 2, 2024

Only upload test metadata for tests that were run with the Replay browser. If a given test run has no tests that match this criteria, then we should not even upload any metadata for it.

Testing

I've tested the following scenarios...

Upload behavior

Only upload tests run with Replay browser
// playwright.config.js
reporter: [
  ["dot"] as const,
  replayReporter({
    apiKey: process.env.REPLAY_API_KEY,
    upload: true,
  })
],
projects: [
  {
    name: "chromium",
    testMatch: "**/*login-logout-devtools.spec.ts",
    use: { ...devices["Desktop Chrome"] },
  },
  {
    testMatch: "**/*login-logout-library.spec.ts",
    use: { ...replayDevices["Replay Chromium"] },
  },
],

I was testing a few things with this configuration:

  • We do upload recordings but only for tests that were run by the Replay browser
  • We don't even upload metadata for tests that were run with other browsers

Here is the terminal output from the above test run:

[replay.io]: 🕑 Completing some outstanding work ...
[replay.io]: 
[replay.io]: 🚀 Successfully uploaded 1 recordings:
[replay.io]: 
[replay.io]:    ✅ login-logout-library: should login and logout from the library
[replay.io]:       https://app.replay.io/recording/8dc7d529-d7ff-4a0d-8cb4-7177b21b33df

And here are the results in our dashboard which seem to confirm that it worked as expected:
image

Upload all tests if all are run with Replay browser
// playwright.config.js
reporter: [
  ["dot"] as const,
  replayReporter({
    apiKey: process.env.REPLAY_API_KEY,
    upload: true,
  })
],
projects: [
  {
    name: "chromium",
    use: { ...devices["Desktop Chrome"] },
  },
  {
    name: "replay-chromium",
    use: { ...replayDevices["Replay Chromium"] },
  },
],

Terminal output:

····
  4 passed (13.7s)

[replay.io]: 🕑 Completing some outstanding work ...
[replay.io]: 
[replay.io]: 🚀 Successfully uploaded 2 recordings:
[replay.io]: 
[replay.io]:    ✅ login-logout-devtools: should login and logout from devtools
[replay.io]:       https://app.replay.io/recording/2fb6449f-c078-48f5-bd08-19cff3dabe6a
[replay.io]:
[replay.io]:    ✅ login-logout-library: should login and logout from the library
[replay.io]:       https://app.replay.io/recording/deef79df-d011-4b52-a917-662dab981adf

Dashboard has both tests (with recordings)
image

Don't upload any data if no tests are run with Replay

Same config but with --project=chromium so the Replay browser doesn't get run:

··
  2 passed (11.3s)
[replay.io]: None of the configured projects ran using Replay Chromium.
[replay.io]:
[replay.io]: Learn more at https://docs.replay.io/reference/test-runners/playwright/overview

And does not create a dashboard test run.

Logged warnings

Trying to record tests without the Replay browser being installed
  2 failed
    [replay-chromium] › login-logout-devtools.spec.ts:5:5 › login-logout-devtools: should login and logout from devtools 
    [replay-chromium] › login-logout-library.spec.ts:5:5 › login-logout-library: should login and logout from the library 
[replay.io]: 🕑 Completing some outstanding work ...
[replay.io]: To record tests with Replay, you need to install the Replay browser: npx replayio install
[replay.io]:
[replay.io]: Learn more at https://docs.replay.io/reference/test-runners/playwright/overview
Using the Replay reporter without the Replay browser installed or configured
··
  2 passed (10.6s)
[replay.io]: None of the configured projects ran using Replay Chromium.
[replay.io]:
[replay.io]: To record tests with Replay, you need to install the Replay browser: npx replayio install
[replay.io]:
[replay.io]: Learn more at https://docs.replay.io/reference/test-runners/playwright/overview

@bvaughn bvaughn requested a review from Andarist July 2, 2024 18:19
Copy link

changeset-bot bot commented Jul 2, 2024

🦋 Changeset detected

Latest commit: d52c6a5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@replayio/playwright Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

replay-io bot commented Jul 2, 2024

Status Complete ↗︎
Commit c4bf984
Results
2 Failed
  • clicks a disappearing button
  • should fail on this test
  • 42 Passed
  • adds items
  • adds new items using a custom command
  • adds todos following the fixture
  • adds todos following the fixture
  • adds todos following the fixture
  • adds todos following the fixture
  • calls inform
  • complete all checkbox should update state when items are completed / cleared
  • gets a number
  • only gets a number
  • only gets a number
  • should allow me to add todo items
  • should allow me to clear the complete state of all items
  • should allow me to display active items
  • should allow me to display all items
  • should allow me to display completed items
  • should allow me to edit an item
  • should allow me to mark all items as completed
  • should allow me to mark items as complete
  • should allow me to un-mark items as complete
  • should append new items to the bottom of the list
  • should be hidden when there are no items that are completed
  • should cancel edits on escape
  • should clear text input field when an item is added
  • should display the correct text
  • should display the current number of todo items
  • should focus on the todo input field
  • should hide #main and #footer
  • should hide other controls when editing
  • should highlight the currently applied filter
  • should intercept postman
  • should invoke some commands that have exceptional option handling
  • should log
  • should persist its data
  • should remove completed items when clicked
  • should remove the item if an empty text string was entered
  • should respect the back button
  • should save edits on blur
  • should show #main and #footer when items added
  • should trim entered text
  • should trim text input
  • yields a number
  • Comment on lines -1233 to +1244
    output.push(`\n🚀 Successfully uploaded ${uploads.length} recordings:\n`);
    output.push(`\n🚀 Successfully uploaded ${uploads.length} recordings:`);
    const sortedUploads = sortRecordingsByResult(uploads);
    sortedUploads.forEach(r => {
    output.push(
    ` ${getTestResultEmoji(r)} ${(r.metadata.title as string | undefined) || "Unknown"}`
    `\n ${getTestResultEmoji(r)} ${(r.metadata.title as string | undefined) || "Unknown"}`
    );
    output.push(
    ` ${process.env.REPLAY_VIEW_HOST || "https://app.replay.io"}/recording/${r.id}\n`
    ` ${process.env.REPLAY_VIEW_HOST || "https://app.replay.io"}/recording/${r.id}`
    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    This was leaving a goofy trailing line too, after the last test.

    this._projects[projectName].executed = true;
    }
    // Don't save metadata for non-Replay projects
    if (projectMetadata?.usesReplayBrowser === false) return;
    Copy link
    Member

    Choose a reason for hiding this comment

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

    It's unclear to me when it can happen but, in theory (aka according to the types), the project is optional.... In such a scenario the tested value resolves to undefined here and based on that code will continue to process this. I wonder if that's intentional behavior or not

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    It was also unclear to me about when this could happen. (How would Playwright even know which browser to use if there was no project?)

    I just did some local testing and realized that I can comment out the projects config block entirely and Playwright still works:

    export default defineConfig({
      testDir: "./tests",
      fullyParallel: true,
      forbidOnly: !!process.env.CI,
      retries: 0,
      reporter: [
        ["dot"] as const,
        replayReporter({
          apiKey: process.env.REPLAY_API_KEY,
          upload: true,
        }),
      ],
      timeout: 10_000,
      use: {
        viewport: {
          width: 1280,
          height: 1024,
        },
      },
    });

    Adding some logging to the reporter I see that we still get a project back in this case though:

    {
      grep: /.*/,
      grepInvert: null,
      outputDir: '/Users/bvaughn/Documents/git/replay/library/test-results',
      repeatEach: 1,
      retries: 0,
      metadata: {},
      name: '',
      testDir: '/Users/bvaughn/Documents/git/replay/library/tests',
      snapshotDir: '/Users/bvaughn/Documents/git/replay/library/tests',
      testIgnore: [],
      testMatch: '**/*.@(spec|test).?(c|m)[jt]s?(x)',
      timeout: 10000,
      use: { viewport: { width: 1280, height: 1024 } },
      dependencies: [],
      teardown: undefined,
      __projectId: ''
    }

    So the logic I have here would still hold. That being said, maybe it's safer to switch back to my original approach:

    if (!projectMetadata?.usesReplayBrowser) return;

    @bvaughn bvaughn merged commit 2d78191 into main Jul 3, 2024
    7 checks passed
    @bvaughn bvaughn deleted the PRO-654 branch July 3, 2024 11:44
    @github-actions github-actions bot mentioned this pull request Jul 3, 2024
    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.

    2 participants