Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9ac07dd
starter code - handle browser recordings
HarshaNalluru Apr 20, 2021
c508d34
changelog
HarshaNalluru Apr 20, 2021
f56a3be
Update matchRequest with applyRequestBodyTransformations
HarshaNalluru Apr 20, 2021
acdb7bb
update test
HarshaNalluru Apr 20, 2021
60b2d93
Update sdk/test-utils/recorder/src/utils/requestBodyTransform.ts
HarshaNalluru Apr 20, 2021
05d2284
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru Apr 20, 2021
ce1f236
Merge branch 'harshan/recorder/filter-scope' of https://github.com/Ha…
HarshaNalluru Apr 21, 2021
43bc9a2
fix regexes and minor bugs
HarshaNalluru Apr 21, 2021
19dbec8
fix test titles and removed .only
HarshaNalluru Apr 21, 2021
478c7f4
remove requestBodyTransformations on the exports as it isn't well sup…
HarshaNalluru Apr 21, 2021
2332a82
InternalRecorderEnvironmentSetup with requestBodyTransformations
HarshaNalluru Apr 21, 2021
a139974
recording
HarshaNalluru Apr 21, 2021
fe26243
reasoning
HarshaNalluru Apr 21, 2021
901e574
applyRequestBodyTransformationsOnFixture
HarshaNalluru Apr 21, 2021
ff8dd0b
changelog
HarshaNalluru Apr 21, 2021
80794b7
minor bug fix
HarshaNalluru Apr 21, 2021
81b58cb
record a test from text-analytics
HarshaNalluru Apr 21, 2021
c6842ca
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru Apr 21, 2021
8a8e2a7
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru Apr 23, 2021
09af90c
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru Apr 23, 2021
fffdb55
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru May 12, 2021
8fc6629
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru May 12, 2021
051aeed
convert to Record<string, unknown>
HarshaNalluru May 12, 2021
dc46c22
rush update --recheck
HarshaNalluru May 12, 2021
822ac74
Required<RequestBodyTransformsType>
HarshaNalluru May 12, 2021
854ce6d
retain older changelog
HarshaNalluru May 12, 2021
07baf37
set the date
HarshaNalluru May 12, 2021
c9d66fd
Update sdk/test-utils/recorder/CHANGELOG.md
HarshaNalluru May 12, 2021
0f14c68
lock file
HarshaNalluru May 19, 2021
fedce31
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru May 22, 2021
0bdcad2
revert recording
HarshaNalluru May 22, 2021
1af5db3
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru May 25, 2021
b3b00dd
lock file
HarshaNalluru May 25, 2021
5c1b872
sanitizeScopeUrl
HarshaNalluru May 25, 2021
4d8fe5a
fix the regex
HarshaNalluru May 25, 2021
e002369
regenerate and playback - works
HarshaNalluru May 25, 2021
f627108
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
HarshaNalluru May 25, 2021
1c80a0f
rush update
HarshaNalluru May 25, 2021
bbffc88
changelog
HarshaNalluru May 25, 2021
f52eb97
tests for browser recordings
HarshaNalluru May 25, 2021
b4a22d7
tests for defaultCustomizationsOnRecordings
HarshaNalluru May 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions sdk/test-utils/recorder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

## 1.0.0 (Unreleased)

## 2021-04-20

- Extended the `requestBodyTransformations` from [#14897](https://github.com/Azure/azure-sdk-for-js/pull/14897) to handle browser tests as well.
- Adds a default transformation to strip out the scope in the request body with the string "https://sanitized/"
- Removed `requestBodyTransformations` property from `RecorderEnvironmentSetup` since Nock doesn't support multiple `.filteringRequestBody` patches in the recordings.

## 2021-04-19

- Helper method added for the transformations to be applied on the requestBody in record mode to be able to filter the requests in playback.
Extends the `RecorderEnvironmentSetup` with `requestBodyTransformations` property which takes the transformation callbacks to be applied on the request body.
[#14897](https://github.com/Azure/azure-sdk-for-js/pull/14897)
- Adds a default transformation to strip out the client-request-id in the request body with the string "client-request-body"

## 2021-04-07

Expand Down
32 changes: 22 additions & 10 deletions sdk/test-utils/recorder/src/baseRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ import {
filterSecretsRecursivelyFromJSON,
generateTestRecordingFilePath
} from "./utils";
import { defaultRequestBodyTransforms } from "./utils/requestBodyTransform";
import {
defaultRequestBodyTransforms,
RequestBodyTransformsType
} from "./utils/requestBodyTransform";

type InternalRecorderEnvironmentSetup = RecorderEnvironmentSetup & {
/**
* Used in record and playback modes
*
* Array of callback functions provided to customize the request body
* - Record mode: These callbacks will be applied on the request body before the recording is saved
* - Playback mode: These callbacks will be applied on the request body of the new requests
*
* // Nock doesn't support multiple `.filteringRequestBody` patches in the recordings,
* // ..hence not exporting `requestBodyTransformations` to the users until we find an alternative
* // TODO: Best alternative would be to migrate to JSON recordings for node tests
*/
requestBodyTransformations: Required<RequestBodyTransformsType>;
};
/**
* Loads the environment variables in both node and browser modes corresponding to the key-value pairs provided.
*
Expand All @@ -32,7 +49,7 @@ export abstract class BaseRecorder {
// Example - node/some_random_test_suite/recording_first_test.js
protected readonly relativeTestRecordingFilePath: string;
public uniqueTestInfo: TestInfo = { uniqueName: {}, newDate: {} };
public environmentSetup: RecorderEnvironmentSetup = {
public environmentSetup: InternalRecorderEnvironmentSetup = {
replaceableVariables: {},
customizationsOnRecordings: [],
queryParametersToSkip: [],
Expand Down Expand Up @@ -103,14 +120,9 @@ export abstract class BaseRecorder {
...environmentSetup.queryParametersToSkip
],
requestBodyTransformations: {
stringTransforms:
this.environmentSetup.requestBodyTransformations?.stringTransforms?.concat(
environmentSetup.requestBodyTransformations?.stringTransforms ?? []
) ?? [],
jsonTransforms:
this.environmentSetup.requestBodyTransformations?.jsonTransforms?.concat(
environmentSetup.requestBodyTransformations?.jsonTransforms ?? []
) ?? []
// TODO: Concat with the requestBodyTransformations once exposed
stringTransforms: this.environmentSetup.requestBodyTransformations?.stringTransforms,
jsonTransforms: this.environmentSetup.requestBodyTransformations?.jsonTransforms
}
};
}
Expand Down
30 changes: 28 additions & 2 deletions sdk/test-utils/recorder/src/createRecorder.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
isPlaybackMode
} from "./utils";
import { customConsoleLog } from "./customConsoleLog";
import {
applyRequestBodyTransformations,
applyRequestBodyTransformationsOnFixture
} from "./utils/requestBodyTransform";

// To better understand how this class works, it's necessary to comprehend how HTTP async requests are made:
// A new request object is created
Expand All @@ -29,7 +33,7 @@ import { customConsoleLog } from "./customConsoleLog";
// Nise module does not have a native implementation of record/playback like Nock does
// This class overrides requests' 'open', 'send' and 'onreadystatechange' functions, adding our own code to them to deal with requests
export class NiseRecorder extends BaseRecorder {
private recordings: any[] = [];
private recordings: { [key: string]: unknown }[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

nit: Record<string, unknown>?

private recordingInFlight: Promise<void>[] = [];
private xhr: nise.FakeXMLHttpRequestStatic | undefined;

Expand Down Expand Up @@ -92,7 +96,21 @@ export class NiseRecorder extends BaseRecorder {
return (
recording.method === request.method &&
recording.url === request.url &&
recording.requestBody === request.requestBody
// For backward compatibility, calling `applyRequestBodyTransformations` on
// - the request-body in the recording
// and
// - the request-body of the new request
//
// Once all the browser recordings are regenerated, L.H.S can be updated to `recording.requestBody`
// since the `applyRequestBodyTransformations` would have been applied before saving the recording
applyRequestBodyTransformations(
recording.requestBody,
this.environmentSetup.requestBodyTransformations
) ===
applyRequestBodyTransformations(
request.requestBody,
this.environmentSetup.requestBodyTransformations
)
);
}

Expand Down Expand Up @@ -225,6 +243,14 @@ export class NiseRecorder extends BaseRecorder {
// recordings at this point are in the JSON format.
this.recordings = this.filterSecrets(this.recordings);

this.recordings = this.recordings.map((singleRecording) =>
applyRequestBodyTransformationsOnFixture(
"browser",
singleRecording,
this.environmentSetup.requestBodyTransformations
)
);

// We're sending the recordings to the 'karma-json-to-file-reporter' via console.log
console.log(
JSON.stringify({
Expand Down
4 changes: 2 additions & 2 deletions sdk/test-utils/recorder/src/createRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { nodeRequireRecordingIfExists } from "./utils/recordings";

import { config as readEnvFile } from "dotenv";
import fs from "fs-extra";
import { applyRequestBodyTransformations } from "./utils/requestBodyTransform";
import { applyRequestBodyTransformationsOnFixture } from "./utils/requestBodyTransform";

let nock: typeof import("nock");

Expand Down Expand Up @@ -85,7 +85,7 @@ export class NockRecorder extends BaseRecorder {
for (const fixture of fixtures) {
let updatedFixture = fixture;
// Applying any requestBody transformations that are provided
updatedFixture = applyRequestBodyTransformations(
updatedFixture = applyRequestBodyTransformationsOnFixture(
"node",
fixture,
this.environmentSetup.requestBodyTransformations
Expand Down
9 changes: 0 additions & 9 deletions sdk/test-utils/recorder/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

import { URLBuilder } from "@azure/core-http";
import { RequestBodyTransformsType } from "./requestBodyTransform";

export { testHasChanged } from "./recordings";

Expand Down Expand Up @@ -46,14 +45,6 @@ export interface RecorderEnvironmentSetup {
* @memberof RecorderEnvironmentSetup
*/
customizationsOnRecordings: Array<(content: string) => string>;
/**
* Used in record and playback modes
*
* Array of callback functions provided to customize the request body
* - Record mode: These callbacks will be applied on the request body before the recording is saved
* - Playback mode: These callbacks will be applied on the request body of the new requests
*/
requestBodyTransformations?: RequestBodyTransformsType;
/**
* Used in record and playback modes
*
Expand Down
Loading