From f2a6749830117f70c9f38d885aea1655fd7f3d0b Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 3 Dec 2024 19:46:52 -0500 Subject: [PATCH] [iot] Migrate @azure-rest/iot-device-update to ESM/vitest (#32039) ### Packages impacted by this PR - @azure-rest/iot-device-update ### Issues associated with this PR - https://github.com/Azure/azure-sdk-for-js/issues/31338 ### Describe the problem that is addressed by this PR Migrates @azure-rest/iot-device-update to ESM/vitest using automation. ### 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) --- common/config/rush/pnpm-lock.yaml | 24 +++- .../iot-device-update-rest/api-extractor.json | 27 +++- .../iot-device-update-rest/karma.conf.js | 130 ------------------ .../iot-device-update-rest/package.json | 113 ++++++++------- .../samples-dev/deleteUpdate.ts | 6 +- .../samples-dev/deployUpdate.ts | 4 +- .../samples-dev/getDevice.ts | 6 +- .../samples-dev/getUpdate.ts | 6 +- .../samples-dev/importUpdate.ts | 17 +-- .../samples-dev/listUpdates.ts | 14 +- .../src/clientDefinitions.ts | 4 +- .../src/deviceUpdate.ts | 2 +- .../iot-device-update-rest/src/index.ts | 21 +-- .../src/isUnexpected.ts | 2 +- .../iot-device-update-rest/src/parameters.ts | 2 +- .../iot-device-update-rest/src/responses.ts | 2 +- .../test/public/management.spec.ts | 39 +++--- .../test/public/update.spec.ts | 35 +++-- .../test/public/utils/recordedClient.ts | 4 +- .../tsconfig.browser.config.json | 10 ++ .../iot-device-update-rest/tsconfig.json | 17 ++- .../vitest.browser.config.ts | 16 +++ .../iot-device-update-rest/vitest.config.ts | 16 +++ 23 files changed, 234 insertions(+), 283 deletions(-) delete mode 100644 sdk/deviceupdate/iot-device-update-rest/karma.conf.js create mode 100644 sdk/deviceupdate/iot-device-update-rest/tsconfig.browser.config.json create mode 100644 sdk/deviceupdate/iot-device-update-rest/vitest.browser.config.ts create mode 100644 sdk/deviceupdate/iot-device-update-rest/vitest.config.ts diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 6cb2cdb18f71..71426bef4b6a 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -20682,7 +20682,7 @@ packages: dev: false file:projects/iot-device-update.tgz: - resolution: {integrity: sha512-j+/7pjRuxaNdX1fkGEa6LLEMmGp6LDV6z5RimV7GRnBRVlrYBgK3bfd4YdqYdNrg5Z4aksGwIcU+dt4Q+/yzRg==, tarball: file:projects/iot-device-update.tgz} + resolution: {integrity: sha512-/KAKSZD3InlQSaS4sF7RFi5sxZH+38eHjRbVP6/AzVtzz6e9cR9rAJvG9ffbEEodn0znE1We00qAVbMQQB0dqg==, tarball: file:projects/iot-device-update.tgz} name: '@rush-temp/iot-device-update' version: 0.0.0 dependencies: @@ -20693,6 +20693,8 @@ packages: '@types/chai': 4.3.20 '@types/mocha': 10.0.10 '@types/node': 18.19.67 + '@vitest/browser': 2.1.8(@types/node@18.19.67)(playwright@1.49.0)(typescript@5.6.3)(vitest@2.1.8) + '@vitest/coverage-istanbul': 2.1.8(vitest@2.1.8) chai: 4.3.10 dotenv: 16.4.5 eslint: 9.16.0 @@ -20710,18 +20712,32 @@ packages: karma-sourcemap-loader: 0.3.8 mocha: 10.8.2 nyc: 17.1.0 + playwright: 1.49.0 source-map-support: 0.5.21 ts-node: 10.9.2(@types/node@18.19.67)(typescript@5.6.3) tslib: 2.8.1 typescript: 5.6.3 + vitest: 2.1.8(@types/node@18.19.67)(@vitest/browser@2.1.8) transitivePeerDependencies: - - '@swc/core' - - '@swc/wasm' + - '@edge-runtime/vm' + - '@vitest/ui' - bufferutil - - debug + - happy-dom - jiti + - jsdom + - less + - lightningcss + - msw + - safaridriver + - sass + - sass-embedded + - stylus + - sugarss - supports-color + - terser - utf-8-validate + - vite + - webdriverio dev: false file:projects/iot-modelsrepository.tgz: diff --git a/sdk/deviceupdate/iot-device-update-rest/api-extractor.json b/sdk/deviceupdate/iot-device-update-rest/api-extractor.json index 32ca74659454..91c23d35c008 100644 --- a/sdk/deviceupdate/iot-device-update-rest/api-extractor.json +++ b/sdk/deviceupdate/iot-device-update-rest/api-extractor.json @@ -1,18 +1,31 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "./types/src/index.d.ts", - "docModel": { "enabled": true }, - "apiReport": { "enabled": true, "reportFolder": "./review" }, + "mainEntryPointFilePath": "dist/esm/index.d.ts", + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, "dtsRollup": { "enabled": true, "untrimmedFilePath": "", - "publicTrimmedFilePath": "./types/iot-device-update.d.ts" + "publicTrimmedFilePath": "dist/iot-device-update.d.ts" }, "messages": { - "tsdocMessageReporting": { "default": { "logLevel": "none" } }, + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, "extractorMessageReporting": { - "ae-missing-release-tag": { "logLevel": "none" }, - "ae-unresolved-link": { "logLevel": "none" } + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } } } } diff --git a/sdk/deviceupdate/iot-device-update-rest/karma.conf.js b/sdk/deviceupdate/iot-device-update-rest/karma.conf.js deleted file mode 100644 index e2dc84ef207d..000000000000 --- a/sdk/deviceupdate/iot-device-update-rest/karma.conf.js +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); -// https://github.com/karma-runner/karma-chrome-launcher -process.env.CHROME_BIN = require("puppeteer").executablePath(); -process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); - -require("dotenv").config(); - -module.exports = function (config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: "./", - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ["source-map-support", "mocha"], - - plugins: [ - "karma-mocha", - "karma-mocha-reporter", - "karma-chrome-launcher", - "karma-firefox-launcher", - "karma-env-preprocessor", - "karma-coverage", - "karma-sourcemap-loader", - "karma-junit-reporter", - "karma-json-to-file-reporter", - "karma-source-map-support", - "karma-json-preprocessor", - ], - - // list of files / patterns to load in the browser - files: [ - "dist-test/index.browser.js", - { pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true }, - ], - - // list of files / patterns to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - "**/*.js": ["sourcemap", "env"], - "recordings/browsers/**/*.json": ["json"], - // IMPORTANT: COMMENT following line if you want to debug in your browsers!! - // Preprocess source file to calculate code coverage, however this will make source file unreadable - // "dist-test/index.js": ["coverage"] - }, - - envPreprocessor: [ - "TEST_MODE", - "ENDPOINT", - "AZURE_CLIENT_SECRET", - "AZURE_CLIENT_ID", - "AZURE_TENANT_ID", - "RECORDINGS_RELATIVE_PATH", - ], - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ["mocha", "coverage", "junit"], - - coverageReporter: { - // specify a common output directory - dir: "coverage-browser/", - reporters: [ - { type: "json", subdir: ".", file: "coverage.json" }, - { type: "lcovonly", subdir: ".", file: "lcov.info" }, - { type: "html", subdir: "html" }, - { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }, - ], - }, - - junitReporter: { - outputDir: "", // results will be saved as $outputDir/$browserName.xml - outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile - suite: "", // suite will become the package name attribute in xml testsuite element - useBrowserName: false, // add browser name to report and classes names - nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element - classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element - properties: {}, // key value pair of properties to add to the section of the report - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // --no-sandbox allows our tests to run in Linux without having to change the system. - // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex. - browsers: ["ChromeHeadlessNoSandbox"], - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: "ChromeHeadless", - flags: ["--no-sandbox", "--disable-web-security"], - }, - }, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: 1, - - browserNoActivityTimeout: 60000000, - browserDisconnectTimeout: 10000, - browserDisconnectTolerance: 3, - - client: { - mocha: { - // change Karma's debug.html to the mocha web reporter - reporter: "html", - timeout: "600000", - }, - }, - }); -}; diff --git a/sdk/deviceupdate/iot-device-update-rest/package.json b/sdk/deviceupdate/iot-device-update-rest/package.json index 13c88019110f..844881b21dcb 100644 --- a/sdk/deviceupdate/iot-device-update-rest/package.json +++ b/sdk/deviceupdate/iot-device-update-rest/package.json @@ -13,9 +13,9 @@ "isomorphic" ], "license": "MIT", - "main": "dist/index.js", - "module": "./dist-esm/src/index.js", - "types": "./types/iot-device-update.d.ts", + "main": "./dist/commonjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/commonjs/index.d.ts", "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/deviceupdate/iot-device-update-rest/README.md", "repository": "github:Azure/azure-sdk-for-js", "bugs": { @@ -23,11 +23,8 @@ }, "files": [ "dist/", - "dist-esm/src/", - "types/iot-device-update.d.ts", "README.md", - "LICENSE", - "review/*" + "LICENSE" ], "//metadata": { "constantPaths": [ @@ -51,16 +48,11 @@ "disableDocsMs": true, "apiRefLink": "https://docs.microsoft.com/rest/api/deviceupdate/2021-06-01-preview/device-update" }, - "browser": { - "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" - }, + "browser": "./dist/browser/index.js", "scripts": { - "build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", - "build:browser": "tsc -p . && dev-tool run bundle", - "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api", - "build:node": "tsc -p . && dev-tool run bundle", + "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", "build:samples": "echo Obsolete.", - "build:test": "tsc -p . && dev-tool run bundle", + "build:test": "echo Obsolete.", "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "dev-tool samples run samples-dev", @@ -68,8 +60,8 @@ "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "generate:client": "autorest --typescript swagger/README.md && npm run format", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:browser": "dev-tool run test:browser", - "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'", + "integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", + "integration-test:node": "dev-tool run test:vitest", "lint": "eslint package.json api-extractor.json src test", "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", @@ -77,50 +69,73 @@ "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", "test:node": "npm run clean && npm run build:test && npm run unit-test:node", "unit-test": "npm run unit-test:node && npm run unit-test:browser", - "unit-test:browser": "dev-tool run test:browser", - "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", + "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" }, "sideEffects": false, "autoPublish": false, "dependencies": { - "@azure-rest/core-client": "^1.0.0", - "@azure/core-auth": "^1.3.0", - "@azure/core-lro": "^2.2.0", - "@azure/core-paging": "^1.2.0", - "@azure/core-rest-pipeline": "^1.8.0", - "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "@azure-rest/core-client": "^2.3.1", + "@azure/core-auth": "^1.9.0", + "@azure/core-lro": "^2.7.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.0", + "@azure/logger": "^1.1.4", + "tslib": "^2.8.1" }, "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.0.0", - "@azure/core-util": "^1.6.1", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.1.0", + "@azure-tools/test-utils-vitest": "^1.0.0", + "@azure/core-util": "^1.11.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/identity": "^4.0.1", - "@types/chai": "^4.1.6", - "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", - "chai": "^4.2.0", + "@vitest/browser": "^2.1.8", + "@vitest/coverage-istanbul": "^2.1.8", "dotenv": "^16.0.0", "eslint": "^9.9.0", - "karma": "^6.2.0", - "karma-chrome-launcher": "^3.0.0", - "karma-coverage": "^2.0.0", - "karma-env-preprocessor": "^0.1.1", - "karma-firefox-launcher": "^2.1.3", - "karma-json-preprocessor": "^0.3.3", - "karma-json-to-file-reporter": "^1.0.1", - "karma-junit-reporter": "^2.0.1", - "karma-mocha": "^2.0.1", - "karma-mocha-reporter": "^2.2.5", - "karma-source-map-support": "~1.4.0", - "karma-sourcemap-loader": "^0.3.8", - "mocha": "^10.0.0", - "nyc": "^17.0.0", - "source-map-support": "^0.5.9", - "ts-node": "^10.0.0", - "typescript": "~5.6.2" + "playwright": "^1.49.0", + "typescript": "~5.6.2", + "vitest": "^2.1.8" + }, + "type": "module", + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false + }, + "exports": { + "./package.json": "./package.json", + ".": { + "browser": { + "types": "./dist/browser/index.d.ts", + "default": "./dist/browser/index.js" + }, + "react-native": { + "types": "./dist/react-native/index.d.ts", + "default": "./dist/react-native/index.js" + }, + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } + } } } diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/deleteUpdate.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/deleteUpdate.ts index 23fdca992526..fdc9dac1a2a2 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/deleteUpdate.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/deleteUpdate.ts @@ -11,14 +11,12 @@ import DeviceUpdate, { getLongRunningPoller, isUnexpected } from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; -import dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; -async function main() { +async function main(): Promise { console.log("== Delete update =="); const updateProvider = process.env["DEVICEUPDATE_UPDATE_PROVIDER"] || ""; const updateName = process.env["DEVICEUPDATE_UPDATE_NAME"] || ""; diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/deployUpdate.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/deployUpdate.ts index 667d947e286d..9c5f28c91d05 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/deployUpdate.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/deployUpdate.ts @@ -11,10 +11,8 @@ import DeviceUpdate, { getLongRunningPoller, isUnexpected } from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; -import dotenv from "dotenv"; import { randomUUID } from "@azure/core-util"; - -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/getDevice.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/getDevice.ts index 2385eb410d43..569890f143f2 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/getDevice.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/getDevice.ts @@ -10,14 +10,12 @@ import DeviceUpdate, { isUnexpected, paginate } from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; -import dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; -async function main() { +async function main(): Promsie { console.log("== Get device =="); const groupId = process.env["DEVICEUPDATE_DEVICE_GROUP"] || ""; diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/getUpdate.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/getUpdate.ts index a1f8d026fd4a..5b780e83d63e 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/getUpdate.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/getUpdate.ts @@ -10,14 +10,12 @@ import DeviceUpdate, { isUnexpected } from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; -import dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; -async function main() { +async function main(): Promise { console.log("== Get update =="); const provider = process.env["DEVICEUPDATE_UPDATE_PROVIDER"] || ""; const name = process.env["DEVICEUPDATE_UPDATE_NAME"] || ""; diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/importUpdate.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/importUpdate.ts index 6ffe6d254653..f3d572825b02 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/importUpdate.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/importUpdate.ts @@ -9,19 +9,16 @@ */ import DeviceUpdate, { getLongRunningPoller, isUnexpected } from "@azure-rest/iot-device-update"; -import { readFileSync, statSync } from "fs"; - +import { readFileSync, statSync } from "node:fs"; import { DefaultAzureCredential } from "@azure/identity"; import { computeSha256Hash } from "@azure/core-util"; -import dotenv from "dotenv"; -import { parse } from "path"; - -dotenv.config(); +import { parse } from "node:path"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; -async function main() { +async function main(): Promise { console.log("== Import update =="); const payloadFile = process.env["DEVICEUPDATE_PAYLOAD_FILE"] || ""; const payloadUrl = process.env["DEVICEUPDATE_PAYLOAD_URL"] || ""; @@ -68,17 +65,17 @@ async function main() { console.log(`Import succeeded!`); } -function getFileSize(filePath: string) { +function getFileSize(filePath: string): number { const stats = statSync(filePath); return stats.size; } -function getFileName(filePath: string) { +function getFileName(filePath: string): string { const fileName = parse(filePath).base; return fileName; } -function getFileHash(filePath: string) { +function getFileHash(filePath: string): Promise { const fileContent = readFileSync(filePath, { encoding: "utf8" }); return computeSha256Hash(fileContent, "base64"); } diff --git a/sdk/deviceupdate/iot-device-update-rest/samples-dev/listUpdates.ts b/sdk/deviceupdate/iot-device-update-rest/samples-dev/listUpdates.ts index 47843491f793..310854dd9ba0 100644 --- a/sdk/deviceupdate/iot-device-update-rest/samples-dev/listUpdates.ts +++ b/sdk/deviceupdate/iot-device-update-rest/samples-dev/listUpdates.ts @@ -10,14 +10,12 @@ import DeviceUpdate, { isUnexpected, paginate } from "@azure-rest/iot-device-update"; import { DefaultAzureCredential } from "@azure/identity"; -import dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || ""; const instanceId = process.env["INSTANCE_ID"] || ""; -async function main() { +async function main(): Promise { console.log("== List updates =="); const provider = process.env["DEVICEUPDATE_UPDATE_PROVIDER"] || ""; const name = process.env["DEVICEUPDATE_UPDATE_NAME"] || ""; @@ -38,8 +36,8 @@ async function main() { } const providers = paginate(client, providersResult); - for await (const provider of providers) { - console.log(provider); + for await (const pagedProvider of providers) { + console.log(pagedProvider); } console.log("\nNames in provider '" + provider + "':"); @@ -52,8 +50,8 @@ async function main() { } const names = paginate(client, namesResult); - for await (const name of names) { - console.log(name); + for await (const pagedName of names) { + console.log(pagedName); } console.log("\nVersions in provider '" + provider + "' and name '" + name + "':"); diff --git a/sdk/deviceupdate/iot-device-update-rest/src/clientDefinitions.ts b/sdk/deviceupdate/iot-device-update-rest/src/clientDefinitions.ts index f665b7aee198..59626eeaca37 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/clientDefinitions.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/clientDefinitions.ts @@ -52,7 +52,7 @@ import type { DeviceManagementListLogCollectionsParameters, DeviceManagementGetLogCollectionDetailedStatusParameters, DeviceManagementListHealthOfDevicesParameters, -} from "./parameters"; +} from "./parameters.js"; import type { DeviceUpdateListUpdates200Response, DeviceUpdateListUpdatesdefaultResponse, @@ -159,7 +159,7 @@ import type { DeviceManagementGetLogCollectionDetailedStatusdefaultResponse, DeviceManagementListHealthOfDevices200Response, DeviceManagementListHealthOfDevicesdefaultResponse, -} from "./responses"; +} from "./responses.js"; import type { Client, StreamableMethod } from "@azure-rest/core-client"; export interface DeviceUpdateListUpdates { diff --git a/sdk/deviceupdate/iot-device-update-rest/src/deviceUpdate.ts b/sdk/deviceupdate/iot-device-update-rest/src/deviceUpdate.ts index ec7312ec1d98..92bd2f9c1e56 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/deviceUpdate.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/deviceUpdate.ts @@ -4,7 +4,7 @@ import type { ClientOptions } from "@azure-rest/core-client"; import { getClient } from "@azure-rest/core-client"; import type { TokenCredential } from "@azure/core-auth"; -import type { DeviceUpdateClient } from "./clientDefinitions"; +import type { DeviceUpdateClient } from "./clientDefinitions.js"; export default function createClient( endpoint: string, diff --git a/sdk/deviceupdate/iot-device-update-rest/src/index.ts b/sdk/deviceupdate/iot-device-update-rest/src/index.ts index cf903e2cf87f..ae667181cdac 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/index.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/index.ts @@ -1,16 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import DeviceUpdate from "./deviceUpdate"; +import DeviceUpdate from "./deviceUpdate.js"; -export * from "./deviceUpdate"; -export * from "./parameters"; -export * from "./responses"; -export * from "./clientDefinitions"; -export * from "./isUnexpected"; -export * from "./models"; -export * from "./outputModels"; -export * from "./paginateHelper"; -export * from "./pollingHelper"; +export * from "./deviceUpdate.js"; +export * from "./parameters.js"; +export * from "./responses.js"; +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./paginateHelper.js"; +export * from "./pollingHelper.js"; +// eslint-disable-next-line @azure/azure-sdk/ts-modules-only-named export default DeviceUpdate; diff --git a/sdk/deviceupdate/iot-device-update-rest/src/isUnexpected.ts b/sdk/deviceupdate/iot-device-update-rest/src/isUnexpected.ts index a118e7acd9d2..a976bbe97995 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/isUnexpected.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/isUnexpected.ts @@ -107,7 +107,7 @@ import type { DeviceManagementGetLogCollectionDetailedStatusdefaultResponse, DeviceManagementListHealthOfDevices200Response, DeviceManagementListHealthOfDevicesdefaultResponse, -} from "./responses"; +} from "./responses.js"; const responseMap: Record = { "GET /deviceUpdate/{instanceId}/updates": ["200"], diff --git a/sdk/deviceupdate/iot-device-update-rest/src/parameters.ts b/sdk/deviceupdate/iot-device-update-rest/src/parameters.ts index f3e6c0a33773..83ae705758e8 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/parameters.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/parameters.ts @@ -3,7 +3,7 @@ import type { RawHttpHeadersInput } from "@azure/core-rest-pipeline"; import type { RequestParameters } from "@azure-rest/core-client"; -import type { ImportUpdateInputItem, PatchBody, Deployment, LogCollection } from "./models"; +import type { ImportUpdateInputItem, PatchBody, Deployment, LogCollection } from "./models.js"; export interface DeviceUpdateListUpdatesQueryParamProperties { /** Request updates matching a free-text search expression. */ diff --git a/sdk/deviceupdate/iot-device-update-rest/src/responses.ts b/sdk/deviceupdate/iot-device-update-rest/src/responses.ts index e0d2165b64d6..ccff65981808 100644 --- a/sdk/deviceupdate/iot-device-update-rest/src/responses.ts +++ b/sdk/deviceupdate/iot-device-update-rest/src/responses.ts @@ -34,7 +34,7 @@ import type { LogCollectionListOutput, LogCollectionOperationDetailedStatusOutput, DeviceHealthListOutput, -} from "./outputModels"; +} from "./outputModels.js"; /** Get a list of all updates that have been imported to Device Update for IoT Hub. */ export interface DeviceUpdateListUpdates200Response extends HttpResponse { diff --git a/sdk/deviceupdate/iot-device-update-rest/test/public/management.spec.ts b/sdk/deviceupdate/iot-device-update-rest/test/public/management.spec.ts index 4789c48136b9..c09a75ce1802 100644 --- a/sdk/deviceupdate/iot-device-update-rest/test/public/management.spec.ts +++ b/sdk/deviceupdate/iot-device-update-rest/test/public/management.spec.ts @@ -1,29 +1,28 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { DeviceUpdateClient } from "../../src"; -import { isUnexpected } from "../../src"; -import type { Context } from "mocha"; -import { assert } from "chai"; +import type { DeviceUpdateClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; import { Recorder } from "@azure-tools/test-recorder"; -import { createRecordedClient, startRecorder } from "./utils/recordedClient"; +import { createRecordedClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("device and deployment test", () => { let recorder: Recorder; let client: DeviceUpdateClient; - beforeEach(async function (this: Context) { - recorder = new Recorder(this.currentTest); + beforeEach(async (ctx) => { + recorder = new Recorder(ctx); await startRecorder(recorder); client = createRecordedClient(recorder); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); const group = "dpokluda-test"; - it("list devices", async function () { + it("list devices", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/devices", "sdkinstance") .get(); @@ -37,7 +36,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("get device not found", async function () { + it("get device not found", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/devices/{deviceId}", "sdkinstance", "foo") .get(); @@ -45,7 +44,7 @@ describe("device and deployment test", () => { assert.equal(response.status, "404"); }); - it("list groups", async function () { + it("list groups", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/groups", "sdkinstance") .get(); @@ -59,7 +58,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("get group", async function () { + it("get group", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/groups/{groupId}", "sdkinstance", group) .get(); @@ -73,7 +72,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("get group not found", async function () { + it("get group not found", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/groups/{groupId}", "sdkinstance", "foo") .get(); @@ -81,7 +80,7 @@ describe("device and deployment test", () => { assert.equal(response.status, "404"); }); - it("list device classes", async function () { + it("list device classes", async () => { const response = await client .path("/deviceUpdate/{instanceId}/management/deviceClasses", "sdkinstance") .get(); @@ -95,7 +94,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("get device class not found", async function () { + it("get device class not found", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/management/deviceClasses/{deviceClassId}", @@ -107,7 +106,7 @@ describe("device and deployment test", () => { assert.equal(response.status, "404"); }); - it("list best updates for group", async function () { + it("list best updates for group", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/management/groups/{groupId}/bestUpdates", @@ -125,7 +124,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("list best updates for group not found", async function () { + it("list best updates for group not found", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/management/groups/{groupId}/bestUpdates", @@ -137,7 +136,7 @@ describe("device and deployment test", () => { assert.equal(response.status, "404"); }); - it("list deployments for group", async function () { + it("list deployments for group", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/management/groups/{groupId}/deployments", @@ -155,7 +154,7 @@ describe("device and deployment test", () => { assert.equal("200", response.status); }); - it("list deployments for group not found", async function () { + it("list deployments for group not found", { timeout: 600000 }, async () => { const response = await client .path( "/deviceUpdate/{instanceId}/management/groups/{groupId}/deployments", @@ -166,4 +165,4 @@ describe("device and deployment test", () => { assert.equal(response.status, "404"); }); -}).timeout(600000); +}); diff --git a/sdk/deviceupdate/iot-device-update-rest/test/public/update.spec.ts b/sdk/deviceupdate/iot-device-update-rest/test/public/update.spec.ts index 6d1332d03fd4..776c5f986958 100644 --- a/sdk/deviceupdate/iot-device-update-rest/test/public/update.spec.ts +++ b/sdk/deviceupdate/iot-device-update-rest/test/public/update.spec.ts @@ -1,23 +1,22 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { DeviceUpdateClient } from "../../src"; -import { isUnexpected } from "../../src"; -import type { Context } from "mocha"; -import { assert } from "chai"; +import type { DeviceUpdateClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; import { Recorder } from "@azure-tools/test-recorder"; -import { createRecordedClient, startRecorder } from "./utils/recordedClient"; +import { createRecordedClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("update test", () => { let recorder: Recorder; let client: DeviceUpdateClient; - beforeEach(async function (this: Context) { - recorder = new Recorder(this.currentTest); + beforeEach(async (ctx) => { + recorder = new Recorder(ctx); await startRecorder(recorder); client = createRecordedClient(recorder); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); @@ -25,7 +24,7 @@ describe("update test", () => { const name = "vacuum"; const version = "2022.401.504.6"; - it("list providers", async function () { + it("list providers", async () => { const response = await client .path("/deviceUpdate/{instanceId}/updates/providers", "sdkinstance") .get(); @@ -39,7 +38,7 @@ describe("update test", () => { assert.equal("200", response.status); }); - it("list names", async function () { + it("list names", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names", @@ -57,7 +56,7 @@ describe("update test", () => { assert.equal("200", response.status); }); - it("get name not found", async function () { + it("get name not found", async () => { const response = await client .path("/deviceUpdate/{instanceId}/updates/providers/{provider}/names", "sdkinstance", "foo") .get(); @@ -65,7 +64,7 @@ describe("update test", () => { assert.equal(response.status, "404"); }); - it("list versions", async function () { + it("list versions", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions", @@ -84,7 +83,7 @@ describe("update test", () => { assert.equal("200", response.status); }); - it("get version not found", async function () { + it("get version not found", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions", @@ -97,7 +96,7 @@ describe("update test", () => { assert.equal(response.status, "404"); }); - it("get update", async function () { + it("get update", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions/{version}", @@ -117,7 +116,7 @@ describe("update test", () => { assert.equal("200", response.status); }); - it("get update not found", async function () { + it("get update not found", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions/{version}", @@ -131,7 +130,7 @@ describe("update test", () => { assert.equal(response.status, "404"); }); - it("list files", async function () { + it("list files", async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions/{version}/files", @@ -151,7 +150,7 @@ describe("update test", () => { assert.equal("200", response.status); }); - it("list files not found", async function () { + it("list files not found", { timeout: 600000 }, async () => { const response = await client .path( "/deviceUpdate/{instanceId}/updates/providers/{provider}/names/{name}/versions/{version}/files", @@ -164,4 +163,4 @@ describe("update test", () => { assert.equal(response.status, "404"); }); -}).timeout(600000); +}); diff --git a/sdk/deviceupdate/iot-device-update-rest/test/public/utils/recordedClient.ts b/sdk/deviceupdate/iot-device-update-rest/test/public/utils/recordedClient.ts index 26ba2922348c..cca4e48acdd9 100644 --- a/sdk/deviceupdate/iot-device-update-rest/test/public/utils/recordedClient.ts +++ b/sdk/deviceupdate/iot-device-update-rest/test/public/utils/recordedClient.ts @@ -2,8 +2,8 @@ // Licensed under the MIT License. import { createTestCredential } from "@azure-tools/test-credential"; -import type { DeviceUpdateClient } from "../../../src"; -import DeviceUpdate from "../../../src"; +import type { DeviceUpdateClient } from "../../../src/index.js"; +import DeviceUpdate from "../../../src/index.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { assertEnvironmentVariable } from "@azure-tools/test-recorder"; diff --git a/sdk/deviceupdate/iot-device-update-rest/tsconfig.browser.config.json b/sdk/deviceupdate/iot-device-update-rest/tsconfig.browser.config.json new file mode 100644 index 000000000000..f772e6eb3b76 --- /dev/null +++ b/sdk/deviceupdate/iot-device-update-rest/tsconfig.browser.config.json @@ -0,0 +1,10 @@ +{ + "extends": "./.tshy/build.json", + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], + "compilerOptions": { + "outDir": "./dist-test/browser", + "rootDir": ".", + "skipLibCheck": true + } +} diff --git a/sdk/deviceupdate/iot-device-update-rest/tsconfig.json b/sdk/deviceupdate/iot-device-update-rest/tsconfig.json index 9ccd199937d2..84b21757cfa2 100644 --- a/sdk/deviceupdate/iot-device-update-rest/tsconfig.json +++ b/sdk/deviceupdate/iot-device-update-rest/tsconfig.json @@ -1,11 +1,20 @@ { "extends": "../../../tsconfig", "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", "paths": { "@azure-rest/iot-device-update": ["./src/index"] - } + }, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": "." }, - "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] + "include": [ + "src/**/*.ts", + "src/**/*.mts", + "src/**/*.cts", + "samples-dev/**/*.ts", + "test/**/*.ts", + "test/**/*.mts", + "test/**/*.cts" + ] } diff --git a/sdk/deviceupdate/iot-device-update-rest/vitest.browser.config.ts b/sdk/deviceupdate/iot-device-update-rest/vitest.browser.config.ts new file mode 100644 index 000000000000..50ec2d5489b0 --- /dev/null +++ b/sdk/deviceupdate/iot-device-update-rest/vitest.browser.config.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.browser.shared.config.ts"; + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["dist-test/browser/test/**/*.spec.js"], + hookTimeout: 5000000, + testTimeout: 5000000, + }, + }), +); diff --git a/sdk/deviceupdate/iot-device-update-rest/vitest.config.ts b/sdk/deviceupdate/iot-device-update-rest/vitest.config.ts new file mode 100644 index 000000000000..d01fdec8ac69 --- /dev/null +++ b/sdk/deviceupdate/iot-device-update-rest/vitest.config.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.shared.config.ts"; + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["test/**/*.spec.ts"], + hookTimeout: 5000000, + testTimeout: 5000000, + }, + }), +);