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

[Unified Recorder] TestProxyClient takes test context to generate recordings at desired location #17388

Merged
merged 55 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e13ec0d
TestProxyClient takes test context to generate recordings at desired …
HarshaNalluru Aug 31, 2021
40c4a5a
set /workspaces/azure-sdk-for-js/ as entry point
HarshaNalluru Sep 20, 2021
30058f7
use Test as testContext type
HarshaNalluru Sep 20, 2021
5a2509e
update recorder-new tests
HarshaNalluru Sep 20, 2021
70e1bbb
update tests with before and after each
HarshaNalluru Sep 21, 2021
6eb87d1
relativePathCalculator - for browser => done
HarshaNalluru Sep 21, 2021
ccbd14c
create utils folder
HarshaNalluru Sep 21, 2021
47bb18a
export relativeRecordingsPathForBrowser to use in karma.conf
HarshaNalluru Sep 21, 2021
05c00b0
utils folder updates
HarshaNalluru Sep 21, 2021
1968f07
RECORDINGS_RELATIVE_PATH env variable in karma.conf
HarshaNalluru Sep 21, 2021
e950683
node side draft
HarshaNalluru Sep 21, 2021
6cb397c
relativeRecordingsPathForNode
HarshaNalluru Sep 27, 2021
f927df5
findRecordingsFolderPath
HarshaNalluru Sep 27, 2021
25fa7a6
remove console.logs
HarshaNalluru Sep 27, 2021
390cb3f
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Sep 27, 2021
79c90da
throw new Error(
HarshaNalluru Sep 27, 2021
d3bd3e0
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Sep 27, 2021
1475dc2
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Sep 27, 2021
b49b78e
lock file
HarshaNalluru Sep 27, 2021
5030832
--net=host docs
HarshaNalluru Sep 27, 2021
eeb79cc
sample recordings
HarshaNalluru Sep 27, 2021
b71afda
refactor existing tests
HarshaNalluru Sep 27, 2021
3ce602d
server and tests hitting the server
HarshaNalluru Sep 27, 2021
75e96c2
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Sep 27, 2021
c916456
unrelated changes in package.json
HarshaNalluru Sep 27, 2021
fa2e266
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 27, 2021
e110ccf
changelog
HarshaNalluru Sep 27, 2021
a66b3fb
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 27, 2021
344ac2e
lock file
HarshaNalluru Sep 27, 2021
1c9f090
Jeremy's feedbackl
HarshaNalluru Sep 28, 2021
cc4420a
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Sep 30, 2021
3703d8e
lock file
HarshaNalluru Sep 30, 2021
56fa188
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 1, 2021
51cbab0
lock file
HarshaNalluru Oct 1, 2021
91d46ad
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Oct 1, 2021
28037ec
Update sdk/test-utils/recorder-new/README.md
HarshaNalluru Oct 1, 2021
b863c43
readme
HarshaNalluru Oct 1, 2021
98b8def
Merge branch 'harshan/recorder/issue/17384' of https://github.com/har…
HarshaNalluru Oct 1, 2021
9b2db94
removing the exclamations. 🙂
HarshaNalluru Oct 1, 2021
dace442
address feedback
HarshaNalluru Oct 1, 2021
4f06aff
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 1, 2021
da830bc
clientHttpClient
HarshaNalluru Oct 1, 2021
613f803
sample recordings
HarshaNalluru Oct 2, 2021
9ab9e1b
relativeRecordingsPathForBrowser -> relativeRecordingsPath
HarshaNalluru Oct 2, 2021
c5855cd
massive update to relativeRecordingsPath - which works fine on linux
HarshaNalluru Oct 2, 2021
5fe22e1
RECORDINGS_RELATIVE_PATH in karma.conf
HarshaNalluru Oct 2, 2021
b743285
dist-esm/test/index.spec.js doesn't exist
HarshaNalluru Oct 2, 2021
e942956
lock file
HarshaNalluru Oct 2, 2021
c08f8b1
updates for windows
HarshaNalluru Oct 2, 2021
b1d079c
`--add-host host.docker.internal:host-gateway`
HarshaNalluru Oct 4, 2021
6239815
more comments
HarshaNalluru Oct 4, 2021
e6c6b0a
remove unintended file
HarshaNalluru Oct 4, 2021
912568b
Update sdk/test-utils/recorder-new/CHANGELOG.md
HarshaNalluru Oct 4, 2021
a110c8f
remove sq brackets
HarshaNalluru Oct 4, 2021
53b24cb
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-js into…
HarshaNalluru Oct 4, 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
Prev Previous commit
Next Next commit
massive update to relativeRecordingsPath - which works fine on linux
  • Loading branch information
HarshaNalluru authored Oct 2, 2021
commit c5855cdc1d7440567664a5f0d567b5036cd153fd
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export function relativeRecordingsPathForNode() {
export function relativeRecordingsPath() {
throw new Error("Attempted to use the function meant for node in a browser.");
}

export function relativeRecordingsPathForBrowser() {
// If you get this error, it's because you tried to use this config in a browser.
// It is meant to be imported in the karma configuration file and used to configure
// the browser launch specifications, not to be used within the browser itself.
throw new Error("Attempted to use the base karma configuration in a browser.");
}
120 changes: 44 additions & 76 deletions sdk/test-utils/recorder-new/src/utils/relativePathCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,60 @@ import path from "path";
import fs from "fs";
import { RecorderError } from "./utils";

sadasant marked this conversation as resolved.
Show resolved Hide resolved
export function relativeRecordingsPathForNode(testContext: Mocha.Test) {
const testAbsolutePath = testContext.file;
if (!testAbsolutePath) {
throw new RecorderError("Unable to grab the file path from the test run");
}

const recordingsPath = findRecordingsFolderPath(testAbsolutePath);
const recordingsFolder = path.basename(recordingsPath);
const projectFolder = path.basename(path.resolve(recordingsPath, ".."));
const serviceFolder = path.basename(path.resolve(recordingsPath, "..", ".."));
const sdk = path.basename(path.resolve(recordingsPath, "..", "..", ".."));
if (sdk !== "sdk") {
throw new Error("Unexpected location for recordings, please fix the location.");
}
return path
.join(sdk, serviceFolder, projectFolder, recordingsFolder)
.split(path.sep)
.join(path.posix.sep);
}

export function relativeRecordingsPathForBrowser() {
const pathFormatted = process.cwd();
const projectFolder = path.basename(pathFormatted);
const serviceFolder = path.basename(path.resolve(pathFormatted, ".."));
const sdk = path.basename(path.resolve(pathFormatted, "..", ".."));
if (sdk !== "sdk") {
throw new Error("Unexpected location for recordings, please fix the location.");
}
return path
.join(sdk, serviceFolder, projectFolder, "recordings")
.split(path.sep)
.join(path.posix.sep);
}

/**
* ONLY WORKS IN THE NODE.JS ENVIRONMENT
*
* 1. Takes the test filePath as argument.
* 2. Looks for the potential `recordings` folder in its hierarchical path.
* 3. Returns the full path of the `recordings` folder
* Returns the potential `recordings` folder(relative path) for the project using `process.cwd()`.
*
* While running the tests, `filePath` can vary depending on location of the test files, examples below
* 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"],
* ```
*
* 1. If roll-up generated bundle files are being leveraged to run the tests
* filePath = `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\dist-test\index.node.js`
* 2. If ts complied dist-esm files are being used to run the tests
* filePath = `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\dist-esm\test\utils.spec.js`
* filePath = `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\dist-esm\test\node\utils.spec.js`
* 3. If `.spec.ts` test files are being used directly
* filePath = `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\test\utils.spec.ts`
* filePath = `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\test\node\utils.spec.ts`
* In the above examples, no matter where the test files are,
* the recordings are located at `<base path>\azure-sdk-for-js\sdk\storage\storage-blob\recordings\`.
* In order to playback the tests, exact location of the recordings is to be found,
* this is done by checking the parent(s) folders until the `recordings` folder is found.
* `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
* @param {string} filePath
* @returns {string} location of the `recordings` folder
* @returns {string} location of the relative `recordings` folder path - `sdk/storage/storage-blob/recordings/` example
*/
function findRecordingsFolderPath(filePath: string): string {
// Stripping away the file name
let currentPath = path.resolve(filePath, "..");
// File/folder path of a closest child of `currentPath` in the folder hierarchy of `filePath`
let lastPath = filePath;
try {
// While loop to find the entry point of the SDK
while (
!(
fs.existsSync(path.resolve(currentPath, "package.json")) &&
fs.existsSync(path.resolve(currentPath, "..", "..", "..", "sdk/")) &&
fs.existsSync(path.resolve(currentPath, "..", "..", "..", "rush.json"))
)
) {
lastPath = currentPath;
currentPath = path.resolve(currentPath, "..");
if (lastPath === currentPath) {
throw new Error(
`'package.json' is not found at ${currentPath} (reached the root directory)`
);
export function relativeRecordingsPath() {
let currentPath = process.cwd();
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;
}
}
return path.resolve(currentPath, "recordings/");
} catch (error) {
throw new Error(
`Unable to locate the 'recordings' folder anywhere in the hierarchy of the file path ${filePath}\n ${error}`
} 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");
// => sdk/service/project/recordings
} else {
throw new RecorderError(
"rootPath or expectedProjectPath could not be calculated properly from process.cwd()"
);
}
}
10 changes: 4 additions & 6 deletions sdk/test-utils/recorder-new/src/utils/sessionFilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

import { env, generateTestRecordingFilePath } from "@azure-tools/test-recorder";
import { isNode } from "@azure/test-utils";
import { relativeRecordingsPathForNode } from "./relativePathCalculator";
import { relativeRecordingsPath } from "./relativePathCalculator";

export function sessionFilePath(testContext: Mocha.Test) {
if (!isNode) {
return `${env.RECORDINGS_RELATIVE_PATH}/${recordingFilePath(testContext)}`;
} else {
return `${relativeRecordingsPathForNode(testContext)}/${recordingFilePath(testContext)}`;
}
const recordingsFolder = !isNode ? env.RECORDINGS_RELATIVE_PATH : relativeRecordingsPath(); // sdk/service/project/recordings
return `${recordingsFolder}/${recordingFilePath(testContext)}`;
// sdk/service/project/recordings/{node|browsers}/<describe-block-title>/recording_<test-title>.json
}

/**
Expand Down