Skip to content

Commit 9d4b052

Browse files
authored
[template] Migrate template projects to use snippets extraction (#33190)
### Packages impacted by this PR - @azure/template - @azure/template-dpg ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under `template` to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 12f2ec3 commit 9d4b052

21 files changed

+97
-80
lines changed

sdk/template/template-dpg/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Create several code examples for how someone would use your library to accomplis
8181

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

84-
```javascript
85-
const { setLogLevel } = require("@azure/logger");
84+
```ts snippet:SetLogLevel
85+
import { setLogLevel } from "@azure/logger";
8686

8787
setLogLevel("info");
8888
```
@@ -101,7 +101,5 @@ If you'd like to contribute to this library, please read the [contributing guide
101101

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

104-
105-
106104
[azure_cli]: https://learn.microsoft.com/cli/azure
107105
[azure_sub]: https://azure.microsoft.com/free/

sdk/template/template-dpg/package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8888
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
8989
"unit-test:node": "dev-tool run test:vitest",
90-
"update-snippets": "echo skipped"
90+
"update-snippets": "dev-tool run update-snippets"
9191
},
9292
"files": [
9393
"dist/",
@@ -118,23 +118,24 @@
118118
"@azure/dev-tool": "^1.0.0",
119119
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
120120
"@types/node": "^18.0.0",
121-
"@vitest/browser": "^3.0.3",
122-
"@vitest/coverage-istanbul": "^3.0.3",
121+
"@vitest/browser": "^3.0.6",
122+
"@vitest/coverage-istanbul": "^3.0.6",
123123
"dotenv": "^16.0.0",
124124
"eslint": "^9.9.0",
125-
"playwright": "^1.49.0",
125+
"playwright": "^1.50.1",
126126
"typescript": "~5.7.2",
127-
"vitest": "^3.0.3"
127+
"vitest": "^3.0.6"
128128
},
129129
"dependencies": {
130130
"@azure-rest/core-client": "^2.3.1",
131131
"@azure/core-auth": "^1.9.0",
132-
"@azure/core-rest-pipeline": "^1.18.0",
132+
"@azure/core-rest-pipeline": "^1.19.0",
133133
"@azure/core-util": "^1.11.0",
134134
"@azure/logger": "^1.1.4",
135135
"tslib": "^2.8.1"
136136
},
137137
"tshy": {
138+
"project": "./tsconfig.src.json",
138139
"exports": {
139140
"./package.json": "./package.json",
140141
".": "./src/index.ts",
@@ -149,8 +150,8 @@
149150
"browser",
150151
"react-native"
151152
],
152-
"selfLink": false,
153-
"project": "./tsconfig.src.json"
153+
"selfLink": false
154154
},
155-
"browser": "./dist/browser/index.js"
155+
"browser": "./dist/browser/index.js",
156+
"react-native": "./dist/react-native/index.js"
156157
}

sdk/template/template-dpg/samples-dev/createWidget.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
* @azsdk-weight 100
1010
*/
1111

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

1515
// Load the .env file if it exists
16-
dotenv.config();
17-
1816
const endpoint = process.env.WIDGET_SERVICE_ENDPOINT || "https://tsp-widgets.azurewebsites.net";
1917

20-
async function main() {
18+
async function main(): Promise<void> {
2119
const client = new WidgetServiceClient(endpoint);
2220

2321
// Create a new widget

sdk/template/template-dpg/test/public/widgetService.spec.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ describe("WidgetServiceClient", () => {
7171
describe("Widgets CRUD", () => {
7272
it("should create a widget", async () => {
7373
const widget = await client.createWidget(10, "red");
74-
// eslint-disable-next-line no-unused-expressions
75-
expect(widget).to.exist;
76-
// eslint-disable-next-line no-unused-expressions
77-
expect(widget.id).to.exist;
74+
expect(widget).toBeDefined();
75+
expect(widget.id).toBeDefined();
7876
expect(widget.color).to.equal("red");
7977
expect(widget.weight).to.equal(10);
8078
});
@@ -88,8 +86,7 @@ describe("WidgetServiceClient", () => {
8886
it("should update a widget", async () => {
8987
const widget = await client.createWidget(10, "red");
9088
const updatedWidget = await client.updateWidget(widget.id, { weight: 20 });
91-
// eslint-disable-next-line no-unused-expressions
92-
expect(updatedWidget).to.exist;
89+
expect(updatedWidget).toBeDefined();
9390
expect(updatedWidget.id).to.equal(widget.id);
9491
expect(updatedWidget.color).to.equal("red");
9592
expect(updatedWidget.weight).to.equal(20);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { setLogLevel } from "@azure/logger";
5+
import { describe, it } from "vitest";
6+
7+
describe("snippets", () => {
8+
it("SetLogLevel", async () => {
9+
setLogLevel("info");
10+
});
11+
});
+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"references": [
3-
{ "path": "./tsconfig.src.json" },
4-
{ "path": "./tsconfig.samples.json" },
5-
{ "path": "./tsconfig.test.json" }
3+
{
4+
"path": "./tsconfig.src.json"
5+
},
6+
{
7+
"path": "./tsconfig.samples.json"
8+
},
9+
{
10+
"path": "./tsconfig.test.json"
11+
}
612
]
713
}

sdk/template/template-dpg/vitest.browser.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default mergeConfig(
99
defineConfig({
1010
test: {
1111
include: ["dist-test/browser/test/**/*.spec.js"],
12-
hookTimeout: 500000,
13-
testTimeout: 500000,
12+
testTimeout: 1200000,
13+
hookTimeout: 1200000,
1414
},
1515
}),
1616
);

sdk/template/template-dpg/vitest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default mergeConfig(
88
viteConfig,
99
defineConfig({
1010
test: {
11-
hookTimeout: 500000,
12-
testTimeout: 500000,
11+
testTimeout: 1200000,
12+
hookTimeout: 1200000,
1313
},
1414
}),
1515
);

sdk/template/template-dpg/vitest.esm.config.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ import { mergeConfig } from "vitest/config";
55
import vitestConfig from "./vitest.config.ts";
66
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";
77

8-
export default mergeConfig(
9-
vitestConfig,
10-
vitestEsmConfig
11-
);
8+
export default mergeConfig(vitestConfig, vitestEsmConfig);

sdk/template/template/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Create a section for each top-level service concept you want to explain.
7575

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

78-
```ts snippet:new_configurationclient
78+
```ts snippet:ReadmeSampleCreateClient
7979
import { ConfigurationClient } from "@azure/template";
8080
import { DefaultAzureCredential } from "@azure/identity";
8181

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

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

94-
```ts snippet:setloglevel
94+
```ts snippet:SetLogLevel
9595
import { setLogLevel } from "@azure/logger";
9696

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

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

114-
115-
116114
[azure_cli]: https://learn.microsoft.com/cli/azure
117115
[azure_sub]: https://azure.microsoft.com/free/

sdk/template/template/api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dtsRollup": {
1212
"enabled": true,
1313
"untrimmedFilePath": "",
14-
"publicTrimmedFilePath": "./dist/template.d.ts"
14+
"publicTrimmedFilePath": "dist/template.d.ts"
1515
},
1616
"messages": {
1717
"tsdocMessageReporting": {

sdk/template/template/package.json

+20-18
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"test:browser": "npm run clean && npm run integration-test:browser",
5454
"test:node": "npm run clean && npm run build:test && npm run integration-test:node",
5555
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
56-
"unit-test:browser": "npm run integration-test:browser",
57-
"unit-test:node": "npm run integration-test:node",
58-
"update-snippets": "dev-tool run build-package && dev-tool run update-snippets"
56+
"unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
57+
"unit-test:node": "dev-tool run test:vitest",
58+
"update-snippets": "dev-tool run update-snippets"
5959
},
6060
"files": [
6161
"dist/",
@@ -80,32 +80,33 @@
8080
"sideEffects": false,
8181
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
8282
"dependencies": {
83-
"@azure/core-auth": "^1.3.0",
84-
"@azure/core-client": "^1.4.0",
83+
"@azure/core-auth": "^1.9.0",
84+
"@azure/core-client": "^1.9.2",
8585
"@azure/core-lro": "^2.7.0",
86-
"@azure/core-rest-pipeline": "^1.4.0",
87-
"@azure/core-tracing": "^1.0.0",
88-
"@azure/logger": "^1.0.0",
89-
"tslib": "^2.6.2"
86+
"@azure/core-rest-pipeline": "^1.19.0",
87+
"@azure/core-tracing": "^1.2.0",
88+
"@azure/logger": "^1.1.4",
89+
"tslib": "^2.8.1"
9090
},
9191
"devDependencies": {
9292
"@azure-tools/test-credential": "^2.0.0",
93-
"@azure-tools/test-recorder": "^4.0.0",
93+
"@azure-tools/test-recorder": "^4.1.0",
9494
"@azure-tools/test-utils-vitest": "^1.0.0",
9595
"@azure-tools/vite-plugin-browser-test-map": "^1.0.0",
9696
"@azure/dev-tool": "^1.0.0",
9797
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
98-
"@azure/identity": "^4.5.0",
98+
"@azure/identity": "^4.7.0",
9999
"@types/node": "^18.0.0",
100-
"@vitest/browser": "^3.0.3",
101-
"@vitest/coverage-istanbul": "^3.0.3",
100+
"@vitest/browser": "^3.0.6",
101+
"@vitest/coverage-istanbul": "^3.0.6",
102102
"dotenv": "^16.0.0",
103103
"eslint": "^9.9.0",
104-
"playwright": "^1.41.2",
104+
"playwright": "^1.50.1",
105105
"typescript": "~5.7.2",
106-
"vitest": "^3.0.3"
106+
"vitest": "^3.0.6"
107107
},
108108
"tshy": {
109+
"project": "./tsconfig.src.json",
109110
"exports": {
110111
"./package.json": "./package.json",
111112
".": "./src/index.ts"
@@ -118,8 +119,7 @@
118119
"browser",
119120
"react-native"
120121
],
121-
"selfLink": false,
122-
"project": "./tsconfig.src.json"
122+
"selfLink": false
123123
},
124124
"exports": {
125125
"./package.json": "./package.json",
@@ -143,5 +143,7 @@
143143
}
144144
},
145145
"type": "module",
146-
"module": "./dist/esm/index.js"
146+
"module": "./dist/esm/index.js",
147+
"browser": "./dist/browser/index.js",
148+
"react-native": "./dist/react-native/index.js"
147149
}

sdk/template/template/samples-dev/getConfigurationSetting.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import { ConfigurationClient } from "@azure/template";
99
import { DefaultAzureCredential } from "@azure/identity";
1010

1111
// Load the .env file if it exists
12-
import * as dotenv from "dotenv";
13-
dotenv.config();
12+
import "dotenv/config";
1413

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

sdk/template/template/samples/v1-beta/typescript/src/getConfigurationSetting.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import { ConfigurationClient } from "@azure/template";
99
import { DefaultAzureCredential } from "@azure/identity";
1010

1111
// Load the .env file if it exists
12-
import * as dotenv from "dotenv";
13-
dotenv.config();
12+
import "dotenv/config";
1413

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

sdk/template/template/src/configurationClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ConfigurationClient {
5151
* Creates an instance of a ConfigurationClient.
5252
*
5353
* Example usage:
54-
* ```ts snippet:new_configurationclient
54+
* ```ts snippet:ReadmeSampleCreateClient
5555
* import { ConfigurationClient } from "@azure/template";
5656
* import { DefaultAzureCredential } from "@azure/identity";
5757
*

sdk/template/template/test/public/configurationClient.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("[AAD] ConfigurationClient functional tests", function () {
5555
// NOTE: use of "function" and not ES6 arrow-style functions with the
5656
// beforeEach hook is IMPORTANT due to the use of `this` in the function
5757
// body.
58-
beforeEach(async function (context) {
58+
beforeEach(async (context) => {
5959
// The recorder has some convenience methods, and we need to store a
6060
// reference to it so that we can `stop()` the recorder later in the
6161
// `afterEach` hook.
@@ -74,7 +74,7 @@ describe("[AAD] ConfigurationClient functional tests", function () {
7474
});
7575

7676
// After each test, we need to stop the recording.
77-
afterEach(async function () {
77+
afterEach(async () => {
7878
await recorder.stop();
7979
});
8080

sdk/template/template/test/snippets.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { ConfigurationClient } from "../src/index.js";
77
import { describe, it } from "vitest";
88

99
describe("snippets", function () {
10-
it("new_configurationclient", function () {
10+
it("ReadmeSampleCreateClient", () => {
1111
const client = new ConfigurationClient(
1212
process.env.ENDPOINT ?? "<app configuration endpoint>",
1313
new DefaultAzureCredential(),
1414
);
1515
});
1616

17-
it("setloglevel", () => {
17+
it("SetLogLevel", () => {
1818
setLogLevel("verbose");
1919
});
2020
});

sdk/template/template/tsconfig.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"references": [
3-
{ "path": "./tsconfig.src.json" },
4-
{ "path": "./tsconfig.samples.json" },
5-
{ "path": "./tsconfig.test.json" }
3+
{
4+
"path": "./tsconfig.src.json"
5+
},
6+
{
7+
"path": "./tsconfig.samples.json"
8+
},
9+
{
10+
"path": "./tsconfig.test.json"
11+
}
612
]
713
}

sdk/template/template/vitest.browser.config.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ export default mergeConfig(
88
viteConfig,
99
defineConfig({
1010
test: {
11-
include: [
12-
"dist-test/browser/test/internal/**/*.spec.js",
13-
"dist-test/browser/test/public/**/*.spec.js",
14-
],
11+
include: ["dist-test/browser/test/**/*.spec.js"],
12+
testTimeout: 1200000,
13+
hookTimeout: 1200000,
1514
},
1615
}),
1716
);

0 commit comments

Comments
 (0)