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

[template] Migrate template projects to use snippets extraction #33190

Merged
merged 35 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
555a50b
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
435dc03
Migration: Update test config
mpodwysocki Feb 25, 2025
d3ba900
Migration: Clean up files
mpodwysocki Feb 25, 2025
02f8deb
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
99cf0cc
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
2d7eb3b
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
d92d325
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
2affa4b
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
4b3de54
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
ad8c634
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
e6bdd00
Migration: npm run format
mpodwysocki Feb 25, 2025
e91a7cb
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
38c7a61
Migration: Update test config
mpodwysocki Feb 25, 2025
8981cb0
Migration: Clean up files
mpodwysocki Feb 25, 2025
d453c54
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
306c3ce
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
9412e12
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
1c881f3
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
e49e77b
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
f09640f
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
6357dd5
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
be38207
Migration: npm run format
mpodwysocki Feb 25, 2025
8163418
Migration: Update package.json, tsconfig.json, and api-extractor.json
mpodwysocki Feb 25, 2025
44ffc2f
Migration: Update test config
mpodwysocki Feb 25, 2025
a5fbc27
Migration: Clean up files
mpodwysocki Feb 25, 2025
9124d23
Migration: Apply codemod: "fixSourceFile"
mpodwysocki Feb 25, 2025
c592654
Migration: Apply codemod: "fixTestingImports"
mpodwysocki Feb 25, 2025
9d65e69
Migration: Apply codemod: "replaceAssertIsRejected"
mpodwysocki Feb 25, 2025
6e94e9c
Migration: Apply codemod: "replaceSinonStub"
mpodwysocki Feb 25, 2025
707529c
Migration: Apply codemod: "addViHelper"
mpodwysocki Feb 25, 2025
eb2dc60
Migration: Apply codemod: "replaceSupportTracing"
mpodwysocki Feb 25, 2025
c42bbf1
Migration: Apply codemod: "replaceTestUtils"
mpodwysocki Feb 25, 2025
659407b
Migration: npm run format
mpodwysocki Feb 25, 2025
9c2cefc
[template] Migrate template projects to use snippets extraction
mpodwysocki Feb 25, 2025
d1e9cb2
[template] Migrate template projects to use snippets extraction
mpodwysocki Feb 25, 2025
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
6 changes: 2 additions & 4 deletions sdk/template/template-dpg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Create several code examples for how someone would use your library to accomplis

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 All @@ -101,7 +101,5 @@ If you'd like to contribute to this library, please read the [contributing guide

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)



[azure_cli]: https://learn.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
19 changes: 10 additions & 9 deletions sdk/template/template-dpg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"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"
},
"files": [
"dist/",
Expand Down Expand Up @@ -118,23 +118,24 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.49.0",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"dependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure/core-auth": "^1.9.0",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-util": "^1.11.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
},
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
Expand All @@ -149,8 +150,8 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"browser": "./dist/browser/index.js"
"browser": "./dist/browser/index.js",
"react-native": "./dist/react-native/index.js"
}
6 changes: 2 additions & 4 deletions sdk/template/template-dpg/samples-dev/createWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
* @azsdk-weight 100
*/

import * as dotenv from "dotenv";
import "dotenv/config";
import { WidgetServiceClient } from "@azure/template-dpg";

// Load the .env file if it exists
dotenv.config();

const endpoint = process.env.WIDGET_SERVICE_ENDPOINT || "https://tsp-widgets.azurewebsites.net";

async function main() {
async function main(): Promise<void> {
const client = new WidgetServiceClient(endpoint);

// Create a new widget
Expand Down
9 changes: 3 additions & 6 deletions sdk/template/template-dpg/test/public/widgetService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ describe("WidgetServiceClient", () => {
describe("Widgets CRUD", () => {
it("should create a widget", async () => {
const widget = await client.createWidget(10, "red");
// eslint-disable-next-line no-unused-expressions
expect(widget).to.exist;
// eslint-disable-next-line no-unused-expressions
expect(widget.id).to.exist;
expect(widget).toBeDefined();
expect(widget.id).toBeDefined();
expect(widget.color).to.equal("red");
expect(widget.weight).to.equal(10);
});
Expand All @@ -88,8 +86,7 @@ describe("WidgetServiceClient", () => {
it("should update a widget", async () => {
const widget = await client.createWidget(10, "red");
const updatedWidget = await client.updateWidget(widget.id, { weight: 20 });
// eslint-disable-next-line no-unused-expressions
expect(updatedWidget).to.exist;
expect(updatedWidget).toBeDefined();
expect(updatedWidget.id).to.equal(widget.id);
expect(updatedWidget.color).to.equal("red");
expect(updatedWidget.weight).to.equal(20);
Expand Down
11 changes: 11 additions & 0 deletions sdk/template/template-dpg/test/snippets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { setLogLevel } from "@azure/logger";
import { describe, it } from "vitest";

describe("snippets", () => {
it("SetLogLevel", async () => {
setLogLevel("info");
});
});
12 changes: 9 additions & 3 deletions sdk/template/template-dpg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
{
"path": "./tsconfig.src.json"
},
{
"path": "./tsconfig.samples.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
4 changes: 2 additions & 2 deletions sdk/template/template-dpg/vitest.browser.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default mergeConfig(
defineConfig({
test: {
include: ["dist-test/browser/test/**/*.spec.js"],
hookTimeout: 500000,
testTimeout: 500000,
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
4 changes: 2 additions & 2 deletions sdk/template/template-dpg/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
hookTimeout: 500000,
testTimeout: 500000,
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
5 changes: 1 addition & 4 deletions sdk/template/template-dpg/vitest.esm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
export default mergeConfig(vitestConfig, vitestEsmConfig);
6 changes: 2 additions & 4 deletions sdk/template/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Create a section for each top-level service concept you want to explain.

Create several code examples for how someone would use your library to accomplish a common task with the service.

```ts snippet:new_configurationclient
```ts snippet:ReadmeSampleCreateClient
import { ConfigurationClient } from "@azure/template";
import { DefaultAzureCredential } from "@azure/identity";

Expand All @@ -91,7 +91,7 @@ const client = new ConfigurationClient(

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`:

```ts snippet:setloglevel
```ts snippet:SetLogLevel
import { setLogLevel } from "@azure/logger";

setLogLevel("verbose");
Expand All @@ -111,7 +111,5 @@ If you'd like to contribute to this library, please read the [contributing guide

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)



[azure_cli]: https://learn.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
2 changes: 1 addition & 1 deletion sdk/template/template/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./dist/template.d.ts"
"publicTrimmedFilePath": "dist/template.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand Down
38 changes: 20 additions & 18 deletions sdk/template/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"test:browser": "npm run clean && npm run integration-test:browser",
"test:node": "npm run clean && npm run build:test && npm run integration-test:node",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "npm run integration-test:browser",
"unit-test:node": "npm run integration-test:node",
"update-snippets": "dev-tool run build-package && dev-tool run update-snippets"
"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": "dev-tool run update-snippets"
},
"files": [
"dist/",
Expand All @@ -80,32 +80,33 @@
"sideEffects": false,
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
"dependencies": {
"@azure/core-auth": "^1.3.0",
"@azure/core-client": "^1.4.0",
"@azure/core-auth": "^1.9.0",
"@azure/core-client": "^1.9.2",
"@azure/core-lro": "^2.7.0",
"@azure/core-rest-pipeline": "^1.4.0",
"@azure/core-tracing": "^1.0.0",
"@azure/logger": "^1.0.0",
"tslib": "^2.6.2"
"@azure/core-rest-pipeline": "^1.19.0",
"@azure/core-tracing": "^1.2.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
},
"devDependencies": {
"@azure-tools/test-credential": "^2.0.0",
"@azure-tools/test-recorder": "^4.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure-tools/vite-plugin-browser-test-map": "^1.0.0",
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.5.0",
"@azure/identity": "^4.7.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^3.0.3",
"@vitest/coverage-istanbul": "^3.0.3",
"@vitest/browser": "^3.0.6",
"@vitest/coverage-istanbul": "^3.0.6",
"dotenv": "^16.0.0",
"eslint": "^9.9.0",
"playwright": "^1.41.2",
"playwright": "^1.50.1",
"typescript": "~5.7.2",
"vitest": "^3.0.3"
"vitest": "^3.0.6"
},
"tshy": {
"project": "./tsconfig.src.json",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
Expand All @@ -118,8 +119,7 @@
"browser",
"react-native"
],
"selfLink": false,
"project": "./tsconfig.src.json"
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
Expand All @@ -143,5 +143,7 @@
}
},
"type": "module",
"module": "./dist/esm/index.js"
"module": "./dist/esm/index.js",
"browser": "./dist/browser/index.js",
"react-native": "./dist/react-native/index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { ConfigurationClient } from "@azure/template";
import { DefaultAzureCredential } from "@azure/identity";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.APPCONFIG_ENDPOINT || "<endpoint>";
const key = process.env.APPCONFIG_TEST_SETTING_KEY || "<test-key>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { ConfigurationClient } from "@azure/template";
import { DefaultAzureCredential } from "@azure/identity";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();
import "dotenv/config";

async function main() {
async function main(): Promise<void> {
const endpoint = process.env.APPCONFIG_ENDPOINT || "<endpoint>";
const key = process.env.APPCONFIG_TEST_SETTING_KEY || "<test-key>";

Expand Down
2 changes: 1 addition & 1 deletion sdk/template/template/src/configurationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ConfigurationClient {
* Creates an instance of a ConfigurationClient.
*
* Example usage:
* ```ts snippet:new_configurationclient
* ```ts snippet:ReadmeSampleCreateClient
* import { ConfigurationClient } from "@azure/template";
* import { DefaultAzureCredential } from "@azure/identity";
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("[AAD] ConfigurationClient functional tests", function () {
// NOTE: use of "function" and not ES6 arrow-style functions with the
// beforeEach hook is IMPORTANT due to the use of `this` in the function
// body.
beforeEach(async function (context) {
beforeEach(async (context) => {
// The recorder has some convenience methods, and we need to store a
// reference to it so that we can `stop()` the recorder later in the
// `afterEach` hook.
Expand All @@ -74,7 +74,7 @@ describe("[AAD] ConfigurationClient functional tests", function () {
});

// After each test, we need to stop the recording.
afterEach(async function () {
afterEach(async () => {
await recorder.stop();
});

Expand Down
4 changes: 2 additions & 2 deletions sdk/template/template/test/snippets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { ConfigurationClient } from "../src/index.js";
import { describe, it } from "vitest";

describe("snippets", function () {
it("new_configurationclient", function () {
it("ReadmeSampleCreateClient", () => {
const client = new ConfigurationClient(
process.env.ENDPOINT ?? "<app configuration endpoint>",
new DefaultAzureCredential(),
);
});

it("setloglevel", () => {
it("SetLogLevel", () => {
setLogLevel("verbose");
});
});
12 changes: 9 additions & 3 deletions sdk/template/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
{
"path": "./tsconfig.src.json"
},
{
"path": "./tsconfig.samples.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
7 changes: 3 additions & 4 deletions sdk/template/template/vitest.browser.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
include: [
"dist-test/browser/test/internal/**/*.spec.js",
"dist-test/browser/test/public/**/*.spec.js",
],
include: ["dist-test/browser/test/**/*.spec.js"],
testTimeout: 1200000,
hookTimeout: 1200000,
},
}),
);
Loading