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

[changes] Update changes projects to use snippet extraction #32551

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 21 additions & 12 deletions sdk/changes/arm-changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ChangesClient } = require("@azure/arm-changes");
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 { ChangesClient } from "@azure/arm-changes";
import { DefaultAzureCredential } from "@azure/identity";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const client = new ChangesClient(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: "<YOUR_TENANT_ID>",
// clientId: "<YOUR_CLIENT_ID>"
// });
// const client = new ChangesClient(credential, subscriptionId);
```ts snippet:ReadmeSampleCreateClient_Browser
import { InteractiveBrowserCredential } from "@azure/identity";
import { ChangesClient } from "@azure/arm-changes";

const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new ChangesClient(credential, subscriptionId);
```

### JavaScript Bundle
Expand All @@ -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");
```

Expand Down
22 changes: 10 additions & 12 deletions sdk/changes/arm-changes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
"node": ">=18.0.0"
},
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.6.1",
"@azure/core-paging": "^1.2.0",
"@azure/core-rest-pipeline": "^1.8.0",
"tslib": "^2.2.0"
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.2",
"tslib": "^2.8.1"
},
"keywords": [
"node",
"azure",
"typescript",
"browser",
"isomorphic"
"isomorphic",
"cloud"
],
"license": "MIT",
"main": "./dist/commonjs/index.js",
Expand All @@ -30,7 +31,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",
Expand All @@ -39,10 +40,7 @@
"vitest": "^2.1.8"
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/changes/arm-changes",
"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"
},
Expand Down Expand Up @@ -77,7 +75,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": {
Expand Down
18 changes: 8 additions & 10 deletions sdk/changes/arm-changes/test/sampleTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
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 = {
Expand All @@ -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);
});
});
27 changes: 27 additions & 0 deletions sdk/changes/arm-changes/test/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { ChangesClient } from "../src/index.js";
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 ChangesClient(new DefaultAzureCredential(), subscriptionId);
});

it("ReadmeSampleCreateClient_Browser", async () => {
const subscriptionId = "00000000-0000-0000-0000-000000000000";
const credential = new InteractiveBrowserCredential({
tenantId: "<YOUR_TENANT_ID>",
clientId: "<YOUR_CLIENT_ID>",
});
const client = new ChangesClient(credential, subscriptionId);
});

it("SetLogLevel", async () => {
setLogLevel("info");
});
});
Loading