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

[Test Utils] [Recorder] Migrate to esm #28667

Merged

Conversation

HarshaNalluru
Copy link
Member

@HarshaNalluru HarshaNalluru commented Feb 27, 2024

Packages impacted by this PR

@azure-tools/test-recorder

Issues associated with this PR

#28475

Describe the problem that is addressed by this PR

Migrates @azure-tools/test-recorder to ESM, supports both vitest and mocha.

What's in the PR

This PR also pulls in @jeremymeng's change to update recorder file path calculation that got reverted #28423

One major non-breaking change to env

This involves bumping recorder to 4.0.0, a new major due to the nature of the change.
process.env is employed in both node and browser vitest with playwright.

  • removes dotenv dependency
  • env shims for browser
  • deletes karma.conf
                       Exported "env" in 3.1.0                             Exported "env" in 4.0.0
node                    Process.env	                                    Process.env
browser                 Window.__env__	                                    --No shim--

Depends on #28917

Exposed sanitizer types

  • Enhanced the addSanitizers method and SanitizerOptions options bag by exposing the following sanitizer types for more flexible usage:

    • FindReplaceSanitizer: A sanitizer that finds and replaces specified strings.
    • RegexSanitizer: A sanitizer that uses regular expressions for pattern matching and replacement.
    • StringSanitizer: A sanitizer that handles string-based sanitization tasks.
    • HeaderSanitizer: A sanitizer specifically designed for handling HTTP headers.
    • ConnectionStringSanitizer: A sanitizer that securely handles connection strings.
    • RemoveHeaderSanitizer: A sanitizer that removes specified headers from HTTP requests or responses.

    This update aims to provide users with a more comprehensive and customizable sanitization process.

Breaking Changes

  • The @azure-tools/test-recorder@4.0.0 package now supports vitest and playwright (stops support for mocha and karma), employs process.env in both Node and browser environments. This aligns with the latest testing frameworks and provides improved testing capabilities.

    • The package has been simplified by removing the dotenv dependency and the karma.conf file, env shims for the browser. This streamlines the package dependencies and configuration files, respectively.
    • These changes introduce a new env strategy for all SDKs once they migrate to ESM and depend on @azure-tools/test-recorder version 4, as we employ process.env through vitest to access environment variables in both Node and browser environments.
  • @azure-tools/test-credential@2.0.0 is introduced and will now consume @azure-tools/test-recorder@4.0.0 with the new env strategy.

HarshaNalluru and others added 23 commits September 22, 2023 18:34
Currently we just need suite title and test title to generate recording
file names. `vitest` provides the info via `context` of the callback
function.

This PR adds vitest support to recorder. Call site would look like

```ts
   //...
  beforeEach(async (context) => {
    recorder = new Recorder(context);
```
@HarshaNalluru HarshaNalluru changed the title [Test Utils] Migrate to esm [Test Utils][Recorder] Migrate to esm Feb 28, 2024
@HarshaNalluru HarshaNalluru changed the title [Test Utils][Recorder] Migrate to esm [Test Utils] [Recorder] Migrate to esm Feb 28, 2024
@mpodwysocki mpodwysocki self-requested a review March 29, 2024 15:55
Copy link
Contributor

@mpodwysocki mpodwysocki left a comment

Choose a reason for hiding this comment

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

Made some minor changes, but looks good. You will need to resolve the conflicts and run rush update with the dependency changes I've made.

@HarshaNalluru HarshaNalluru enabled auto-merge (squash) March 31, 2024 05:56
HarshaNalluru added a commit that referenced this pull request Apr 1, 2024
Listed types in package.json and files included for publishing were not
in sync.
`"types": "types/tools-test-credential.d.ts"` vs `"types/latest/src"`

Needed to unblock #28667
@HarshaNalluru HarshaNalluru merged commit 7f1f103 into Azure:main Apr 1, 2024
24 checks passed
@HarshaNalluru HarshaNalluru deleted the harshan/migrate-to-esm/test-utils branch April 1, 2024 20:39
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.

5 participants