From 0498f2c23f7ab790c32c393bd74b759e91c9665e Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:53 -0500 Subject: [PATCH 01/13] Migration: Update package.json, tsconfig.json, and api-extractor.json --- sdk/maps/maps-route-rest/api-extractor.json | 27 +++++--- sdk/maps/maps-route-rest/package.json | 69 ++++++++++----------- sdk/maps/maps-route-rest/tsconfig.json | 23 +++++-- 3 files changed, 71 insertions(+), 48 deletions(-) diff --git a/sdk/maps/maps-route-rest/api-extractor.json b/sdk/maps/maps-route-rest/api-extractor.json index 914d0d6f4f95..bdec5854157b 100644 --- a/sdk/maps/maps-route-rest/api-extractor.json +++ b/sdk/maps/maps-route-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/maps-route-rest.d.ts" + "publicTrimmedFilePath": "dist/maps-route-rest.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/maps/maps-route-rest/package.json b/sdk/maps/maps-route-rest/package.json index 627d43e0205b..ecedf5b1eace 100644 --- a/sdk/maps/maps-route-rest/package.json +++ b/sdk/maps/maps-route-rest/package.json @@ -25,11 +25,8 @@ }, "files": [ "dist/", - "dist-esm/src/", - "types/maps-route-rest.d.ts", "README.md", - "LICENSE", - "review/*" + "LICENSE" ], "//sampleConfiguration": { "productName": "Azure Maps Route", @@ -55,12 +52,12 @@ "node": ">=18.0.0" }, "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 --browser-test false", + "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", + "build:browser": "dev-tool run build-package && dev-tool run bundle", + "build:debug": "dev-tool run build-package && dev-tool run bundle && dev-tool run extract-api", + "build:node": "dev-tool run build-package && dev-tool run bundle --browser-test false", "build:samples": "dev-tool samples publish --force", - "build:test": "tsc -p . && dev-tool run bundle", + "build:test": "dev-tool run build-package && dev-tool run bundle", "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", @@ -77,52 +74,54 @@ "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/abort-controller": "^2.1.2", "@azure/core-auth": "^1.3.0", "@azure/core-lro": "^3.1.0", "@azure/core-rest-pipeline": "^1.8.0", "@azure/logger": "^1.0.0", "@azure/maps-common": "1.0.0-beta.2", - "tslib": "^2.4.0", - "@azure/abort-controller": "^2.1.2" + "tslib": "^2.4.0" }, "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.0.0", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.1.0", + "@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", - "@types/chai": "^4.2.8", - "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", + "@vitest/browser": "^2.1.5", + "@vitest/coverage-istanbul": "^2.1.5", "autorest": "latest", - "chai": "^4.2.0", "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": "^1.1.0", - "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.5" }, - "browser": { - "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + "browser": "./dist/browser/index.js", + "type": "module", + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false } } diff --git a/sdk/maps/maps-route-rest/tsconfig.json b/sdk/maps/maps-route-rest/tsconfig.json index 8c95568f19e6..1981e29db7c8 100644 --- a/sdk/maps/maps-route-rest/tsconfig.json +++ b/sdk/maps/maps-route-rest/tsconfig.json @@ -1,11 +1,22 @@ { "extends": "../../../tsconfig", "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", - // Configuring the path so that the Samples engine could resolve the sample-dev package against the source code of the SDK. - // Reference: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-quickstart.md#how-to-write-samples - "paths": { "@azure-rest/maps-route": ["./src/index"] } + "paths": { + "@azure-rest/maps-route": [ + "./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" + ] } From b55898ec82864d6156fddfc27748a603bb6e0db4 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:53 -0500 Subject: [PATCH 02/13] Migration: Update test config --- .../tsconfig.browser.config.json | 17 +++++++++++++++++ .../maps-route-rest/vitest.browser.config.ts | 17 +++++++++++++++++ sdk/maps/maps-route-rest/vitest.config.ts | 15 +++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 sdk/maps/maps-route-rest/tsconfig.browser.config.json create mode 100644 sdk/maps/maps-route-rest/vitest.browser.config.ts create mode 100644 sdk/maps/maps-route-rest/vitest.config.ts diff --git a/sdk/maps/maps-route-rest/tsconfig.browser.config.json b/sdk/maps/maps-route-rest/tsconfig.browser.config.json new file mode 100644 index 000000000000..b6586181d006 --- /dev/null +++ b/sdk/maps/maps-route-rest/tsconfig.browser.config.json @@ -0,0 +1,17 @@ +{ + "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/maps/maps-route-rest/vitest.browser.config.ts b/sdk/maps/maps-route-rest/vitest.browser.config.ts new file mode 100644 index 000000000000..b48c61b2ef46 --- /dev/null +++ b/sdk/maps/maps-route-rest/vitest.browser.config.ts @@ -0,0 +1,17 @@ + +// 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", + ], + }, + }), +); diff --git a/sdk/maps/maps-route-rest/vitest.config.ts b/sdk/maps/maps-route-rest/vitest.config.ts new file mode 100644 index 000000000000..39267dd2f56f --- /dev/null +++ b/sdk/maps/maps-route-rest/vitest.config.ts @@ -0,0 +1,15 @@ + +// 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"], + }, + }), +); From 1ee06b47bdebdacea1332b8555423fd6def8bb12 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:53 -0500 Subject: [PATCH 03/13] Migration: Clean up files --- sdk/maps/maps-route-rest/karma.conf.js | 125 ------------------------- 1 file changed, 125 deletions(-) delete mode 100644 sdk/maps/maps-route-rest/karma.conf.js diff --git a/sdk/maps/maps-route-rest/karma.conf.js b/sdk/maps/maps-route-rest/karma.conf.js deleted file mode 100644 index 8793e336491d..000000000000 --- a/sdk/maps/maps-route-rest/karma.conf.js +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// https://github.com/karma-runner/karma-chrome-launcher -process.env.CHROME_BIN = require("puppeteer").executablePath(); -require("dotenv").config(); -const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); -process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); - -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-source-map-support", - ], - - // 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"], - // 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", "MAPS_RESOURCE_CLIENT_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", - }, - }, - }); -}; From c4e61c8fb9d2c2f22018d1bdb3cc0ae40af62d98 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:54 -0500 Subject: [PATCH 04/13] Migration: Apply codemod: "fixSourceFile" --- .../generated/clientDefinitions.ts | 4 +-- sdk/maps/maps-route-rest/generated/index.ts | 20 +++++++------- .../maps-route-rest/generated/isUnexpected.ts | 2 +- .../generated/mapsRouteClient.ts | 4 +-- .../maps-route-rest/generated/parameters.ts | 2 +- .../maps-route-rest/generated/responses.ts | 2 +- sdk/maps/maps-route-rest/src/helpers.ts | 2 +- sdk/maps/maps-route-rest/src/index.ts | 6 ++--- sdk/maps/maps-route-rest/src/mapsRoute.ts | 4 +-- .../test/public/helper.spec.ts | 4 +-- .../test/public/mapsRouteClient.spec.ts | 26 +++++++++---------- .../test/public/utils/recordedClient.ts | 6 ++--- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/sdk/maps/maps-route-rest/generated/clientDefinitions.ts b/sdk/maps/maps-route-rest/generated/clientDefinitions.ts index 8bc63ee74e09..30b0d6044e49 100644 --- a/sdk/maps/maps-route-rest/generated/clientDefinitions.ts +++ b/sdk/maps/maps-route-rest/generated/clientDefinitions.ts @@ -11,7 +11,7 @@ import { RouteRequestRouteDirectionsBatchParameters, RouteGetRouteDirectionsBatchParameters, RouteRequestRouteDirectionsBatchSyncParameters, -} from "./parameters"; +} from "./parameters.js"; import { RouteRequestRouteMatrix200Response, RouteRequestRouteMatrix202Response, @@ -33,7 +33,7 @@ import { RouteRequestRouteDirectionsBatchSync200Response, RouteRequestRouteDirectionsBatchSync408Response, RouteRequestRouteDirectionsBatchSyncDefaultResponse, -} from "./responses"; +} from "./responses.js"; import { Client, StreamableMethod } from "@azure-rest/core-client"; export interface RequestRouteMatrix { diff --git a/sdk/maps/maps-route-rest/generated/index.ts b/sdk/maps/maps-route-rest/generated/index.ts index 19cb44d10b30..581a3f200682 100644 --- a/sdk/maps/maps-route-rest/generated/index.ts +++ b/sdk/maps/maps-route-rest/generated/index.ts @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import MapsRouteClient from "./mapsRouteClient"; +import MapsRouteClient from "./mapsRouteClient.js"; -export * from "./mapsRouteClient"; -export * from "./parameters"; -export * from "./responses"; -export * from "./clientDefinitions"; -export * from "./isUnexpected"; -export * from "./models"; -export * from "./outputModels"; -export * from "./pollingHelper"; -export * from "./serializeHelper"; +export * from "./mapsRouteClient.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 "./pollingHelper.js"; +export * from "./serializeHelper.js"; export default MapsRouteClient; diff --git a/sdk/maps/maps-route-rest/generated/isUnexpected.ts b/sdk/maps/maps-route-rest/generated/isUnexpected.ts index d7e2b34863c7..165c00027d02 100644 --- a/sdk/maps/maps-route-rest/generated/isUnexpected.ts +++ b/sdk/maps/maps-route-rest/generated/isUnexpected.ts @@ -14,7 +14,7 @@ import { RouteRequestRouteDirectionsBatchSync200Response, RouteRequestRouteDirectionsBatchSync408Response, RouteRequestRouteDirectionsBatchSyncDefaultResponse, -} from "./responses"; +} from "./responses.js"; const responseMap: Record = { "GET /route/matrix/{format}": ["200", "202"], diff --git a/sdk/maps/maps-route-rest/generated/mapsRouteClient.ts b/sdk/maps/maps-route-rest/generated/mapsRouteClient.ts index a7479f4e3a7e..cbe76d274bc1 100644 --- a/sdk/maps/maps-route-rest/generated/mapsRouteClient.ts +++ b/sdk/maps/maps-route-rest/generated/mapsRouteClient.ts @@ -2,9 +2,9 @@ // Licensed under the MIT License. import { getClient, ClientOptions } from "@azure-rest/core-client"; -import { logger } from "./logger"; +import { logger } from "./logger.js"; import { KeyCredential } from "@azure/core-auth"; -import { MapsRouteClient } from "./clientDefinitions"; +import { MapsRouteClient } from "./clientDefinitions.js"; /** The optional parameters for the client */ export interface MapsRouteClientOptions extends ClientOptions { diff --git a/sdk/maps/maps-route-rest/generated/parameters.ts b/sdk/maps/maps-route-rest/generated/parameters.ts index c00343031472..02f3ccde373f 100644 --- a/sdk/maps/maps-route-rest/generated/parameters.ts +++ b/sdk/maps/maps-route-rest/generated/parameters.ts @@ -6,7 +6,7 @@ import { RouteMatrixQuery, RouteDirectionParameters, BatchRequest, -} from "./models"; +} from "./models.js"; export interface RouteRequestRouteMatrixBodyParam { /** The matrix of origin and destination coordinates to compute the route distance, travel time and other summary for each cell of the matrix based on the input parameters. The minimum and the maximum cell count supported are 1 and **700** for async and **100** for sync respectively. For example, it can be 35 origins and 20 destinations or 25 origins and 25 destinations for async API. */ diff --git a/sdk/maps/maps-route-rest/generated/responses.ts b/sdk/maps/maps-route-rest/generated/responses.ts index 6b744305eb4d..082ea3fe953b 100644 --- a/sdk/maps/maps-route-rest/generated/responses.ts +++ b/sdk/maps/maps-route-rest/generated/responses.ts @@ -9,7 +9,7 @@ import { RouteDirectionsOutput, RouteRangeResultOutput, RouteDirectionsBatchResultOutput, -} from "./outputModels"; +} from "./outputModels.js"; /** * diff --git a/sdk/maps/maps-route-rest/src/helpers.ts b/sdk/maps/maps-route-rest/src/helpers.ts index 882a71abacf7..1843b7c1a074 100644 --- a/sdk/maps/maps-route-rest/src/helpers.ts +++ b/sdk/maps/maps-route-rest/src/helpers.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import type { LatLon } from "@azure/maps-common"; -import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../generated"; +import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../generated/index.js"; function toLatLonString(coordinates: LatLon): string { return `${coordinates[0]},${coordinates[1]}`; diff --git a/sdk/maps/maps-route-rest/src/index.ts b/sdk/maps/maps-route-rest/src/index.ts index 8f0915b943f7..1eefe4c4b44f 100644 --- a/sdk/maps/maps-route-rest/src/index.ts +++ b/sdk/maps/maps-route-rest/src/index.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import MapsRoute from "./mapsRoute"; +import MapsRoute from "./mapsRoute.js"; -export * from "../generated"; -export * from "./helpers"; +export * from "../generated/index.js"; +export * from "./helpers.js"; export default MapsRoute; diff --git a/sdk/maps/maps-route-rest/src/mapsRoute.ts b/sdk/maps/maps-route-rest/src/mapsRoute.ts index 32bc1d95c6ee..a5a661620e0d 100644 --- a/sdk/maps/maps-route-rest/src/mapsRoute.ts +++ b/sdk/maps/maps-route-rest/src/mapsRoute.ts @@ -5,8 +5,8 @@ import type { ClientOptions } from "@azure-rest/core-client"; import type { AzureKeyCredential, AzureSASCredential, TokenCredential } from "@azure/core-auth"; import { isSASCredential, isTokenCredential } from "@azure/core-auth"; import { createMapsClientIdPolicy } from "@azure/maps-common"; -import type { MapsRouteClient } from "../generated"; -import createClient from "../generated"; +import type { MapsRouteClient } from "../generated/index.js"; +import createClient from "../generated/index.js"; import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline"; /** diff --git a/sdk/maps/maps-route-rest/test/public/helper.spec.ts b/sdk/maps/maps-route-rest/test/public/helper.spec.ts index 5593301d09e8..25e27c6bdd4e 100644 --- a/sdk/maps/maps-route-rest/test/public/helper.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/helper.spec.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../../src"; -import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src"; +import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../../src/index.js"; +import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; import { assert } from "chai"; import type { LatLon } from "@azure/maps-common"; diff --git a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts index b39f2d0a7aa6..05e927d2d37d 100644 --- a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts @@ -2,26 +2,26 @@ // Licensed under the MIT License. import type { Context, Suite } from "mocha"; -import type { RouteDirectionParameters, RouteMatrixQuery } from "../../src"; -import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src"; +import type { RouteDirectionParameters, RouteMatrixQuery } from "../../src/index.js"; +import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { isPlaybackMode } from "@azure-tools/test-recorder"; import { assert } from "chai"; -import { createClient, createRecorder, testLogger } from "./utils/recordedClient"; +import { createClient, createRecorder, testLogger } from "./utils/recordedClient.js"; import type { MapsRouteClient, RouteGetRouteDirectionsBatch200Response, RouteGetRouteDirectionsQueryParamProperties, RouteGetRouteMatrix200Response, -} from "../../generated"; -import { getLongRunningPoller, isUnexpected } from "../../generated"; +} from "../../generated/index.js"; +import { getLongRunningPoller, isUnexpected } from "../../generated/index.js"; import type { LatLon } from "@azure/maps-common"; describe("Endpoint can be overwritten", function (this: Suite) { let recorder: Recorder; const fastTimeout = 10000; - beforeEach(async function (this: Context) { + beforeEach(async function (ctx) { testLogger.verbose(`Recorder: starting...`); recorder = await createRecorder(this); }); @@ -31,7 +31,7 @@ describe("Endpoint can be overwritten", function (this: Suite) { await recorder.stop(); }); - before(function (this: Context) { + before(function (ctx) { this.timeout(fastTimeout); }); @@ -71,7 +71,7 @@ describe("Get Route Directions", function (this: Suite) { let client: MapsRouteClient; const fastTimeout = 10000; - beforeEach(async function (this: Context) { + beforeEach(async function (ctx) { testLogger.verbose(`Recorder: starting...`); recorder = await createRecorder(this); client = createClient(recorder.configureClientOptions({})); @@ -82,7 +82,7 @@ describe("Get Route Directions", function (this: Suite) { await recorder.stop(); }); - before(function (this: Context) { + before(function (ctx) { this.timeout(fastTimeout); }); @@ -141,7 +141,7 @@ describe("Get Route Range", function () { let client: MapsRouteClient; const fastTimeout = 10000; - beforeEach(async function (this: Context) { + beforeEach(async function (ctx) { testLogger.verbose(`Recorder: starting...`); recorder = await createRecorder(this); client = createClient(recorder.configureClientOptions({})); @@ -152,7 +152,7 @@ describe("Get Route Range", function () { await recorder.stop(); }); - before(function (this: Context) { + before(function (ctx) { this.timeout(fastTimeout); }); @@ -176,7 +176,7 @@ describe("LRO", function (this: Suite) { const CLITimeout = this.timeout(); const fastTimeout = 10000; - beforeEach(async function (this: Context) { + beforeEach(async function (ctx) { recorder = await createRecorder(this); client = createClient(recorder.configureClientOptions({})); }); @@ -187,7 +187,7 @@ describe("LRO", function (this: Suite) { const pollingInterval = isPlaybackMode() ? 0 : 2000; - before(function (this: Context) { + before(function (ctx) { this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); }); diff --git a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts index 83470adf451d..220149acfa5c 100644 --- a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts +++ b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts @@ -4,12 +4,12 @@ import type { Context } from "mocha"; import type { RecorderStartOptions } from "@azure-tools/test-recorder"; import { Recorder, env } from "@azure-tools/test-recorder"; -import "./env"; +import "./env.js"; import { createClientLogger } from "@azure/logger"; import { createTestCredential } from "@azure-tools/test-credential"; -import MapsRoute from "../../../src/mapsRoute"; +import MapsRoute from "../../../src/mapsRoute.js"; import type { ClientOptions } from "@azure-rest/core-client"; -import type { MapsRouteClient } from "../../../generated"; +import type { MapsRouteClient } from "../../../generated/index.js"; const envSetupForPlayback: Record = { MAPS_RESOURCE_CLIENT_ID: "azure_maps_client_id", From d03ae85022fbe6dda2b2cc969787024514c270cb Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:55 -0500 Subject: [PATCH 05/13] Migration: Apply codemod: "fixTestingImports" --- sdk/maps/maps-route-rest/test/public/helper.spec.ts | 2 +- sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts | 4 +--- sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sdk/maps/maps-route-rest/test/public/helper.spec.ts b/sdk/maps/maps-route-rest/test/public/helper.spec.ts index 25e27c6bdd4e..1c62c2cf9b56 100644 --- a/sdk/maps/maps-route-rest/test/public/helper.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/helper.spec.ts @@ -3,8 +3,8 @@ import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../../src/index.js"; import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; -import { assert } from "chai"; import type { LatLon } from "@azure/maps-common"; +import { describe, it, assert } from "vitest"; describe("toColonDelimitedLatLonString", function () { it("should compose the string correctly", function () { diff --git a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts index 05e927d2d37d..8099912a13ff 100644 --- a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts @@ -1,12 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - -import type { Context, Suite } from "mocha"; import type { RouteDirectionParameters, RouteMatrixQuery } from "../../src/index.js"; import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { isPlaybackMode } from "@azure-tools/test-recorder"; -import { assert } from "chai"; import { createClient, createRecorder, testLogger } from "./utils/recordedClient.js"; import type { MapsRouteClient, @@ -16,6 +13,7 @@ import type { } from "../../generated/index.js"; import { getLongRunningPoller, isUnexpected } from "../../generated/index.js"; import type { LatLon } from "@azure/maps-common"; +import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; describe("Endpoint can be overwritten", function (this: Suite) { let recorder: Recorder; diff --git a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts index 220149acfa5c..a3861ffacb7c 100644 --- a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts +++ b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - -import type { Context } from "mocha"; import type { RecorderStartOptions } from "@azure-tools/test-recorder"; import { Recorder, env } from "@azure-tools/test-recorder"; import "./env.js"; From d6c66e0d08edae4729e3e984d25c5271f4027919 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:55 -0500 Subject: [PATCH 06/13] Migration: Apply codemod: "replaceAssertIsRejected" From 2789707665e5c5250ba0f65c0859251bbc3ca260 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:55 -0500 Subject: [PATCH 07/13] Migration: Apply codemod: "replaceSinonStub" From 58a4eb628d44bd722d06fc046a8342f70b14f705 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:56 -0500 Subject: [PATCH 08/13] Migration: Apply codemod: "addViHelper" From 84d1d85c546a8136643ffe17f7112a3303e94799 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:56 -0500 Subject: [PATCH 09/13] Migration: Apply codemod: "replaceSupportTracing" From 01f87608891e05272a33594ba462bb2e80b3182d Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:56 -0500 Subject: [PATCH 10/13] Migration: Apply codemod: "replaceTestUtils" From b92e97611f2bf10e3f2c3dbc39c0c596a272863f Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:33:58 -0500 Subject: [PATCH 11/13] Migration: rushx format --- sdk/maps/maps-route-rest/src/helpers.ts | 5 ++++- sdk/maps/maps-route-rest/test/public/helper.spec.ts | 5 ++++- .../test/public/mapsRouteClient.spec.ts | 5 ++++- sdk/maps/maps-route-rest/tsconfig.browser.config.json | 11 ++--------- sdk/maps/maps-route-rest/tsconfig.json | 4 +--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sdk/maps/maps-route-rest/src/helpers.ts b/sdk/maps/maps-route-rest/src/helpers.ts index 1843b7c1a074..d0e4b33f1fb0 100644 --- a/sdk/maps/maps-route-rest/src/helpers.ts +++ b/sdk/maps/maps-route-rest/src/helpers.ts @@ -2,7 +2,10 @@ // Licensed under the MIT License. import type { LatLon } from "@azure/maps-common"; -import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../generated/index.js"; +import type { + BatchRequest, + RouteGetRouteDirectionsQueryParamProperties, +} from "../generated/index.js"; function toLatLonString(coordinates: LatLon): string { return `${coordinates[0]},${coordinates[1]}`; diff --git a/sdk/maps/maps-route-rest/test/public/helper.spec.ts b/sdk/maps/maps-route-rest/test/public/helper.spec.ts index 1c62c2cf9b56..46019043c1ad 100644 --- a/sdk/maps/maps-route-rest/test/public/helper.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/helper.spec.ts @@ -2,7 +2,10 @@ // Licensed under the MIT License. import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from "../../src/index.js"; -import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; +import { + createRouteDirectionsBatchRequest, + toColonDelimitedLatLonString, +} from "../../src/index.js"; import type { LatLon } from "@azure/maps-common"; import { describe, it, assert } from "vitest"; diff --git a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts index 8099912a13ff..a2bcbdb6630c 100644 --- a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts @@ -1,7 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import type { RouteDirectionParameters, RouteMatrixQuery } from "../../src/index.js"; -import { createRouteDirectionsBatchRequest, toColonDelimitedLatLonString } from "../../src/index.js"; +import { + createRouteDirectionsBatchRequest, + toColonDelimitedLatLonString, +} from "../../src/index.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { isPlaybackMode } from "@azure-tools/test-recorder"; import { createClient, createRecorder, testLogger } from "./utils/recordedClient.js"; diff --git a/sdk/maps/maps-route-rest/tsconfig.browser.config.json b/sdk/maps/maps-route-rest/tsconfig.browser.config.json index b6586181d006..f772e6eb3b76 100644 --- a/sdk/maps/maps-route-rest/tsconfig.browser.config.json +++ b/sdk/maps/maps-route-rest/tsconfig.browser.config.json @@ -1,14 +1,7 @@ { "extends": "./.tshy/build.json", - "include": [ - "./src/**/*.ts", - "./src/**/*.mts", - "./test/**/*.spec.ts", - "./test/**/*.mts" - ], - "exclude": [ - "./test/**/node/**/*.ts" - ], + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", diff --git a/sdk/maps/maps-route-rest/tsconfig.json b/sdk/maps/maps-route-rest/tsconfig.json index 1981e29db7c8..8b6fad2202c0 100644 --- a/sdk/maps/maps-route-rest/tsconfig.json +++ b/sdk/maps/maps-route-rest/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../../tsconfig", "compilerOptions": { "paths": { - "@azure-rest/maps-route": [ - "./src/index" - ] + "@azure-rest/maps-route": ["./src/index"] }, "module": "NodeNext", "moduleResolution": "NodeNext", From d1fc278bedaece97c4e8dd18634e094653b599b7 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:55:32 -0500 Subject: [PATCH 12/13] [maps] Upgrade @azure-rest/maps-route to ESM/vitest --- common/config/rush/pnpm-lock.yaml | 26 ++++-- sdk/maps/maps-route-rest/package.json | 27 +++++- .../maps-route-rest/samples-dev/directions.ts | 7 +- sdk/maps/maps-route-rest/samples-dev/lro.ts | 6 +- .../maps-route-rest/samples-dev/matrix.ts | 8 +- sdk/maps/maps-route-rest/samples-dev/range.ts | 5 +- .../maps-route-rest/samples-dev/resumeLro.ts | 6 +- .../{ => src}/generated/clientDefinitions.ts | 0 .../{ => src}/generated/index.ts | 0 .../{ => src}/generated/isUnexpected.ts | 0 .../{ => src}/generated/logger.ts | 0 .../{ => src}/generated/mapsRouteClient.ts | 0 .../{ => src}/generated/models.ts | 0 .../{ => src}/generated/outputModels.ts | 0 .../{ => src}/generated/parameters.ts | 0 .../{ => src}/generated/pollingHelper.ts | 0 .../{ => src}/generated/responses.ts | 0 .../{ => src}/generated/serializeHelper.ts | 0 sdk/maps/maps-route-rest/src/helpers.ts | 2 +- sdk/maps/maps-route-rest/src/index.ts | 2 +- sdk/maps/maps-route-rest/src/mapsRoute.ts | 4 +- sdk/maps/maps-route-rest/swagger/README.md | 2 +- .../test/public/mapsRouteClient.spec.ts | 89 ++++++++----------- .../utils/{env.browser.ts => env-browser.mts} | 0 .../test/public/utils/recordedClient.ts | 6 +- .../maps-route-rest/vitest.browser.config.ts | 7 +- sdk/maps/maps-route-rest/vitest.config.ts | 3 +- 27 files changed, 103 insertions(+), 97 deletions(-) rename sdk/maps/maps-route-rest/{ => src}/generated/clientDefinitions.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/index.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/isUnexpected.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/logger.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/mapsRouteClient.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/models.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/outputModels.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/parameters.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/pollingHelper.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/responses.ts (100%) rename sdk/maps/maps-route-rest/{ => src}/generated/serializeHelper.ts (100%) rename sdk/maps/maps-route-rest/test/public/utils/{env.browser.ts => env-browser.mts} (100%) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 30ef27a5568b..bf0c28a83e80 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -20553,7 +20553,7 @@ packages: dev: false file:projects/health-insights-cancerprofiling.tgz: - resolution: {integrity: sha512-fAdFqmdr0LMhpG7oC5nnvnll+JoRDQo2yfqWDwz/1CCo+jYW6TkCHUD5xBL573SCSwgHuiwnTBy8XrzkZPHRcw==, tarball: file:projects/health-insights-cancerprofiling.tgz} + resolution: {integrity: sha512-VbNwjG9FeYaNHVZ5ccHivYA5aMTBQaj9e/3S1qhujNHdW79W4w9R989l0SMtitK7WXcC7OfQunMVVA/v5BKPeA==, tarball: file:projects/health-insights-cancerprofiling.tgz} name: '@rush-temp/health-insights-cancerprofiling' version: 0.0.0 dependencies: @@ -21320,7 +21320,7 @@ packages: dev: false file:projects/maps-route.tgz: - resolution: {integrity: sha512-7CIlx59lH1iXpkFOrf1zQ6r986jREdZS9F+cKejJPIrbqqj0e9uO5Po1q9aUwQgEkQFlh8wQ55GrK36jhQG5jQ==, tarball: file:projects/maps-route.tgz} + resolution: {integrity: sha512-5+w6/ULXCxZtXZhoJ5l7+MKUKaQIx49viOcfYMVGjQw0vi0Tq59nx9Qrl6qWos6BC1kILM5uINp8W47dBpCNWA==, tarball: file:projects/maps-route.tgz} name: '@rush-temp/maps-route' version: 0.0.0 dependencies: @@ -21331,6 +21331,8 @@ packages: '@types/chai': 4.3.20 '@types/mocha': 10.0.10 '@types/node': 18.19.65 + '@vitest/browser': 2.1.5(@types/node@18.19.65)(playwright@1.49.0)(typescript@5.6.3)(vitest@2.1.5) + '@vitest/coverage-istanbul': 2.1.5(vitest@2.1.5) autorest: 3.7.1 chai: 4.3.10 dotenv: 16.4.5 @@ -21347,18 +21349,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.65)(typescript@5.6.3) tslib: 2.8.1 typescript: 5.6.3 + vitest: 2.1.5(@types/node@18.19.65)(@vitest/browser@2.1.5) 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/maps-search.tgz: diff --git a/sdk/maps/maps-route-rest/package.json b/sdk/maps/maps-route-rest/package.json index ecedf5b1eace..67daef58053d 100644 --- a/sdk/maps/maps-route-rest/package.json +++ b/sdk/maps/maps-route-rest/package.json @@ -15,9 +15,9 @@ "route" ], "license": "MIT", - "main": "dist/index.js", - "module": "./dist-esm/src/index.js", - "types": "./types/maps-route-rest.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/maps/maps-route-rest/README.md", "repository": "github:Azure/azure-sdk-for-js", "bugs": { @@ -123,5 +123,26 @@ "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/maps/maps-route-rest/samples-dev/directions.ts b/sdk/maps/maps-route-rest/samples-dev/directions.ts index 291ad5ab4ff1..178863031eee 100644 --- a/sdk/maps/maps-route-rest/samples-dev/directions.ts +++ b/sdk/maps/maps-route-rest/samples-dev/directions.ts @@ -6,16 +6,13 @@ */ import { DefaultAzureCredential } from "@azure/identity"; +import type { RouteRequestRouteDirectionsBatchSync200Response } from "@azure-rest/maps-route"; import MapsRoute, { createRouteDirectionsBatchRequest, isUnexpected, toColonDelimitedLatLonString, - RouteRequestRouteDirectionsBatchSync200Response, } from "@azure-rest/maps-route"; - -// Load the .env file if it exists -import * as dotenv from "dotenv"; -dotenv.config(); +import "dotenv/config"; async function main(): Promise { /** diff --git a/sdk/maps/maps-route-rest/samples-dev/lro.ts b/sdk/maps/maps-route-rest/samples-dev/lro.ts index c262d1cd3185..7f67f2e4868e 100644 --- a/sdk/maps/maps-route-rest/samples-dev/lro.ts +++ b/sdk/maps/maps-route-rest/samples-dev/lro.ts @@ -6,15 +6,13 @@ */ import { DefaultAzureCredential } from "@azure/identity"; +import type { RouteGetRouteDirectionsBatch200Response } from "@azure-rest/maps-route"; import MapsRoute, { createRouteDirectionsBatchRequest, getLongRunningPoller, - RouteGetRouteDirectionsBatch200Response, toColonDelimitedLatLonString, } from "@azure-rest/maps-route"; -import * as dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; /** * We use "/route/directions/batch/" in this example. diff --git a/sdk/maps/maps-route-rest/samples-dev/matrix.ts b/sdk/maps/maps-route-rest/samples-dev/matrix.ts index a03cd7f6a1e0..ecec712ddf4f 100644 --- a/sdk/maps/maps-route-rest/samples-dev/matrix.ts +++ b/sdk/maps/maps-route-rest/samples-dev/matrix.ts @@ -6,11 +6,9 @@ */ import { DefaultAzureCredential } from "@azure/identity"; -import MapsRoute, { RouteGetRouteMatrix200Response, isUnexpected } from "@azure-rest/maps-route"; - -// Load the .env file if it exists -import * as dotenv from "dotenv"; -dotenv.config(); +import type { RouteGetRouteMatrix200Response } from "@azure-rest/maps-route"; +import MapsRoute, { isUnexpected } from "@azure-rest/maps-route"; +import "dotenv/config"; async function main(): Promise { /** diff --git a/sdk/maps/maps-route-rest/samples-dev/range.ts b/sdk/maps/maps-route-rest/samples-dev/range.ts index e15398c7ebdf..6f0dcc508328 100644 --- a/sdk/maps/maps-route-rest/samples-dev/range.ts +++ b/sdk/maps/maps-route-rest/samples-dev/range.ts @@ -7,10 +7,7 @@ import { DefaultAzureCredential } from "@azure/identity"; import MapsRoute, { isUnexpected } from "@azure-rest/maps-route"; - -// Load the .env file if it exists -import * as dotenv from "dotenv"; -dotenv.config(); +import "dotenv/config"; async function main(): Promise { /** diff --git a/sdk/maps/maps-route-rest/samples-dev/resumeLro.ts b/sdk/maps/maps-route-rest/samples-dev/resumeLro.ts index 0003a7632b2d..58e70c764817 100644 --- a/sdk/maps/maps-route-rest/samples-dev/resumeLro.ts +++ b/sdk/maps/maps-route-rest/samples-dev/resumeLro.ts @@ -6,15 +6,13 @@ */ import { DefaultAzureCredential } from "@azure/identity"; +import type { RouteGetRouteDirectionsBatch200Response } from "@azure-rest/maps-route"; import MapsRoute, { createRouteDirectionsBatchRequest, getLongRunningPoller, - RouteGetRouteDirectionsBatch200Response, toColonDelimitedLatLonString, } from "@azure-rest/maps-route"; -import * as dotenv from "dotenv"; - -dotenv.config(); +import "dotenv/config"; /** * With the help from the long running operation poller, we can resume a long running request. diff --git a/sdk/maps/maps-route-rest/generated/clientDefinitions.ts b/sdk/maps/maps-route-rest/src/generated/clientDefinitions.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/clientDefinitions.ts rename to sdk/maps/maps-route-rest/src/generated/clientDefinitions.ts diff --git a/sdk/maps/maps-route-rest/generated/index.ts b/sdk/maps/maps-route-rest/src/generated/index.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/index.ts rename to sdk/maps/maps-route-rest/src/generated/index.ts diff --git a/sdk/maps/maps-route-rest/generated/isUnexpected.ts b/sdk/maps/maps-route-rest/src/generated/isUnexpected.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/isUnexpected.ts rename to sdk/maps/maps-route-rest/src/generated/isUnexpected.ts diff --git a/sdk/maps/maps-route-rest/generated/logger.ts b/sdk/maps/maps-route-rest/src/generated/logger.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/logger.ts rename to sdk/maps/maps-route-rest/src/generated/logger.ts diff --git a/sdk/maps/maps-route-rest/generated/mapsRouteClient.ts b/sdk/maps/maps-route-rest/src/generated/mapsRouteClient.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/mapsRouteClient.ts rename to sdk/maps/maps-route-rest/src/generated/mapsRouteClient.ts diff --git a/sdk/maps/maps-route-rest/generated/models.ts b/sdk/maps/maps-route-rest/src/generated/models.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/models.ts rename to sdk/maps/maps-route-rest/src/generated/models.ts diff --git a/sdk/maps/maps-route-rest/generated/outputModels.ts b/sdk/maps/maps-route-rest/src/generated/outputModels.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/outputModels.ts rename to sdk/maps/maps-route-rest/src/generated/outputModels.ts diff --git a/sdk/maps/maps-route-rest/generated/parameters.ts b/sdk/maps/maps-route-rest/src/generated/parameters.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/parameters.ts rename to sdk/maps/maps-route-rest/src/generated/parameters.ts diff --git a/sdk/maps/maps-route-rest/generated/pollingHelper.ts b/sdk/maps/maps-route-rest/src/generated/pollingHelper.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/pollingHelper.ts rename to sdk/maps/maps-route-rest/src/generated/pollingHelper.ts diff --git a/sdk/maps/maps-route-rest/generated/responses.ts b/sdk/maps/maps-route-rest/src/generated/responses.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/responses.ts rename to sdk/maps/maps-route-rest/src/generated/responses.ts diff --git a/sdk/maps/maps-route-rest/generated/serializeHelper.ts b/sdk/maps/maps-route-rest/src/generated/serializeHelper.ts similarity index 100% rename from sdk/maps/maps-route-rest/generated/serializeHelper.ts rename to sdk/maps/maps-route-rest/src/generated/serializeHelper.ts diff --git a/sdk/maps/maps-route-rest/src/helpers.ts b/sdk/maps/maps-route-rest/src/helpers.ts index d0e4b33f1fb0..59170a62323c 100644 --- a/sdk/maps/maps-route-rest/src/helpers.ts +++ b/sdk/maps/maps-route-rest/src/helpers.ts @@ -5,7 +5,7 @@ import type { LatLon } from "@azure/maps-common"; import type { BatchRequest, RouteGetRouteDirectionsQueryParamProperties, -} from "../generated/index.js"; +} from "./generated/index.js"; function toLatLonString(coordinates: LatLon): string { return `${coordinates[0]},${coordinates[1]}`; diff --git a/sdk/maps/maps-route-rest/src/index.ts b/sdk/maps/maps-route-rest/src/index.ts index 1eefe4c4b44f..ab7a5f13ed86 100644 --- a/sdk/maps/maps-route-rest/src/index.ts +++ b/sdk/maps/maps-route-rest/src/index.ts @@ -3,7 +3,7 @@ import MapsRoute from "./mapsRoute.js"; -export * from "../generated/index.js"; +export * from "./generated/index.js"; export * from "./helpers.js"; export default MapsRoute; diff --git a/sdk/maps/maps-route-rest/src/mapsRoute.ts b/sdk/maps/maps-route-rest/src/mapsRoute.ts index a5a661620e0d..b26c9625c968 100644 --- a/sdk/maps/maps-route-rest/src/mapsRoute.ts +++ b/sdk/maps/maps-route-rest/src/mapsRoute.ts @@ -5,8 +5,8 @@ import type { ClientOptions } from "@azure-rest/core-client"; import type { AzureKeyCredential, AzureSASCredential, TokenCredential } from "@azure/core-auth"; import { isSASCredential, isTokenCredential } from "@azure/core-auth"; import { createMapsClientIdPolicy } from "@azure/maps-common"; -import type { MapsRouteClient } from "../generated/index.js"; -import createClient from "../generated/index.js"; +import type { MapsRouteClient } from "./generated/index.js"; +import createClient from "./generated/index.js"; import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline"; /** diff --git a/sdk/maps/maps-route-rest/swagger/README.md b/sdk/maps/maps-route-rest/swagger/README.md index d1db6ad21a31..5eb1df35f9f4 100644 --- a/sdk/maps/maps-route-rest/swagger/README.md +++ b/sdk/maps/maps-route-rest/swagger/README.md @@ -22,7 +22,7 @@ generate-metadata: false generate-test: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../ -source-code-folder-path: ./generated +source-code-folder-path: ./src/generated input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/maps/data-plane/Route/preview/1.0/route.json package-version: 1.0.0-beta.4 rest-level-client: true diff --git a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts index a2bcbdb6630c..58bbfb7ad0a2 100644 --- a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. + import type { RouteDirectionParameters, RouteMatrixQuery } from "../../src/index.js"; import { createRouteDirectionsBatchRequest, @@ -13,30 +14,25 @@ import type { RouteGetRouteDirectionsBatch200Response, RouteGetRouteDirectionsQueryParamProperties, RouteGetRouteMatrix200Response, -} from "../../generated/index.js"; -import { getLongRunningPoller, isUnexpected } from "../../generated/index.js"; +} from "../../src/generated/index.js"; +import { getLongRunningPoller, isUnexpected } from "../../src/generated/index.js"; import type { LatLon } from "@azure/maps-common"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; -describe("Endpoint can be overwritten", function (this: Suite) { +describe("Endpoint can be overwritten", () => { let recorder: Recorder; - const fastTimeout = 10000; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { testLogger.verbose(`Recorder: starting...`); - recorder = await createRecorder(this); + recorder = await createRecorder(ctx); }); - afterEach(async function () { + afterEach(async () => { testLogger.verbose(`Recorder: stopping...`); await recorder.stop(); }); - before(function (ctx) { - this.timeout(fastTimeout); - }); - - it("should be executed without specifying baseUrl", async function () { + it("should be executed without specifying baseUrl", async () => { const client = createClient(recorder.configureClientOptions({})); const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({ queryParameters: { @@ -50,7 +46,7 @@ describe("Endpoint can be overwritten", function (this: Suite) { assert.isOk(!isUnexpected(routeDirectionsResult)); }); - it("should be executed with different baseUrl", async function () { + it("should be executed with different baseUrl", async () => { const client = createClient( recorder.configureClientOptions({ baseUrl: "https://us.atlas.microsoft.com/" }), ); @@ -67,27 +63,23 @@ describe("Endpoint can be overwritten", function (this: Suite) { }); }); -describe("Get Route Directions", function (this: Suite) { +describe("Get Route Directions", () => { let recorder: Recorder; let client: MapsRouteClient; const fastTimeout = 10000; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { testLogger.verbose(`Recorder: starting...`); - recorder = await createRecorder(this); + recorder = await createRecorder(ctx); client = createClient(recorder.configureClientOptions({})); }); - afterEach(async function () { + afterEach(async () => { testLogger.verbose(`Recorder: stopping...`); await recorder.stop(); }); - before(function (ctx) { - this.timeout(fastTimeout); - }); - - it("should accept LatLon[] and return route directions", async function () { + it("should accept LatLon[] and return route directions", async () => { const routePoints: LatLon[] = [ [52.50931, 13.42936], [52.50274, 13.43872], @@ -103,7 +95,7 @@ describe("Get Route Directions", function (this: Suite) { } }); - it("should accept additional parameters and return route directions", async function () { + it("should accept additional parameters and return route directions", async () => { const routePoints: LatLon[] = [ [47.6133869, -122.0235832], [47.5565375, -122.1411044], @@ -137,27 +129,22 @@ describe("Get Route Directions", function (this: Suite) { }); }); -describe("Get Route Range", function () { +describe("Get Route Range", () => { let recorder: Recorder; let client: MapsRouteClient; - const fastTimeout = 10000; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { testLogger.verbose(`Recorder: starting...`); - recorder = await createRecorder(this); + recorder = await createRecorder(ctx); client = createClient(recorder.configureClientOptions({})); }); - afterEach(async function () { + afterEach(async () => { testLogger.verbose(`Recorder: stopping...`); await recorder.stop(); }); - before(function (ctx) { - this.timeout(fastTimeout); - }); - - it("should accept LatLon and return reachable range", async function () { + it("should accept LatLon and return reachable range", async () => { const startCoordinates: LatLon = [50.97452, 5.86605]; const routeRangeResult = await client @@ -171,29 +158,23 @@ describe("Get Route Range", function () { }); }); -describe("LRO", function (this: Suite) { +describe("LRO", () => { let recorder: Recorder; let client: MapsRouteClient; - const CLITimeout = this.timeout(); - const fastTimeout = 10000; - beforeEach(async function (ctx) { - recorder = await createRecorder(this); + beforeEach(async (ctx) => { + recorder = await createRecorder(ctx); client = createClient(recorder.configureClientOptions({})); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); const pollingInterval = isPlaybackMode() ? 0 : 2000; - before(function (ctx) { - this.timeout(isPlaybackMode() ? fastTimeout : CLITimeout); - }); - - describe("Begin Request Route Directions Batch", function () { - it("could take an array of route directions requests as input", async function () { + describe("Begin Request Route Directions Batch", () => { + it("could take an array of route directions requests as input", async () => { const batchRequests: RouteGetRouteDirectionsQueryParamProperties[] = [ { query: toColonDelimitedLatLonString([ @@ -237,8 +218,8 @@ describe("LRO", function (this: Suite) { }); }); - describe("Resume Route Directions Batch Result", function () { - it("should be able to resume the previous request", async function () { + describe("Resume Route Directions Batch Result", () => { + it("should be able to resume the previous request", async () => { const batchRequests: RouteGetRouteDirectionsQueryParamProperties[] = [ { query: toColonDelimitedLatLonString([ @@ -290,7 +271,7 @@ describe("LRO", function (this: Suite) { assert.equal(batchResult.body.batchItems.length, batchRequests.length); }); - it("should obtain the same result from the rehydrated poller after the lro is finished", async function () { + it("should obtain the same result from the rehydrated poller after the lro is finished", async () => { const batchRequests: RouteGetRouteDirectionsQueryParamProperties[] = [ { query: toColonDelimitedLatLonString([ @@ -343,8 +324,8 @@ describe("LRO", function (this: Suite) { }); }); - describe("Begin Request Route Matrix", function () { - it("should accept routeMatrixQuery as input", async function () { + describe("Begin Request Route Matrix", () => { + it("should accept routeMatrixQuery as input", async () => { const routeMatrixQuery: RouteMatrixQuery = { origins: { type: "MultiPoint", @@ -376,8 +357,8 @@ describe("LRO", function (this: Suite) { }); }); - describe("Resume Get Route Matrix Result", function () { - it("should be able to resume the previous request", async function () { + describe("Resume Get Route Matrix Result", () => { + it("should be able to resume the previous request", async () => { const routeMatrixQuery: RouteMatrixQuery = { origins: { type: "MultiPoint", @@ -417,7 +398,7 @@ describe("LRO", function (this: Suite) { assert.equal(routeMatrixResult.body.summary.totalRoutes, 4); }); - it("should obtain the same result as beginRequestRouteMatrix ", async function () { + it("should obtain the same result as beginRequestRouteMatrix ", async () => { const routeMatrixQuery: RouteMatrixQuery = { origins: { type: "MultiPoint", diff --git a/sdk/maps/maps-route-rest/test/public/utils/env.browser.ts b/sdk/maps/maps-route-rest/test/public/utils/env-browser.mts similarity index 100% rename from sdk/maps/maps-route-rest/test/public/utils/env.browser.ts rename to sdk/maps/maps-route-rest/test/public/utils/env-browser.mts diff --git a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts index a3861ffacb7c..11597aca2bac 100644 --- a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts +++ b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder"; import { Recorder, env } from "@azure-tools/test-recorder"; import "./env.js"; import { createClientLogger } from "@azure/logger"; @@ -22,8 +22,8 @@ const recorderEnvSetup: RecorderStartOptions = { * Should be called first in the test suite to make sure environment variables are * read before they are being used. */ -export async function createRecorder(context: Context): Promise { - const recorder = new Recorder(context.currentTest); +export async function createRecorder(context: TestInfo): Promise { + const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; } diff --git a/sdk/maps/maps-route-rest/vitest.browser.config.ts b/sdk/maps/maps-route-rest/vitest.browser.config.ts index b48c61b2ef46..50ec2d5489b0 100644 --- a/sdk/maps/maps-route-rest/vitest.browser.config.ts +++ b/sdk/maps/maps-route-rest/vitest.browser.config.ts @@ -1,4 +1,3 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. @@ -9,9 +8,9 @@ export default mergeConfig( viteConfig, defineConfig({ test: { - include: [ - "dist-test/browser/test/**/*.spec.js", - ], + include: ["dist-test/browser/test/**/*.spec.js"], + hookTimeout: 5000000, + testTimeout: 5000000, }, }), ); diff --git a/sdk/maps/maps-route-rest/vitest.config.ts b/sdk/maps/maps-route-rest/vitest.config.ts index 39267dd2f56f..d01fdec8ac69 100644 --- a/sdk/maps/maps-route-rest/vitest.config.ts +++ b/sdk/maps/maps-route-rest/vitest.config.ts @@ -1,4 +1,3 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. @@ -10,6 +9,8 @@ export default mergeConfig( defineConfig({ test: { include: ["test/**/*.spec.ts"], + hookTimeout: 5000000, + testTimeout: 5000000, }, }), ); From ef8177bb2beb0b96f4f75b9646de427ada588959 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Mon, 25 Nov 2024 14:58:36 -0500 Subject: [PATCH 13/13] [maps] Upgrade @azure-rest/maps-route to ESM/vitest --- sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts | 1 - sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts index 58bbfb7ad0a2..38ff6edcd6b1 100644 --- a/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts +++ b/sdk/maps/maps-route-rest/test/public/mapsRouteClient.spec.ts @@ -66,7 +66,6 @@ describe("Endpoint can be overwritten", () => { describe("Get Route Directions", () => { let recorder: Recorder; let client: MapsRouteClient; - const fastTimeout = 10000; beforeEach(async (ctx) => { testLogger.verbose(`Recorder: starting...`); diff --git a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts index 11597aca2bac..3d76cebb4825 100644 --- a/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts +++ b/sdk/maps/maps-route-rest/test/public/utils/recordedClient.ts @@ -7,7 +7,7 @@ import { createClientLogger } from "@azure/logger"; import { createTestCredential } from "@azure-tools/test-credential"; import MapsRoute from "../../../src/mapsRoute.js"; import type { ClientOptions } from "@azure-rest/core-client"; -import type { MapsRouteClient } from "../../../generated/index.js"; +import type { MapsRouteClient } from "../../../src/generated/index.js"; const envSetupForPlayback: Record = { MAPS_RESOURCE_CLIENT_ID: "azure_maps_client_id",