-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Unified Recorder] TestProxyClient takes test context to generate rec…
…ordings at desired location (#17388) * TestProxyClient takes test context to generate recordings at desired location * set /workspaces/azure-sdk-for-js/ as entry point * use Test as testContext type * update recorder-new tests * update tests with before and after each * relativePathCalculator - for browser => done * create utils folder * export relativeRecordingsPathForBrowser to use in karma.conf * utils folder updates * RECORDINGS_RELATIVE_PATH env variable in karma.conf * node side draft * relativeRecordingsPathForNode * findRecordingsFolderPath * remove console.logs * Update sdk/test-utils/recorder-new/README.md * throw new Error( "Unable to determine the recording file path, testContext provided is not defined." ); * Update sdk/test-utils/recorder-new/README.md * lock file * --net=host docs * sample recordings * refactor existing tests * server and tests hitting the server * unrelated changes in package.json * changelog * lock file * Jeremy's feedbackl * lock file * lock file * Update sdk/test-utils/recorder-new/README.md Co-authored-by: Will Temple <witemple@microsoft.com> * Update sdk/test-utils/recorder-new/README.md Co-authored-by: Will Temple <witemple@microsoft.com> * readme * removing the exclamations. 🙂 * address feedback * clientHttpClient * sample recordings * relativeRecordingsPathForBrowser -> relativeRecordingsPath * massive update to relativeRecordingsPath - which works fine on linux * RECORDINGS_RELATIVE_PATH in karma.conf * dist-esm/test/index.spec.js doesn't exist * lock file * updates for windows * `--add-host host.docker.internal:host-gateway` * more comments * remove unintended file * Update sdk/test-utils/recorder-new/CHANGELOG.md Co-authored-by: Daniel Rodríguez <sadasant@users.noreply.github.com> * remove sq brackets Co-authored-by: Will Temple <witemple@microsoft.com> Co-authored-by: Daniel Rodríguez <sadasant@users.noreply.github.com>
- Loading branch information
1 parent
0e569b5
commit e099b12
Showing
25 changed files
with
1,497 additions
and
902 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Release History | ||
|
||
## 1.0.0 (Unreleased) | ||
|
||
## 2021-09-27 | ||
|
||
- `TestProxyClient` now takes the test context to determine the location of the recordings. [#17388](https://github.com/Azure/azure-sdk-for-js/pull/17388) | ||
- Adds a server for the tests, to play the role of an actual service to be able to test the proxy-tool end-to-end. | ||
[#17388](https://github.com/Azure/azure-sdk-for-js/pull/17388) | ||
|
||
## 2021-07-17 | ||
|
||
- Building the unified recorder prototype leveraging the proxy-tool, works for both core-v1 and core-v2 SDKs. Shows data-tables and storage-queue as examples for core-v2 and core-v1 respectively. | ||
[#15826](https://github.com/Azure/azure-sdk-for-js/pull/15826) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sdk/test-utils/recorder-new/recordings/browsers/proxy_tool/recording_sample_response.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
sdk/test-utils/recorder-new/recordings/node/proxy_tool/recording_sample_response.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
sdk/test-utils/recorder-new/src/utils/relativePathCalculator.browser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
export function relativeRecordingsPath() { | ||
throw new Error("Attempted to use the function meant for node in a browser."); | ||
} |
67 changes: 67 additions & 0 deletions
67
sdk/test-utils/recorder-new/src/utils/relativePathCalculator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import path from "path"; | ||
import fs from "fs"; | ||
import { RecorderError } from "./utils"; | ||
|
||
/** | ||
* ONLY WORKS IN THE NODE.JS ENVIRONMENT | ||
* | ||
* Returns the potential `recordings` folder(relative path) for the project using `process.cwd()`. | ||
* | ||
* Note for browser tests: | ||
* 1. Supposed to be called from karma.conf.js in the package for which the testing is being done. | ||
* 2. Set this `RECORDINGS_RELATIVE_PATH` as an env variable | ||
* ```js | ||
* const { relativeRecordingsPathForBrowser } = require("@azure-tools/test-recorder-new"); | ||
* process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPathForBrowser(); | ||
* ``` | ||
* 3. Add "RECORDINGS_RELATIVE_PATH" in the `envPreprocessor` array to let this be loaded in the browser environment. | ||
* ``` | ||
* envPreprocessor: ["RECORDINGS_RELATIVE_PATH"], | ||
* ``` | ||
* | ||
* `RECORDINGS_RELATIVE_PATH` in the browser environment is used in the recorder to tell the proxy-tool about the location to generate the browser recordings at. | ||
* | ||
* @export | ||
* @returns {string} location of the relative `recordings` folder path - `sdk/storage/storage-blob/recordings/` example | ||
*/ | ||
export function relativeRecordingsPath() { | ||
let currentPath = process.cwd(); // Gives the current working directory | ||
console.log(currentPath); | ||
|
||
let rootPath = undefined; | ||
let expectedProjectPath = undefined; | ||
|
||
if (fs.existsSync(path.join(currentPath, "package.json"))) { | ||
// <root>/sdk/service/project/package.json | ||
if (fs.existsSync(path.join(currentPath, "package.json"))) { | ||
expectedProjectPath = currentPath; // <root>/sdk/service/project/ | ||
const expectedRootPath = path.join(currentPath, "..", "..", ".."); // <root>/ | ||
if ( | ||
fs.existsSync(path.join(expectedRootPath, "sdk/")) && // <root>/sdk | ||
fs.existsSync(path.join(expectedRootPath, "rush.json")) // <root>/rush.json | ||
) { | ||
// reached root path | ||
rootPath = expectedRootPath; | ||
} | ||
} | ||
} else { | ||
throw new RecorderError(`'package.json' is not found at ${currentPath}`); | ||
} | ||
|
||
if (!(rootPath === undefined || expectedProjectPath === undefined)) { | ||
// <root>/ | ||
// <root>/sdk/service/project/ | ||
return path | ||
.join(path.relative(rootPath, expectedProjectPath), "recordings") | ||
.split(path.sep) | ||
.join(path.posix.sep); // Converting "\" to "/" (needed for windows) so that the path.sep("\") is not treated as an escape character in the browsers | ||
// => sdk/service/project/recordings | ||
} else { | ||
throw new RecorderError( | ||
"rootPath or expectedProjectPath could not be calculated properly from process.cwd()" | ||
); | ||
} | ||
} |
Oops, something went wrong.