diff --git a/common/tools/dev-tool/src/commands/run/update-snippets.ts b/common/tools/dev-tool/src/commands/run/update-snippets.ts index 197f4ae64a16..c1ab1b994a90 100644 --- a/common/tools/dev-tool/src/commands/run/update-snippets.ts +++ b/common/tools/dev-tool/src/commands/run/update-snippets.ts @@ -229,15 +229,12 @@ async function parseSnippetDefinitions( sourceFile, ); - const imports: [string, string][] = []; + const imports: { name: string; moduleSpecifier: string; isDefault: boolean }[] = []; // This nested visitor is just for extracting the imports of a symbol. const symbolImportVisitor: ts.Visitor = (node: ts.Node) => { - let importLocations: string[] | undefined; - if ( - ts.isIdentifier(node) && - (importLocations = extractImportLocations(node)) !== undefined - ) { + if (ts.isIdentifier(node)) { + const importLocations = extractImportLocations(node); if (importLocations.length > 1) { // We can probably handle this, but it's an obscure case and it's probably better to let it error out and // then observe whether or not we actually need (or even _want_) snippets with merged imports. @@ -247,7 +244,10 @@ async function parseSnippetDefinitions( } else if (importLocations.length === 1) { // The symbol was imported, so we need to track the imports to add them to the snippet later. log.debug(`symbol ${node.text} was imported from ${importLocations[0]}`); - imports.push([node.text, importLocations[0]]); + imports.push({ + name: node.text, + ...importLocations[0], + }); } // else the symbol was not imported within this file, so it must be defined in the ambient context of the // module, so we don't need to generate any code for it. @@ -264,23 +264,56 @@ async function parseSnippetDefinitions( // file using `convert`. log.debug(`found a snippet named ${name.text}: \n${contents}`); + interface ImportedSymbols { + default?: string; + named?: Set; + } + // We have a loose map of imports in the form { [k:symbol]: module } and we need to anneal it into a map // { [k: module]: symbol[] } (one import statement per module with the whole list of symbols imported from it) - const importMap = new Map>( - imports.map(([, module]) => [module, new Set()]), - ); + const importMap = new Map(); - for (const [symbol, name] of imports) { - importMap.get(name)!.add(symbol); + for (const { name, moduleSpecifier, isDefault } of imports) { + let moduleImports = importMap.get(moduleSpecifier); + if (!moduleImports) { + moduleImports = {}; + importMap.set(moduleSpecifier, moduleImports); + } + if (isDefault) { + if (moduleImports.default) { + throw new Error( + `unrecoverable error: multiple default imports from the same module '${moduleSpecifier}'`, + ); + } + moduleImports.default = name; + } else { + if (!moduleImports.named) { + moduleImports.named = new Set(); + } + moduleImports.named.add(name); + } } // Form import declarations and prepend them to the rest of the contents. const fullSnippetTypeScriptText = ( [...importMap.entries()] - .map( - ([module, symbols]) => - `import { ${[...symbols.values()].join(", ")} } from "${module}";`, - ) + .map(([module, imports]) => { + const importParts = []; + if (imports.default) { + importParts.push(imports.default); + } + if (imports.named) { + importParts.push(`{ ${[...imports.named].join(", ")} }`); + } + + if (importParts.length === 0) { + throw new Error( + `unrecoverable error: no imports were generated for the snippet '${name.text}'`, + ); + } + + return `import ${importParts.join(", ")} from "${module}";`; + }) .join(EOL) + EOL + EOL + @@ -387,11 +420,14 @@ async function parseSnippetDefinitions( * @param node - the node to check for imports * @returns a list of module specifiers that form the definition of the node's symbol, or undefined */ - function extractImportLocations(node: ts.Node): string[] | undefined { + function extractImportLocations(node: ts.Node): { + isDefault: boolean; + moduleSpecifier: string; + }[] { const sym = checker.getSymbolAtLocation(node); // Get all the decls that are in source files and where the decl comes from an import clause. - return sym?.declarations + const nonDefaultExports = sym?.declarations ?.filter( (decl) => decl.getSourceFile() === sourceFile && @@ -411,12 +447,38 @@ async function parseSnippetDefinitions( moduleSpecifierText === path.join(relativeIndexPath, "index.js") || moduleSpecifierText === path.join(relativeIndexPath, "index") ) { - return project.name; + return { moduleSpecifier: project.name, isDefault: false }; } else { - return moduleSpecifierText; + return { moduleSpecifier: moduleSpecifierText, isDefault: false }; } }, ); + + const defaultExports = sym?.declarations + ?.filter( + (decl) => + decl.getSourceFile() === sourceFile && + ts.isImportClause(decl) && + ts.isImportDeclaration(decl.parent) && + decl.name, + ) + .map((decl) => { + const moduleSpecifierText = ( + (decl.parent as ts.ImportDeclaration).moduleSpecifier as ts.StringLiteral + ).text; + + if ( + moduleSpecifierText === relativeIndexPath || + moduleSpecifierText === path.join(relativeIndexPath, "index.js") || + moduleSpecifierText === path.join(relativeIndexPath, "index") + ) { + return { moduleSpecifier: project.name, isDefault: true }; + } else { + return { moduleSpecifier: moduleSpecifierText, isDefault: true }; + } + }); + + return [...(nonDefaultExports ?? []), ...(defaultExports ?? [])]; } } diff --git a/sdk/agrifood/agrifood-farming-rest/README.md b/sdk/agrifood/agrifood-farming-rest/README.md index 4e6f8b994856..02215bad04ab 100644 --- a/sdk/agrifood/agrifood-farming-rest/README.md +++ b/sdk/agrifood/agrifood-farming-rest/README.md @@ -54,7 +54,7 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET Use the returned token credential to authenticate the client: ```ts snippet:CreateFarmBeatsClient -import { FarmBeats } from "@azure-rest/agrifood-farming"; +import FarmBeats from "@azure-rest/agrifood-farming"; import { DefaultAzureCredential } from "@azure/identity"; const client = FarmBeats( @@ -96,7 +96,7 @@ Once you have authenticated and created the client object as shown in the [Authe section, you can create a party within the Data Manager for Agriculture resource like this: ```ts snippet:CreateParty -import { FarmBeats, isUnexpected } from "@azure-rest/agrifood-farming"; +import FarmBeats, { isUnexpected } from "@azure-rest/agrifood-farming"; import { DefaultAzureCredential } from "@azure/identity"; const client = FarmBeats( @@ -127,7 +127,7 @@ console.log(`Created Party: ${party.name}`); ### List Parties ```ts snippet:ListParties -import { FarmBeats, isUnexpected, paginate } from "@azure-rest/agrifood-farming"; +import FarmBeats, { isUnexpected, paginate } from "@azure-rest/agrifood-farming"; import { DefaultAzureCredential } from "@azure/identity"; const client = FarmBeats( diff --git a/sdk/agrifood/agrifood-farming-rest/test/public/farmHeirarchy.spec.ts b/sdk/agrifood/agrifood-farming-rest/test/public/farmHeirarchy.spec.ts index f42a29e766ea..572163d8b9e2 100644 --- a/sdk/agrifood/agrifood-farming-rest/test/public/farmHeirarchy.spec.ts +++ b/sdk/agrifood/agrifood-farming-rest/test/public/farmHeirarchy.spec.ts @@ -8,12 +8,12 @@ import type { import { getLongRunningPoller, isUnexpected } from "../../src/index.js"; import { createClient, createRecorder } from "./utils/recordedClient.js"; import type { Recorder } from "@azure-tools/test-recorder"; -import { isNode } from "@azure/core-util"; +import { isNodeLike } from "@azure/core-util"; import { describe, it, assert, beforeEach, afterEach } from "vitest"; const startDateTime = new Date("2020-02-01T08:00:00.000Z"); const endDateTime = new Date("2020-03-02T08:00:00.000Z"); -const suffix = isNode ? "node" : "browser"; +const suffix = isNodeLike ? "node" : "browser"; const partyId = `${suffix}-contoso-party`; const boundaryId = `${suffix}-contoso-boundary`; const testparty = { @@ -28,13 +28,13 @@ describe("party Operations", () => { let recorder: Recorder; let client: FarmBeatsClient; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = await createRecorder(ctx); client = createClient(recorder.configureClientOptions({})); jobId = recorder.variable("jobId", `${suffix}-job-${Math.ceil(Math.random() * 1000)}`); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/agrifood/agrifood-farming-rest/test/snippets.spec.ts b/sdk/agrifood/agrifood-farming-rest/test/snippets.spec.ts index efa5ceb83017..b36001bf8c41 100644 --- a/sdk/agrifood/agrifood-farming-rest/test/snippets.spec.ts +++ b/sdk/agrifood/agrifood-farming-rest/test/snippets.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { describe, it } from "vitest"; -import { FarmBeats, isUnexpected, paginate } from "@azure-rest/agrifood-farming"; +import FarmBeats, { isUnexpected, paginate } from "../src/index.js"; import { DefaultAzureCredential } from "@azure/identity"; import { setLogLevel } from "@azure/logger"; diff --git a/sdk/anomalydetector/ai-anomaly-detector-rest/README.md b/sdk/anomalydetector/ai-anomaly-detector-rest/README.md index 84b5bf14f63f..11143eba21b6 100644 --- a/sdk/anomalydetector/ai-anomaly-detector-rest/README.md +++ b/sdk/anomalydetector/ai-anomaly-detector-rest/README.md @@ -90,12 +90,12 @@ The following section provides several code snippets covering some of the most c ### Batch detection ```ts snippet:batch_detection -import { +import AnomalyDetector, { TimeSeriesPoint, - AnomalyDetector, DetectUnivariateEntireSeriesParameters, isUnexpected, } from "@azure-rest/ai-anomaly-detector"; +import { readFileSync } from "node:fs"; import { parse } from "csv-parse/sync"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -105,7 +105,7 @@ const timeSeriesDataPath = "./samples-dev/example-data/request-data.csv"; function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); @@ -149,12 +149,12 @@ if (result.body.isAnomaly) { ### Streaming Detection ```ts snippet:streaming_detection -import { +import AnomalyDetector, { TimeSeriesPoint, - AnomalyDetector, DetectUnivariateLastPointParameters, isUnexpected, } from "@azure-rest/ai-anomaly-detector"; +import { readFileSync } from "node:fs"; import { parse } from "csv-parse/sync"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -164,7 +164,7 @@ const timeSeriesDataPath = "./samples-dev/example-data/request-data.csv"; function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); @@ -205,12 +205,12 @@ if (result.body.isAnomaly) { ### Detect change points ```ts snippet:detect_change_points -import { +import AnomalyDetector, { TimeSeriesPoint, - AnomalyDetector, DetectUnivariateChangePointParameters, isUnexpected, } from "@azure-rest/ai-anomaly-detector"; +import { readFileSync } from "node:fs"; import { parse } from "csv-parse/sync"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -220,7 +220,7 @@ const timeSeriesDataPath = "./samples-dev/example-data/request-data.csv"; function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); diff --git a/sdk/anomalydetector/ai-anomaly-detector-rest/test/snippets.spec.ts b/sdk/anomalydetector/ai-anomaly-detector-rest/test/snippets.spec.ts index fbb57bdec04b..01e49a09fbb1 100644 --- a/sdk/anomalydetector/ai-anomaly-detector-rest/test/snippets.spec.ts +++ b/sdk/anomalydetector/ai-anomaly-detector-rest/test/snippets.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { describe, it } from "vitest"; -import fs from "node:fs"; +import { readFileSync } from "node:fs"; import { parse } from "csv-parse/sync"; import { AzureKeyCredential } from "@azure/core-auth"; import type { @@ -10,8 +10,8 @@ import type { DetectUnivariateEntireSeriesParameters, DetectUnivariateLastPointParameters, TimeSeriesPoint, -} from "@azure-rest/ai-anomaly-detector"; -import { AnomalyDetector, isUnexpected } from "@azure-rest/ai-anomaly-detector"; +} from "../src/index.js"; +import AnomalyDetector, { isUnexpected } from "../src/index.js"; import { setLogLevel } from "@azure/logger"; describe("snippets", () => { @@ -22,7 +22,7 @@ describe("snippets", () => { // @ts-preserve-whitespace function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); @@ -70,7 +70,7 @@ describe("snippets", () => { // @ts-preserve-whitespace function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); @@ -115,7 +115,7 @@ describe("snippets", () => { // @ts-preserve-whitespace function read_series_from_file(path: string): Array { const result = Array(); - const input = fs.readFileSync(path).toString(); + const input = readFileSync(path).toString(); const parsed = parse(input, { skip_empty_lines: true }); parsed.forEach(function (e: Array) { result.push({ timestamp: new Date(e[0]), value: Number(e[1]) }); diff --git a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/LICENSE.txt b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/LICENSE.txt deleted file mode 100644 index ea8fb1516028..000000000000 --- a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2020 Microsoft - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/README.md b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/README.md index acbb95314e0e..789dcf168f31 100644 --- a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/README.md +++ b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/README.md @@ -48,20 +48,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). -```javascript -const { WebSiteManagementClient } = require("@azure/arm-appservice-profile-2020-09-01-hybrid"); -const { DefaultAzureCredential } = require("@azure/identity"); -// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. + +```ts snippet:ReadmeSampleCreateClient_Node +import { WebSiteManagementClient } from "@azure/arm-appservice-profile-2020-09-01-hybrid"; +import { DefaultAzureCredential } from "@azure/identity"; const subscriptionId = "00000000-0000-0000-0000-000000000000"; const client = new WebSiteManagementClient(new DefaultAzureCredential(), subscriptionId); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. -// For client-side applications running in the browser, use this code instead: -// const credential = new InteractiveBrowserCredential({ -// tenantId: "", -// clientId: "" -// }); -// const client = new WebSiteManagementClient(credential, subscriptionId); +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import { WebSiteManagementClient } from "@azure/arm-appservice-profile-2020-09-01-hybrid"; + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", +}); +const client = new WebSiteManagementClient(credential, subscriptionId); ``` ### JavaScript Bundle @@ -80,8 +88,9 @@ To use this client library in the browser, first you need to use a bundler. For Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: -```javascript -const { setLogLevel } = require("@azure/logger"); +```ts snippet:SetLogLevel +import { setLogLevel } from "@azure/logger"; + setLogLevel("info"); ``` diff --git a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/package.json b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/package.json index 5330351520f3..24ad3db5b020 100644 --- a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/package.json +++ b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/package.json @@ -8,20 +8,21 @@ "node": ">=18.0.0" }, "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/core-auth": "^1.3.0", - "@azure/core-client": "^1.6.1", - "@azure/core-lro": "^2.2.0", - "@azure/core-paging": "^1.2.0", - "@azure/core-rest-pipeline": "^1.8.0", - "tslib": "^2.2.0" + "@azure/abort-controller": "^2.1.2", + "@azure/core-auth": "^1.9.0", + "@azure/core-client": "^1.9.2", + "@azure/core-lro": "^2.7.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.0", + "tslib": "^2.8.1" }, "keywords": [ "node", "azure", "typescript", "browser", - "isomorphic" + "isomorphic", + "cloud" ], "license": "MIT", "main": "./dist/commonjs/index.js", @@ -32,7 +33,7 @@ "@azure-tools/test-recorder": "^4.1.0", "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", - "@azure/identity": "^4.0.1", + "@azure/identity": "^4.5.0", "@types/node": "^18.0.0", "@vitest/browser": "^2.1.8", "@vitest/coverage-istanbul": "^2.1.8", @@ -42,10 +43,7 @@ "vitest": "^2.1.8" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid", - "repository": { - "type": "git", - "url": "https://github.com/Azure/azure-sdk-for-js.git" - }, + "repository": "github:Azure/azure-sdk-for-js", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, @@ -80,7 +78,7 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "echo skipped", "unit-test:node": "dev-tool run test:vitest", - "update-snippets": "echo skipped" + "update-snippets": "dev-tool run update-snippets" }, "sideEffects": false, "//metadata": { diff --git a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/sampleTest.spec.ts b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/sampleTest.spec.ts index e25d3db273e7..86a13f7a74a4 100644 --- a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/sampleTest.spec.ts +++ b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/sampleTest.spec.ts @@ -6,17 +6,15 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { - Recorder, - RecorderStartOptions -} from "@azure-tools/test-recorder"; -import { afterEach, beforeEach, describe, it } from "vitest"; +import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import { Recorder } from "@azure-tools/test-recorder"; +import { afterEach, beforeEach, describe, it, assert } from "vitest"; const replaceableVariables: Record = { AZURE_CLIENT_ID: "azure_client_id", AZURE_CLIENT_SECRET: "azure_client_secret", AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", - SUBSCRIPTION_ID: "azure_subscription_id" + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderOptions: RecorderStartOptions = { @@ -30,16 +28,16 @@ const recorderOptions: RecorderStartOptions = { describe("My test", () => { let recorder: Recorder; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = new Recorder(ctx); await recorder.start(recorderOptions); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it("sample test", async function () { - console.log("Hi, I'm a test!"); + it("sample test", async () => { + assert(true); }); }); diff --git a/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/snippets.spec.ts b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/snippets.spec.ts new file mode 100644 index 000000000000..eb0cd51a35f7 --- /dev/null +++ b/sdk/appservice/arm-appservice-profile-2020-09-01-hybrid/test/snippets.spec.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { WebSiteManagementClient } from "@azure/arm-appservice-profile-2020-09-01-hybrid"; +import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const client = new WebSiteManagementClient(new DefaultAzureCredential(), subscriptionId); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + const client = new WebSiteManagementClient(credential, subscriptionId); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/sdk/appservice/arm-appservice-rest/README.md b/sdk/appservice/arm-appservice-rest/README.md index 3ba6461d100e..c20d1e42e833 100644 --- a/sdk/appservice/arm-appservice-rest/README.md +++ b/sdk/appservice/arm-appservice-rest/README.md @@ -45,10 +45,23 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET Use the returned token credential to authenticate the client: -```typescript +```ts snippet:ReadmeSampleCreateClient_Node import WebSiteManagementClient from "@azure-rest/arm-appservice"; import { DefaultAzureCredential } from "@azure/identity"; -const credential = new DefaultAzureCredential(); + +const client = WebSiteManagementClient(new DefaultAzureCredential()); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. + +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import WebSiteManagementClient from "@azure-rest/arm-appservice"; + +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", +}); const client = WebSiteManagementClient(credential); ``` @@ -58,26 +71,25 @@ The following section shows you how to initialize and authenticate your client, ### List All App Service Plans -```typescript -import WebSiteManagementClient, { paginate } from "@azure-rest/arm-appservice"; +```ts snippet:ListAppServicePlans import { DefaultAzureCredential } from "@azure/identity"; +import WebSiteManagementClient, { paginate } from "@azure-rest/arm-appservice"; + +const subscriptionId = process.env.SUBSCRIPTION_ID as string; +const credential = new DefaultAzureCredential(); +const client = WebSiteManagementClient(credential); + +const result = []; +const initialResposne = await client + .path("/subscriptions/{subscriptionId}/providers/Microsoft.Web/serverfarms", subscriptionId) + .get(); +const res = paginate(client, initialResposne); -async function listAppServicePlans() { - const subscriptionId = process.env.SUBSCRIPTION_ID as string; - const credential = new DefaultAzureCredential(); - const client = WebSiteManagementClient(credential); - const result = []; - const initialResposne = await client - .path("/subscriptions/{subscriptionId}/providers/Microsoft.Web/serverfarms", subscriptionId) - .get(); - const res = paginate(client, initialResposne); - for await (let item of res) { - result.push(item); - } - console.log(result); +for await (const item of res) { + result.push(item); } -listAppServicePlans().catch(console.error); +console.log(result); ``` ## Troubleshooting @@ -86,7 +98,7 @@ listAppServicePlans().catch(console.error); Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: -```javascript +```ts snippet:SetLogLevel import { setLogLevel } from "@azure/logger"; setLogLevel("info"); diff --git a/sdk/appservice/arm-appservice-rest/package.json b/sdk/appservice/arm-appservice-rest/package.json index aeec162f62fb..64f3d8536e01 100644 --- a/sdk/appservice/arm-appservice-rest/package.json +++ b/sdk/appservice/arm-appservice-rest/package.json @@ -64,18 +64,18 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", "unit-test:node": "dev-tool run test:vitest", - "update-snippets": "echo skipped" + "update-snippets": "dev-tool run update-snippets" }, "sideEffects": false, "autoPublish": false, "dependencies": { - "@azure-rest/core-client": "^1.0.0", + "@azure-rest/core-client": "^2.3.2", "@azure/abort-controller": "^2.1.2", - "@azure/core-auth": "^1.3.0", + "@azure/core-auth": "^1.9.0", "@azure/core-lro": "^3.1.0", - "@azure/core-rest-pipeline": "^1.8.0", - "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "@azure/core-rest-pipeline": "^1.18.1", + "@azure/logger": "^1.1.4", + "tslib": "^2.8.1" }, "devDependencies": { "@azure-tools/test-credential": "^2.0.0", @@ -83,7 +83,7 @@ "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@azure/identity": "^4.0.1", + "@azure/identity": "^4.5.0", "@types/node": "^18.0.0", "@vitest/browser": "^2.1.8", "@vitest/coverage-istanbul": "^2.1.8", diff --git a/sdk/appservice/arm-appservice-rest/test/public/appservice-rest.spec.ts b/sdk/appservice/arm-appservice-rest/test/public/appservice-rest.spec.ts index 33d3af2ce9c9..51d15081c1d4 100644 --- a/sdk/appservice/arm-appservice-rest/test/public/appservice-rest.spec.ts +++ b/sdk/appservice/arm-appservice-rest/test/public/appservice-rest.spec.ts @@ -20,7 +20,7 @@ describe("Web test", () => { let appservicePlanName: string; let name: string; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = await createRecorder(ctx); client = await createClient(recorder); subscriptionId = env.SUBSCRIPTION_ID ?? ""; @@ -29,11 +29,11 @@ describe("Web test", () => { name = "mysitexxxx"; }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it("appServicePlans create test", async function () { + it("appServicePlans create test", async () => { const initialResponse = await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/serverfarms/{name}", @@ -61,7 +61,7 @@ describe("Web test", () => { assert.isTrue(res.body !== undefined); }); - it("webApps create test", async function () { + it("webApps create test", async () => { const initialResponse = await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}", @@ -102,7 +102,7 @@ describe("Web test", () => { assert.isTrue(res.body !== undefined); }); - it("appServicePlans get test", async function () { + it("appServicePlans get test", async () => { const res = await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/serverfarms/{name}", @@ -114,7 +114,7 @@ describe("Web test", () => { assert.strictEqual(res.status, "200"); }); - it("webApps get test", async function () { + it("webApps get test", async () => { const res = await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}", @@ -126,7 +126,7 @@ describe("Web test", () => { assert.strictEqual(res.status, "200"); }); - it.skip("appServicePlans list test", async function () { + it.skip("appServicePlans list test", async () => { const resArray = new Array(); const initialResposne = await client .path( @@ -141,7 +141,6 @@ describe("Web test", () => { body: { value: [ [Object] ], nextLink: null, id: null } } */ - // console.log(initialResposne); // Body Property nextLink should be a string or undefined const res = paginate(client, initialResposne); for await (const item of res) { @@ -150,7 +149,7 @@ describe("Web test", () => { assert.equal(resArray.length, 1); }); - it("webApps list test", async function () { + it("webApps list test", async () => { const resArray = new Array(); const initialResposne = await client .path("/subscriptions/{subscriptionId}/providers/Microsoft.Web/sites", subscriptionId) @@ -162,7 +161,7 @@ describe("Web test", () => { assert.equal(resArray.length, 1); }); - it("webApps update test", async function () { + it("webApps update test", async () => { const res = await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}", @@ -193,7 +192,7 @@ describe("Web test", () => { assert.isTrue(res.body !== undefined); }); - it("webApps delete test", async function () { + it("webApps delete test", async () => { await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}", @@ -213,7 +212,7 @@ describe("Web test", () => { assert.equal(resArray.length, 0); }); - it("appServicePlans delete test", async function () { + it("appServicePlans delete test", async () => { await client .path( "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/serverfarms/{name}", diff --git a/sdk/appservice/arm-appservice-rest/test/snippets.spec.ts b/sdk/appservice/arm-appservice-rest/test/snippets.spec.ts new file mode 100644 index 000000000000..223e11761a30 --- /dev/null +++ b/sdk/appservice/arm-appservice-rest/test/snippets.spec.ts @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import WebSiteManagementClient, { paginate } from "@azure-rest/arm-appservice"; +import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + // @ts-ignore + const client = WebSiteManagementClient(new DefaultAzureCredential()); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + // @ts-ignore + const client = WebSiteManagementClient(credential); + }); + + it("ListAppServicePlans", async () => { + const subscriptionId = process.env.SUBSCRIPTION_ID as string; + const credential = new DefaultAzureCredential(); + const client = WebSiteManagementClient(credential); + // @ts-preserve-whitespace + const result = []; + const initialResposne = await client + .path("/subscriptions/{subscriptionId}/providers/Microsoft.Web/serverfarms", subscriptionId) + .get(); + const res = paginate(client, initialResposne); + // @ts-preserve-whitespace + for await (const item of res) { + result.push(item); + } + // @ts-preserve-whitespace + console.log(result); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/sdk/appservice/arm-appservice-rest/tsconfig.browser.config.json b/sdk/appservice/arm-appservice-rest/tsconfig.browser.config.json index f772e6eb3b76..c8e4cc1e72a4 100644 --- a/sdk/appservice/arm-appservice-rest/tsconfig.browser.config.json +++ b/sdk/appservice/arm-appservice-rest/tsconfig.browser.config.json @@ -1,6 +1,12 @@ { "extends": "./.tshy/build.json", - "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "include": [ + "./src/**/*.ts", + "./src/**/*.mts", + "./test/**/*.ts", + "./test/**/*.spec.ts", + "./test/**/*.mts" + ], "exclude": ["./test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", diff --git a/sdk/appservice/arm-appservice-rest/vitest.browser.config.ts b/sdk/appservice/arm-appservice-rest/vitest.browser.config.ts index b48c61b2ef46..304ad6de01f5 100644 --- a/sdk/appservice/arm-appservice-rest/vitest.browser.config.ts +++ b/sdk/appservice/arm-appservice-rest/vitest.browser.config.ts @@ -1,4 +1,3 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. @@ -9,9 +8,8 @@ export default mergeConfig( viteConfig, defineConfig({ test: { - include: [ - "dist-test/browser/test/**/*.spec.js", - ], + include: ["dist-test/browser/test/**/*.spec.js"], + exclude: ["dist-test/browser/test/snippets.spec.js"], }, }), ); diff --git a/sdk/appservice/arm-appservice/README.md b/sdk/appservice/arm-appservice/README.md index 550d0de46f17..406da4facc5c 100644 --- a/sdk/appservice/arm-appservice/README.md +++ b/sdk/appservice/arm-appservice/README.md @@ -48,20 +48,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). -```javascript -const { WebSiteManagementClient } = require("@azure/arm-appservice"); -const { DefaultAzureCredential } = require("@azure/identity"); -// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. + +```ts snippet:ReadmeSampleCreateClient_Node +import { WebSiteManagementClient } from "@azure/arm-appservice"; +import { DefaultAzureCredential } from "@azure/identity"; const subscriptionId = "00000000-0000-0000-0000-000000000000"; const client = new WebSiteManagementClient(new DefaultAzureCredential(), subscriptionId); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. -// For client-side applications running in the browser, use this code instead: -// const credential = new InteractiveBrowserCredential({ -// tenantId: "", -// clientId: "" -// }); -// const client = new WebSiteManagementClient(credential, subscriptionId); +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import { WebSiteManagementClient } from "@azure/arm-appservice"; + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", +}); +const client = new WebSiteManagementClient(credential, subscriptionId); ``` ### JavaScript Bundle @@ -80,8 +88,9 @@ To use this client library in the browser, first you need to use a bundler. For Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: -```javascript -const { setLogLevel } = require("@azure/logger"); +```ts snippet:SetLogLevel +import { setLogLevel } from "@azure/logger"; + setLogLevel("info"); ``` diff --git a/sdk/appservice/arm-appservice/package.json b/sdk/appservice/arm-appservice/package.json index 619106798ab1..2240f81814c5 100644 --- a/sdk/appservice/arm-appservice/package.json +++ b/sdk/appservice/arm-appservice/package.json @@ -8,12 +8,12 @@ "node": ">=18.0.0" }, "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/core-auth": "^1.6.0", - "@azure/core-client": "^1.7.0", - "@azure/core-lro": "^2.5.4", - "@azure/core-paging": "^1.2.0", - "@azure/core-rest-pipeline": "^1.14.0", + "@azure/abort-controller": "^2.1.2", + "@azure/core-auth": "^1.9.0", + "@azure/core-client": "^1.9.2", + "@azure/core-lro": "^2.7.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.1", "tslib": "^2.2.0" }, "keywords": [ @@ -21,7 +21,8 @@ "azure", "typescript", "browser", - "isomorphic" + "isomorphic", + "cloud" ], "license": "MIT", "main": "./dist/commonjs/index.js", @@ -32,20 +33,16 @@ "@azure-tools/test-recorder": "^4.1.0", "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", - "@azure/identity": "^4.0.1", + "@azure/identity": "^4.5.0", "@types/node": "^18.0.0", "@vitest/browser": "^2.1.8", "@vitest/coverage-istanbul": "^2.1.8", "dotenv": "^16.0.0", "playwright": "^1.49.1", - "tsx": "^4.7.1", "typescript": "~5.7.2", "vitest": "^2.1.8" }, - "repository": { - "type": "git", - "url": "https://github.com/Azure/azure-sdk-for-js.git" - }, + "repository": "github:Azure/azure-sdk-for-js", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, @@ -80,7 +77,7 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "echo skipped", "unit-test:node": "dev-tool run test:vitest", - "update-snippets": "echo skipped" + "update-snippets": "dev-tool run update-snippets" }, "sideEffects": false, "//metadata": { diff --git a/sdk/appservice/arm-appservice/test/snippets.spec.ts b/sdk/appservice/arm-appservice/test/snippets.spec.ts new file mode 100644 index 000000000000..11dd2e26c868 --- /dev/null +++ b/sdk/appservice/arm-appservice/test/snippets.spec.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { WebSiteManagementClient } from "@azure/arm-appservice"; +import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const client = new WebSiteManagementClient(new DefaultAzureCredential(), subscriptionId); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + const client = new WebSiteManagementClient(credential, subscriptionId); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/sdk/appservice/arm-appservice/test/web_examples.spec.ts b/sdk/appservice/arm-appservice/test/web_examples.spec.ts index 56d5544aa912..b1812c867030 100644 --- a/sdk/appservice/arm-appservice/test/web_examples.spec.ts +++ b/sdk/appservice/arm-appservice/test/web_examples.spec.ts @@ -6,18 +6,14 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { - env, - Recorder, - RecorderStartOptions, - isPlaybackMode, -} from "@azure-tools/test-recorder"; +import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import { env, Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { createTestCredential } from "@azure-tools/test-credential"; import { WebSiteManagementClient } from "../src/webSiteManagementClient.js"; import { afterEach, assert, beforeEach, describe, it } from "vitest"; const replaceableVariables: Record = { - SUBSCRIPTION_ID: "azure_subscription_id" + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderOptions: RecorderStartOptions = { @@ -41,101 +37,118 @@ describe("Web test", () => { let appservicePlanName: string; let name: string; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = new Recorder(ctx); await recorder.start(recorderOptions); - subscriptionId = env.SUBSCRIPTION_ID || ''; + subscriptionId = env.SUBSCRIPTION_ID || ""; // This is an example of how the environment variables are used const credential = createTestCredential(); - client = new WebSiteManagementClient(credential, subscriptionId, recorder.configureClientOptions({})); + client = new WebSiteManagementClient( + credential, + subscriptionId, + recorder.configureClientOptions({}), + ); location = "eastus"; resourceGroup = "myjstest"; appservicePlanName = "myappserviceplanxxx"; name = "mysitexxxx"; }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it("operation list test", async function () { + it("operation list test", async () => { const resArray = new Array(); - for await (let item of client.provider.listOperations()) { + for await (const item of client.provider.listOperations()) { resArray.push(item); } assert.notEqual(resArray.length, 0); }); - it.skip("appServicePlans create test", async function () { - const res = await client.appServicePlans.beginCreateOrUpdateAndWait(resourceGroup, appservicePlanName, { - location, - sku: { - name: "S1", - tier: "STANDARD", - capacity: 1, + it.skip("appServicePlans create test", async () => { + const res = await client.appServicePlans.beginCreateOrUpdateAndWait( + resourceGroup, + appservicePlanName, + { + location, + sku: { + name: "S1", + tier: "STANDARD", + capacity: 1, + }, + perSiteScaling: false, + isXenon: false, }, - perSiteScaling: false, - isXenon: false - }, testPollingOptions) + testPollingOptions, + ); assert.equal(res.name, appservicePlanName); }); - it.skip("webApps create test", async function () { - const res = await client.webApps.beginCreateOrUpdateAndWait(resourceGroup, name, { - location, - serverFarmId: - "/subscriptions/" + - subscriptionId + - "/resourceGroups/myjstest/providers/Microsoft.Web/serverfarms/myappserviceplanxxx", - reserved: false, - isXenon: false, - hyperV: false, - siteConfig: { - netFrameworkVersion: "v4.6", - appSettings: [ - { - name: "WEBSITE_NODE_DEFAULT_VERSION", - value: "10.14", - }, - ], - localMySqlEnabled: false, - http20Enabled: true, + it.skip("webApps create test", async () => { + const res = await client.webApps.beginCreateOrUpdateAndWait( + resourceGroup, + name, + { + location, + serverFarmId: + "/subscriptions/" + + subscriptionId + + "/resourceGroups/myjstest/providers/Microsoft.Web/serverfarms/myappserviceplanxxx", + reserved: false, + isXenon: false, + hyperV: false, + siteConfig: { + netFrameworkVersion: "v4.6", + appSettings: [ + { + name: "WEBSITE_NODE_DEFAULT_VERSION", + value: "10.14", + }, + ], + localMySqlEnabled: false, + http20Enabled: true, + }, + scmSiteAlsoStopped: false, + httpsOnly: false, }, - scmSiteAlsoStopped: false, - httpsOnly: false - }, testPollingOptions) + testPollingOptions, + ); assert.equal(res.name, name); }); - it.skip("appServicePlans get test", async function () { + it.skip("appServicePlans get test", async () => { const res = await client.appServicePlans.get(resourceGroup, appservicePlanName); assert.equal(res.name, appservicePlanName); }); - it.skip("webApps get test", async function () { + it.skip("webApps get test", async () => { const res = await client.webApps.get(resourceGroup, name); assert.equal(res.name, name); }); - it.skip("appServicePlans list test", async function () { + it.skip("appServicePlans list test", async () => { const resArray = new Array(); - for await (let item of client.appServicePlans.listByResourceGroup(resourceGroup)) { + for await (const item of client.appServicePlans.listByResourceGroup(resourceGroup)) { resArray.push(item); } assert.equal(resArray.length, 1); }); - it.skip("webApps list test", async function () { + it.skip("webApps list test", async () => { const resArray = new Array(); - for await (let item of client.webApps.listByResourceGroup(resourceGroup)) { + for await (const item of client.webApps.listByResourceGroup(resourceGroup)) { resArray.push(item); } assert.equal(resArray.length, 1); }); - it.skip("webApps update test", async function () { + it.skip("webApps update test", async () => { const res = await client.webApps.update(resourceGroup, name, { - serverFarmId: "/subscriptions/" + subscriptionId + "/resourceGroups/myjstest/providers/Microsoft.Web/serverfarms/myappserviceplanxxx", + serverFarmId: + "/subscriptions/" + + subscriptionId + + "/resourceGroups/myjstest/providers/Microsoft.Web/serverfarms/myappserviceplanxxx", reserved: false, isXenon: false, hyperV: false, @@ -144,24 +157,24 @@ describe("Web test", () => { localMySqlEnabled: false, http20Enabled: true, }, - scmSiteAlsoStopped: false - }) + scmSiteAlsoStopped: false, + }); assert.equal(res.name, name); }); - it.skip("webApps delete test", async function () { + it.skip("webApps delete test", async () => { await client.webApps.delete(resourceGroup, name); const resArray = new Array(); - for await (let item of client.webApps.listByResourceGroup(resourceGroup)) { + for await (const item of client.webApps.listByResourceGroup(resourceGroup)) { resArray.push(item); } assert.equal(resArray.length, 0); }); - it.skip("appServicePlans delete test", async function () { + it.skip("appServicePlans delete test", async () => { await client.appServicePlans.delete(resourceGroup, appservicePlanName); const resArray = new Array(); - for await (let item of client.appServicePlans.listByResourceGroup(resourceGroup)) { + for await (const item of client.appServicePlans.listByResourceGroup(resourceGroup)) { resArray.push(item); } assert.equal(resArray.length, 0);