From 18fe8bfc3f26e5574fba62fce578204406130fb6 Mon Sep 17 00:00:00 2001 From: Matthew Podwysocki Date: Tue, 19 Nov 2024 13:21:18 -0500 Subject: [PATCH] [communication] Migrate @azure/communication-rooms to ESM/vitest (#31840) ### Packages impacted by this PR - @azure/communication-rooms ### 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/communication-rooms using our migration tool to ESM/vitest ### 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 | 80 +++++++++-- sdk/communication/communication-rooms/.nycrc | 10 -- .../communication-rooms/api-extractor.json | 4 +- .../communication-rooms/karma.conf.js | 127 ------------------ .../communication-rooms/package.json | 109 +++++++++------ .../src/generated/src/index.ts | 8 +- .../src/generated/src/models/parameters.ts | 2 +- .../src/generated/src/operations/index.ts | 4 +- .../generated/src/operations/participants.ts | 12 +- .../src/generated/src/operations/rooms.ts | 12 +- .../src/operationsInterfaces/index.ts | 4 +- .../src/operationsInterfaces/participants.ts | 2 +- .../src/operationsInterfaces/rooms.ts | 2 +- .../src/generated/src/roomsRestClient.ts | 6 +- .../communication-rooms/src/index.ts | 6 +- .../communication-rooms/src/models/mappers.ts | 6 +- .../communication-rooms/src/models/options.ts | 2 +- .../communication-rooms/src/roomsClient.ts | 12 +- .../test/internal/roomsClient.mocked.spec.ts | 57 ++++---- .../test/internal/utils/mockedClient.ts | 4 +- .../test/public/roomsClient.spec.ts | 87 ++++++------ .../test/public/utils/connectionUtils.ts | 4 +- .../test/public/utils/recordedClient.ts | 17 ++- .../tsconfig.browser.config.json | 10 ++ .../communication-rooms/tsconfig.json | 9 +- .../vitest.browser.config.ts | 16 +++ .../communication-rooms/vitest.config.ts | 16 +++ 27 files changed, 307 insertions(+), 321 deletions(-) delete mode 100644 sdk/communication/communication-rooms/.nycrc delete mode 100644 sdk/communication/communication-rooms/karma.conf.js create mode 100644 sdk/communication/communication-rooms/tsconfig.browser.config.json create mode 100644 sdk/communication/communication-rooms/vitest.browser.config.ts create mode 100644 sdk/communication/communication-rooms/vitest.config.ts diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 6a78239fa1c1..07510e3e840c 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -4538,6 +4538,40 @@ packages: - vite dev: false + /@vitest/browser@2.1.5(@types/node@18.19.64)(playwright@1.49.0)(typescript@5.6.3)(vitest@2.1.5): + resolution: {integrity: sha512-JrpnxvkrjlBrF7oXbK/YytWVYfJIzWYeDKppANlUaisBKwDso+yXlWocAJrANx8gUxyirF355Yx80S+SKQqayg==} + peerDependencies: + playwright: '*' + safaridriver: '*' + vitest: 2.1.5 + webdriverio: '*' + peerDependenciesMeta: + playwright: + optional: true + safaridriver: + optional: true + webdriverio: + optional: true + dependencies: + '@testing-library/dom': 10.4.0 + '@testing-library/user-event': 14.5.2(@testing-library/dom@10.4.0) + '@vitest/mocker': 2.1.5(msw@2.6.4) + '@vitest/utils': 2.1.5 + magic-string: 0.30.12 + msw: 2.6.4(@types/node@18.19.64)(typescript@5.6.3) + playwright: 1.49.0 + sirv: 3.0.0 + tinyrainbow: 1.2.0 + vitest: 2.1.5(@types/node@18.19.64)(@vitest/browser@2.1.5) + ws: 8.18.0 + transitivePeerDependencies: + - '@types/node' + - bufferutil + - typescript + - utf-8-validate + - vite + dev: false + /@vitest/coverage-istanbul@1.6.0(vitest@1.6.0): resolution: {integrity: sha512-h/BwpXehkkS0qsNCS00QxiupAqVkNi0WT19BR0dQvlge5oHghoSVLx63fABYFoKxVb7Ue7+k6V2KokmQ1zdMpg==} peerDependencies: @@ -9351,6 +9385,12 @@ packages: hasBin: true dev: false + /playwright-core@1.49.0: + resolution: {integrity: sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==} + engines: {node: '>=18'} + hasBin: true + dev: false + /playwright@1.48.2: resolution: {integrity: sha512-NjYvYgp4BPmiwfe31j4gHLa3J7bD2WiBz8Lk2RoSsmX38SVIARZ18VYjxLjAcDsAhA+F4iSEXTSGgjua0rrlgQ==} engines: {node: '>=18'} @@ -9361,6 +9401,16 @@ packages: fsevents: 2.3.2 dev: false + /playwright@1.49.0: + resolution: {integrity: sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==} + engines: {node: '>=18'} + hasBin: true + dependencies: + playwright-core: 1.49.0 + optionalDependencies: + fsevents: 2.3.2 + dev: false + /polite-json@5.0.0: resolution: {integrity: sha512-OLS/0XeUAcE8a2fdwemNja+udKgXNnY6yKVIXqAD2zVRx1KvY6Ato/rZ2vdzbxqYwPW0u6SCNC/bAMPNzpzxbw==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} @@ -10910,10 +10960,6 @@ packages: walk-up-path: 3.0.1 dev: false - /tslib@1.14.1: - resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} - dev: false - /tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} dev: false @@ -19522,7 +19568,7 @@ packages: dev: false file:projects/communication-rooms.tgz: - resolution: {integrity: sha512-P7jfhBHPpmbT+F7ZiIsSE6UE2c3eH3VurYQSyRaYxcCuKRvzccHbqk1RtO0SyPiDjPTgxjGnAHnexI18C2+UeQ==, tarball: file:projects/communication-rooms.tgz} + resolution: {integrity: sha512-F/7ZgMfumTgdSJXk4iLzYs3cbwxW08iZlD3OjjDYAqkYG/qodpxjdwjDxneSeXLPaIDUwYBnz9S7LTTzvSGtcA==, tarball: file:projects/communication-rooms.tgz} name: '@rush-temp/communication-rooms' version: 0.0.0 dependencies: @@ -19532,6 +19578,8 @@ packages: '@types/mocha': 10.0.9 '@types/node': 18.19.64 '@types/sinon': 17.0.3 + '@vitest/browser': 2.1.5(@types/node@18.19.64)(playwright@1.49.0)(typescript@5.6.3)(vitest@2.1.5) + '@vitest/coverage-istanbul': 2.1.5(vitest@2.1.5) chai: 4.3.10 dotenv: 16.4.5 eslint: 9.14.0 @@ -19539,18 +19587,32 @@ packages: karma-env-preprocessor: 0.1.1 mocha: 10.8.2 nyc: 17.1.0 + playwright: 1.49.0 sinon: 17.0.1 ts-node: 10.9.2(@types/node@18.19.64)(typescript@5.6.3) - tslib: 1.14.1 + tslib: 2.8.1 typescript: 5.6.3 + vitest: 2.1.5(@types/node@18.19.64)(@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/communication-short-codes.tgz: diff --git a/sdk/communication/communication-rooms/.nycrc b/sdk/communication/communication-rooms/.nycrc deleted file mode 100644 index 29174b423579..000000000000 --- a/sdk/communication/communication-rooms/.nycrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "include": ["dist-esm/src/**/*.js"], - "exclude": ["**/*.d.ts", "dist-esm/src/generated/*"], - "reporter": ["text-summary", "html", "cobertura"], - "exclude-after-remap": false, - "sourceMap": true, - "produce-source-map": true, - "instrument": true, - "all": true -} diff --git a/sdk/communication/communication-rooms/api-extractor.json b/sdk/communication/communication-rooms/api-extractor.json index f47cb6f46dc6..65ad997b8933 100644 --- a/sdk/communication/communication-rooms/api-extractor.json +++ b/sdk/communication/communication-rooms/api-extractor.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "types/src/index.d.ts", + "mainEntryPointFilePath": "dist/esm/index.d.ts", "docModel": { "enabled": true }, @@ -11,7 +11,7 @@ "dtsRollup": { "enabled": true, "untrimmedFilePath": "", - "publicTrimmedFilePath": "./types/communication-rooms.d.ts" + "publicTrimmedFilePath": "dist/communication-rooms.d.ts" }, "messages": { "tsdocMessageReporting": { diff --git a/sdk/communication/communication-rooms/karma.conf.js b/sdk/communication/communication-rooms/karma.conf.js deleted file mode 100644 index f95d5eee9346..000000000000 --- a/sdk/communication/communication-rooms/karma.conf.js +++ /dev/null @@ -1,127 +0,0 @@ -// https://github.com/karma-runner/karma-chrome-launcher -process.env.CHROME_BIN = require("puppeteer").executablePath(); -const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); - -require("dotenv").config(); - -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: ["mocha"], - - plugins: [ - "karma-mocha", - "karma-mocha-reporter", - "karma-chrome-launcher", - "karma-firefox-launcher", - "karma-env-preprocessor", - "karma-coverage", - "karma-sourcemap-loader", - "karma-junit-reporter", - ], - - // list of files / patterns to load in the browser - files: ["dist-test/index.browser.js"], - - // 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.browser.js": ["coverage"] - }, - - // inject following environment values into browser testing with window.__env__ - // environment values MUST be exported or set with same console running "karma start" - // https://www.npmjs.com/package/karma-env-preprocessor - envPreprocessor: [ - "TEST_MODE", - "COMMUNICATION_CONNECTION_STRING_ROOMS", - "COMMUNICATION_SAMPLES_CONNECTION_STRING", - "BASE_URL", - "COMMUNICATION_ENDPOINT", - "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, - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - // 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE' - browsers: ["HeadlessChrome"], - - customLaunchers: { - HeadlessChrome: { - base: "ChromeHeadless", - flags: ["--no-sandbox"], - }, - }, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: 1, - - browserNoActivityTimeout: 600000, - browserDisconnectTimeout: 10000, - browserDisconnectTolerance: 3, - - client: { - mocha: { - // change Karma's debug.html to the mocha web reporter - reporter: "html", - timeout: "600000", - }, - }, - }); -}; diff --git a/sdk/communication/communication-rooms/package.json b/sdk/communication/communication-rooms/package.json index 7995fb4f44fc..183061454bac 100644 --- a/sdk/communication/communication-rooms/package.json +++ b/sdk/communication/communication-rooms/package.json @@ -9,14 +9,14 @@ }, "dependencies": { "@azure/communication-common": "^2.3.1", - "@azure/core-auth": "^1.3.2", - "@azure/core-client": "^1.6.0", - "@azure/core-paging": "^1.5.0", - "@azure/core-rest-pipeline": "^1.3.0", - "@azure/core-tracing": "^1.0.0", - "@azure/core-util": "^1.6.1", - "@azure/logger": "^1.0.0", - "tslib": "^1.9.3" + "@azure/core-auth": "^1.9.0", + "@azure/core-client": "^1.9.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.0", + "@azure/core-tracing": "^1.2.0", + "@azure/core-util": "^1.11.0", + "@azure/logger": "^1.1.4", + "tslib": "^2.8.1" }, "keywords": [ "node", @@ -30,31 +30,24 @@ "cloud" ], "license": "MIT", - "main": "dist/index.js", - "module": "dist-esm/src/index.js", - "types": "types/communication-rooms.d.ts", + "main": "./dist/commonjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/commonjs/index.d.ts", "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.0.0", - "@azure-tools/test-utils": "~1.0.0", - "@azure/communication-identity": "^1.1.0-beta.2", - "@azure/core-auth": "^1.3.0", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.1.0", + "@azure-tools/test-utils-vitest": "^1.0.0", + "@azure/communication-identity": "^1.3.1", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@types/chai": "~4.3.1", - "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", - "@types/sinon": "^17.0.0", - "chai": "^4.2.0", + "@vitest/browser": "^2.1.5", + "@vitest/coverage-istanbul": "^2.1.5", "dotenv": "^16.0.0", "eslint": "^9.9.0", - "karma": "^6.2.0", - "karma-env-preprocessor": "^0.1.1", - "mocha": "^10.0.0", - "nyc": "^17.0.0", - "sinon": "^17.0.0", - "ts-node": "^10.0.0", - "typescript": "~5.6.2" + "playwright": "^1.49.0", + "typescript": "~5.6.2", + "vitest": "^2.1.5" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-rooms/", "repository": "github:Azure/azure-sdk-for-js", @@ -63,35 +56,33 @@ }, "files": [ "dist/", - "dist-esm/src/", - "types/communication-rooms.d.ts", "README.md", "LICENSE" ], "scripts": { - "build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run extract-api", - "build:browser": "tsc -p . && dev-tool run bundle", - "build:node": "tsc -p . && dev-tool run bundle", + "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:node": "dev-tool run build-package && dev-tool run bundle", "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-* temp types *.tgz *.log", "execute:samples": "dev-tool samples run samples-dev", - "extract-api": "tsc -p . && dev-tool run extract-api", + "extract-api": "dev-tool run build-package && dev-tool run extract-api", "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 --disable-async-iterators ./swagger/README.md && rushx 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'", - "lint": "eslint package.json api-extractor.json README.md src test", - "lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]", + "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": "dev-tool run vendored eslint package.json api-extractor.json README.md src test", + "lint:fix": "dev-tool run vendored eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", "test": "npm run build:test && npm run unit-test && npm run integration-test", "test:browser": "npm run build:test && npm run unit-test:browser", "test:node": "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 vendored cross-env TS_NODE_FILES=true TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\":\\\"commonjs\\\"}\" dev-tool run test:node-ts-input -- --timeout 1200000 '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, @@ -118,5 +109,43 @@ "requiredResources": { "Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource" } + }, + "type": "module", + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false + }, + "browser": "./dist/browser/index.js", + "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/communication/communication-rooms/src/generated/src/index.ts b/sdk/communication/communication-rooms/src/generated/src/index.ts index 71e47769e5a4..fce4bd93d32b 100644 --- a/sdk/communication/communication-rooms/src/generated/src/index.ts +++ b/sdk/communication/communication-rooms/src/generated/src/index.ts @@ -7,7 +7,7 @@ */ /// -export { getContinuationToken } from "./pagingHelper"; -export * from "./models"; -export { RoomsRestClient } from "./roomsRestClient"; -export * from "./operationsInterfaces"; +export { getContinuationToken } from "./pagingHelper.js"; +export * from "./models/index.js"; +export { RoomsRestClient } from "./roomsRestClient.js"; +export * from "./operationsInterfaces/index.js"; diff --git a/sdk/communication/communication-rooms/src/generated/src/models/parameters.ts b/sdk/communication/communication-rooms/src/generated/src/models/parameters.ts index 8d5371288937..85a8e0132847 100644 --- a/sdk/communication/communication-rooms/src/generated/src/models/parameters.ts +++ b/sdk/communication/communication-rooms/src/generated/src/models/parameters.ts @@ -15,7 +15,7 @@ import { CreateRoomRequest as CreateRoomRequestMapper, UpdateRoomRequest as UpdateRoomRequestMapper, UpdateParticipantsRequest as UpdateParticipantsRequestMapper, -} from "../models/mappers"; +} from "../models/mappers.js"; export const contentType: OperationParameter = { parameterPath: ["options", "contentType"], diff --git a/sdk/communication/communication-rooms/src/generated/src/operations/index.ts b/sdk/communication/communication-rooms/src/generated/src/operations/index.ts index f6a3087c1549..937d8ab195a4 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operations/index.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operations/index.ts @@ -6,5 +6,5 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -export * from "./rooms"; -export * from "./participants"; +export * from "./rooms.js"; +export * from "./participants.js"; diff --git a/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts b/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts index 2ba1a5739fe9..9c70122cdaf0 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operations/participants.ts @@ -6,12 +6,12 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { tracingClient } from "../tracing"; -import { Participants } from "../operationsInterfaces"; +import { tracingClient } from "../tracing.js"; +import { Participants } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; -import * as Mappers from "../models/mappers"; -import * as Parameters from "../models/parameters"; -import { RoomsRestClient } from "../roomsRestClient"; +import * as Mappers from "../models/mappers.js"; +import * as Parameters from "../models/parameters.js"; +import { RoomsRestClient } from "../roomsRestClient.js"; import { ParticipantsListOptionalParams, ParticipantsListResponse, @@ -19,7 +19,7 @@ import { ParticipantsUpdateResponse, ParticipantsListNextOptionalParams, ParticipantsListNextResponse -} from "../models"; +} from "../models/index.js"; /** Class containing Participants operations. */ export class ParticipantsImpl implements Participants { diff --git a/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts b/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts index 86a105eb7fe1..30593f9c7663 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operations/rooms.ts @@ -6,12 +6,12 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { tracingClient } from "../tracing"; -import { Rooms } from "../operationsInterfaces"; +import { tracingClient } from "../tracing.js"; +import { Rooms } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; -import * as Mappers from "../models/mappers"; -import * as Parameters from "../models/parameters"; -import { RoomsRestClient } from "../roomsRestClient"; +import * as Mappers from "../models/mappers.js"; +import * as Parameters from "../models/parameters.js"; +import { RoomsRestClient } from "../roomsRestClient.js"; import { RoomsCreateOptionalParams, RoomsCreateResponse, @@ -24,7 +24,7 @@ import { RoomsDeleteOptionalParams, RoomsListNextOptionalParams, RoomsListNextResponse -} from "../models"; +} from "../models/index.js"; /** Class containing Rooms operations. */ export class RoomsImpl implements Rooms { diff --git a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/index.ts b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/index.ts index f6a3087c1549..937d8ab195a4 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/index.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/index.ts @@ -6,5 +6,5 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -export * from "./rooms"; -export * from "./participants"; +export * from "./rooms.js"; +export * from "./participants.js"; diff --git a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts index 333b5ef1d0f9..7e04d0709ccb 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/participants.ts @@ -13,7 +13,7 @@ import { ParticipantsUpdateResponse, ParticipantsListNextOptionalParams, ParticipantsListNextResponse -} from "../models"; +} from "../models/index.js"; /** Interface representing a Participants. */ export interface Participants { diff --git a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts index 137e93a486d3..5a5b60809e1c 100644 --- a/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts +++ b/sdk/communication/communication-rooms/src/generated/src/operationsInterfaces/rooms.ts @@ -18,7 +18,7 @@ import { RoomsDeleteOptionalParams, RoomsListNextOptionalParams, RoomsListNextResponse -} from "../models"; +} from "../models/index.js"; /** Interface representing a Rooms. */ export interface Rooms { diff --git a/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts b/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts index 6608067babc7..74c7c216fd72 100644 --- a/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts +++ b/sdk/communication/communication-rooms/src/generated/src/roomsRestClient.ts @@ -12,9 +12,9 @@ import { PipelineResponse, SendRequest, } from "@azure/core-rest-pipeline"; -import { RoomsImpl, ParticipantsImpl } from "./operations"; -import { Rooms, Participants } from "./operationsInterfaces"; -import { RoomsRestClientOptionalParams } from "./models"; +import { RoomsImpl, ParticipantsImpl } from "./operations/index.js"; +import { Rooms, Participants } from "./operationsInterfaces/index.js"; +import { RoomsRestClientOptionalParams } from "./models/index.js"; export class RoomsRestClient extends coreClient.ServiceClient { endpoint: string; diff --git a/sdk/communication/communication-rooms/src/index.ts b/sdk/communication/communication-rooms/src/index.ts index de20c30512e4..c88c8d372816 100644 --- a/sdk/communication/communication-rooms/src/index.ts +++ b/sdk/communication/communication-rooms/src/index.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -export * from "./models/options"; -export * from "./models/models"; -export * from "./roomsClient"; +export * from "./models/options.js"; +export * from "./models/models.js"; +export * from "./roomsClient.js"; diff --git a/sdk/communication/communication-rooms/src/models/mappers.ts b/sdk/communication/communication-rooms/src/models/mappers.ts index 8e5f73c01f27..68ef1f661231 100644 --- a/sdk/communication/communication-rooms/src/models/mappers.ts +++ b/sdk/communication/communication-rooms/src/models/mappers.ts @@ -1,19 +1,19 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type * as RestModel from "../generated/src/models"; +import type * as RestModel from "../generated/src/models/index.js"; import type { CommunicationRoom, ParticipantRole, RoomParticipant, RoomParticipantPatch, -} from "./models"; +} from "./models.js"; import type { CommunicationIdentifier } from "@azure/communication-common"; import { getIdentifierKind, getIdentifierRawId } from "@azure/communication-common"; import type { ParticipantProperties, RoomParticipant as RESTRoomParticipant, -} from "../generated/src/models"; +} from "../generated/src/models/index.js"; import { createIdentifierFromRawId } from "@azure/communication-common"; const defaultRole: ParticipantRole = "Attendee"; diff --git a/sdk/communication/communication-rooms/src/models/options.ts b/sdk/communication/communication-rooms/src/models/options.ts index e9acf3e80390..3da303285dc3 100644 --- a/sdk/communication/communication-rooms/src/models/options.ts +++ b/sdk/communication/communication-rooms/src/models/options.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import type { CommonClientOptions, OperationOptions } from "@azure/core-client"; -import type { RoomParticipantPatch } from "./models"; +import type { RoomParticipantPatch } from "./models.js"; /** * Options to create rooms client. diff --git a/sdk/communication/communication-rooms/src/roomsClient.ts b/sdk/communication/communication-rooms/src/roomsClient.ts index 13e4f8d3d2ba..7eff38998e80 100644 --- a/sdk/communication/communication-rooms/src/roomsClient.ts +++ b/sdk/communication/communication-rooms/src/roomsClient.ts @@ -10,16 +10,16 @@ import { parseClientArguments, } from "@azure/communication-common"; -import { logger } from "./logger"; -import { tracingClient } from "./tracing"; -import { RoomsRestClient } from "./generated/src"; +import { logger } from "./logger.js"; +import { tracingClient } from "./tracing.js"; +import { RoomsRestClient } from "./generated/src/index.js"; import { mapCommunicationRoomToSDKModel, mapRoomParticipantForRemoval, mapRoomParticipantToRawId, mapToRoomParticipantSDKModel, -} from "./models/mappers"; -import type { CommunicationRoom, RoomParticipantPatch, RoomParticipant } from "./models/models"; +} from "./models/mappers.js"; +import type { CommunicationRoom, RoomParticipantPatch, RoomParticipant } from "./models/models.js"; import type { CreateRoomOptions, DeleteRoomOptions, @@ -30,7 +30,7 @@ import type { RoomsClientOptions, UpdateRoomOptions, AddOrUpdateParticipantsOptions, -} from "./models/options"; +} from "./models/options.js"; import { randomUUID } from "@azure/core-util"; import type { PagedAsyncIterableIterator } from "@azure/core-paging"; diff --git a/sdk/communication/communication-rooms/test/internal/roomsClient.mocked.spec.ts b/sdk/communication/communication-rooms/test/internal/roomsClient.mocked.spec.ts index fbab3f57100f..84861be5a97c 100644 --- a/sdk/communication/communication-rooms/test/internal/roomsClient.mocked.spec.ts +++ b/sdk/communication/communication-rooms/test/internal/roomsClient.mocked.spec.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import sinon from "sinon"; -import { assert } from "chai"; -import type { RoomsClient } from "../../src"; +import type { RoomsClient } from "../../src/index.js"; import { createRoomsClient, generateHttpClient, @@ -13,26 +11,23 @@ import { mockListRoomsResultWithoutNextLink, mockCreateRoomsWithPstnDialOutEnabledResult, mockUpdateRoomsWithPstnEnabledResult, -} from "./utils/mockedClient"; +} from "./utils/mockedClient.js"; +import { describe, it, assert, expect, vi } from "vitest"; -describe("[Mocked] RoomsClient", async function () { +describe("[Mocked] RoomsClient", async () => { let roomsClient: RoomsClient; - afterEach(function () { - sinon.restore(); - }); - - it("makes successful create Rooms request", async function () { + it("makes successful create Rooms request", async () => { const mockHttpClient = generateHttpClient(201, mockCreateRoomsResult); roomsClient = createRoomsClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions = {}; const createRoomsResult = await roomsClient.createRoom(sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(createRoomsResult); assert.equal(createRoomsResult.id, mockCreateRoomsResult.id); assert.deepEqual(createRoomsResult.validFrom, mockCreateRoomsResult.validFrom); @@ -42,17 +37,17 @@ describe("[Mocked] RoomsClient", async function () { mockCreateRoomsResult.pstnDialOutEnabled, ); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "POST"); assert.deepEqual(JSON.parse(request.body as string), { participants: {} }); assert.isNotEmpty(request.headers.get("repeatability-request-id")); }); - it("makes successful create Rooms request with Pstn Dial-Out Enabled", async function () { + it("makes successful create Rooms request with Pstn Dial-Out Enabled", async () => { const mockHttpClient = generateHttpClient(201, mockCreateRoomsWithPstnDialOutEnabledResult); roomsClient = createRoomsClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions = { pstnDialOutEnabled: true, @@ -60,7 +55,7 @@ describe("[Mocked] RoomsClient", async function () { const createRoomsResult = await roomsClient.createRoom(sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(createRoomsResult); assert.equal(createRoomsResult.id, mockCreateRoomsWithPstnDialOutEnabledResult.id); assert.deepEqual( @@ -76,15 +71,15 @@ describe("[Mocked] RoomsClient", async function () { mockCreateRoomsWithPstnDialOutEnabledResult.pstnDialOutEnabled, ); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "POST"); assert.isNotEmpty(request.headers.get("repeatability-request-id")); }); - it("makes update Rooms request", async function () { + it("makes update Rooms request", async () => { const mockHttpClient = generateHttpClient(200, mockUpdateRoomsResult); roomsClient = createRoomsClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions = { validFrom: new Date("2022-08-16T18:06:06Z"), validUntil: new Date("2022-08-17T18:06:06Z"), @@ -92,44 +87,44 @@ describe("[Mocked] RoomsClient", async function () { const updateRoomResult = await roomsClient.updateRoom("id", sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(updateRoomResult); assert.equal(updateRoomResult.id, mockUpdateRoomsResult.id); assert.deepEqual(updateRoomResult.validFrom, mockUpdateRoomsResult.validFrom); assert.deepEqual(updateRoomResult.validUntil, mockUpdateRoomsResult.validUntil); assert.deepEqual(updateRoomResult.pstnDialOutEnabled, mockUpdateRoomsResult.pstnDialOutEnabled); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "PATCH"); assert.deepEqual(request.body as string, JSON.stringify(sendOptions)); }); - it("makes update Rooms request with PSTN Dial-Out", async function () { + it("makes update Rooms request with PSTN Dial-Out", async () => { const mockHttpClient = generateHttpClient(200, mockUpdateRoomsWithPstnEnabledResult); roomsClient = createRoomsClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions = { pstnDialOutEnabled: true, }; const updateRoomResult = await roomsClient.updateRoom("id", sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(updateRoomResult); assert.equal(updateRoomResult.id, mockUpdateRoomsResult.id); assert.deepEqual(updateRoomResult.validFrom, mockUpdateRoomsResult.validFrom); assert.deepEqual(updateRoomResult.validUntil, mockUpdateRoomsResult.validUntil); assert.deepEqual(updateRoomResult.pstnDialOutEnabled, sendOptions.pstnDialOutEnabled); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "PATCH"); assert.deepEqual(request.body as string, JSON.stringify(sendOptions)); }); - it("makes add Participant request", async function () { + it("makes add Participant request", async () => { const mockHttpClient = generateHttpClient(200, mockUpdateRoomsResult); roomsClient = createRoomsClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions = { validFrom: new Date("2022-08-16T18:06:06Z"), validUntil: new Date("2022-08-17T18:06:06Z"), @@ -137,18 +132,18 @@ describe("[Mocked] RoomsClient", async function () { const updateRoomResult = await roomsClient.updateRoom("id", sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(updateRoomResult); assert.equal(updateRoomResult.id, mockUpdateRoomsResult.id); assert.deepEqual(updateRoomResult.validFrom, mockUpdateRoomsResult.validFrom); assert.deepEqual(updateRoomResult.validUntil, mockUpdateRoomsResult.validUntil); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "PATCH"); assert.deepEqual(request.body as string, JSON.stringify(sendOptions)); }); - it("successfully list rooms request with nextLink", async function () { + it("successfully list rooms request with nextLink", async () => { const mockHttpClient = generateHttpClient(200, mockListRoomsResultWithNextLink); roomsClient = createRoomsClient(mockHttpClient); @@ -164,7 +159,7 @@ describe("[Mocked] RoomsClient", async function () { } }); - it("successfully list rooms request without nextLink", async function () { + it("successfully list rooms request without nextLink", async () => { const mockHttpClient = generateHttpClient(200, mockListRoomsResultWithoutNextLink); roomsClient = createRoomsClient(mockHttpClient); diff --git a/sdk/communication/communication-rooms/test/internal/utils/mockedClient.ts b/sdk/communication/communication-rooms/test/internal/utils/mockedClient.ts index 32d88625735c..123f17b91cac 100644 --- a/sdk/communication/communication-rooms/test/internal/utils/mockedClient.ts +++ b/sdk/communication/communication-rooms/test/internal/utils/mockedClient.ts @@ -3,8 +3,8 @@ import type { HttpClient, PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline"; import { createHttpHeaders } from "@azure/core-rest-pipeline"; -import type * as RestModel from "../../../src/generated/src/models"; -import { RoomsClient } from "../../../src"; +import type * as RestModel from "../../../src/generated/src/models/index.js"; +import { RoomsClient } from "../../../src/index.js"; export const mockCreateRoomsResult: RestModel.RoomsCreateResponse = { id: "id", diff --git a/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts b/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts index cbd41fc5c098..cdf60b29052d 100644 --- a/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts +++ b/sdk/communication/communication-rooms/test/public/roomsClient.spec.ts @@ -3,16 +3,14 @@ import type { Recorder } from "@azure-tools/test-recorder"; import { isPlaybackMode } from "@azure-tools/test-recorder"; -import { createRecordedRoomsClient, createTestUser } from "./utils/recordedClient"; -import { assert, expect } from "chai"; -import type { Context } from "mocha"; -import sinon from "sinon"; -import type { RoomsClient } from "../../src/roomsClient"; +import { createRecordedRoomsClient, createTestUser } from "./utils/recordedClient.js"; +import type { RoomsClient } from "../../src/roomsClient.js"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; -import type { CreateRoomOptions, UpdateRoomOptions } from "../../src/models/options"; -import type { CommunicationRoom, RoomParticipantPatch } from "../../src/models/models"; +import type { CreateRoomOptions, UpdateRoomOptions } from "../../src/models/options.js"; +import type { CommunicationRoom, RoomParticipantPatch } from "../../src/models/models.js"; +import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; -describe("RoomsClient", function () { +describe("RoomsClient", () => { let recorder: Recorder; let client: RoomsClient; const validFrom = new Date(); @@ -20,27 +18,24 @@ describe("RoomsClient", function () { const over180DaysValidUntil = new Date(validUntil.getTime() + 288000 * 60 * 1000); // 200 days from validUntil const expiredValidUntil = new Date(validFrom.getTime() - 5 * 60 * 1000); // 5 days from validFrom - describe("Room Operations", function () { + describe("Room Operations", () => { let testUser1: CommunicationUserIdentifier; let testUser2: CommunicationUserIdentifier; let roomId = ""; - beforeEach(async function (this: Context) { - ({ client, recorder } = await createRecordedRoomsClient(this)); + beforeEach(async (ctx) => { + ({ client, recorder } = await createRecordedRoomsClient(ctx)); }); - afterEach(async function () { + afterEach(async () => { if (roomId !== "") { await client.deleteRoom(roomId); roomId = ""; } await recorder.stop(); - if (isPlaybackMode()) { - sinon.restore(); - } }); - it("successfully creates a room with no attributes", async function () { + it("successfully creates a room with no attributes", async () => { const options = {}; const createRoomResult = await client.createRoom(options); @@ -48,7 +43,7 @@ describe("RoomsClient", function () { roomId = createRoomResult?.id; }); - it("successfully creates a room with only participants attributes", async function () { + it("successfully creates a room with only participants attributes", async () => { testUser1 = (await createTestUser(recorder)).user; testUser2 = (await createTestUser(recorder)).user; @@ -68,7 +63,7 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); - it("successfully creates a room with an invalid MRI attribute", async function () { + it("successfully creates a room with an invalid MRI attribute", async () => { testUser1 = (await createTestUser(recorder)).user; testUser2 = (await createTestUser(recorder)).user; testUser1.communicationUserId = "invalid MRI Values"; @@ -93,7 +88,7 @@ describe("RoomsClient", function () { } }); - it("successfully creates a room with only valid time range attributes", async function () { + it("successfully creates a room with only valid time range attributes", async () => { testUser1 = (await createTestUser(recorder)).user; const options: CreateRoomOptions = { @@ -109,7 +104,7 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); - it("successfully creates a room with an expired validUntil", async function () { + it("successfully creates a room with an expired validUntil", async () => { testUser1 = (await createTestUser(recorder)).user; const options: CreateRoomOptions = { @@ -126,7 +121,7 @@ describe("RoomsClient", function () { } }); - it("successfully creates a room with validUntil greater than 180 days from current date", async function () { + it("successfully creates a room with validUntil greater than 180 days from current date", async () => { testUser1 = (await createTestUser(recorder)).user; const options: CreateRoomOptions = { @@ -143,7 +138,7 @@ describe("RoomsClient", function () { } }); - it("successfully creates a room with only PSTN Dial-Out attribute", async function () { + it("successfully creates a room with only PSTN Dial-Out attribute", async () => { testUser1 = (await createTestUser(recorder)).user; testUser2 = (await createTestUser(recorder)).user; @@ -165,7 +160,7 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); - it("successfully creates a room with PSTN Dial-Out and valid time range attributes", async function () { + it("successfully creates a room with PSTN Dial-Out and valid time range attributes", async () => { testUser1 = (await createTestUser(recorder)).user; const options: CreateRoomOptions = { @@ -188,7 +183,7 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 0, 0, 0, 0); }); - it("successfully creates a room with PSTN Dial-Out and Valid Particpants attributes", async function () { + it("successfully creates a room with PSTN Dial-Out and Valid Particpants attributes", async () => { testUser1 = (await createTestUser(recorder)).user; testUser2 = (await createTestUser(recorder)).user; @@ -216,7 +211,7 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); - it("successfully creates a room with all optional attributes", async function () { + it("successfully creates a room with all optional attributes", async () => { testUser1 = (await createTestUser(recorder)).user; const options: CreateRoomOptions = { @@ -238,14 +233,14 @@ describe("RoomsClient", function () { verifyRoomsParticipantsAttributes(addParticipantsResult, 1, 1, 0, 0); }); - it("successfully gets a valid room", async function () { + it("successfully gets a valid room", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; await client.getRoom(roomId); }); - it("successfully gets an invalid room", async function () { + it("successfully gets an invalid room", async () => { try { await client.getRoom("non-existingroomId"); } catch (e: any) { @@ -253,7 +248,7 @@ describe("RoomsClient", function () { } }); - it("successfully update room with a valid time range", async function () { + it("successfully update room with a valid time range", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; testUser1 = (await createTestUser(recorder)).user; @@ -276,7 +271,7 @@ describe("RoomsClient", function () { await client.updateRoom(roomId, options); }); - it("successfully updates a room with validUntil greater than 180 days from current date", async function () { + it("successfully updates a room with validUntil greater than 180 days from current date", async () => { testUser1 = (await createTestUser(recorder)).user; const createRoom = await client.createRoom({ validFrom: new Date(recorder.variable("validFrom", validFrom.toString())), @@ -306,7 +301,7 @@ describe("RoomsClient", function () { } }); - it("successfully updates a room with an expired validUntil", async function () { + it("successfully updates a room with an expired validUntil", async () => { testUser1 = (await createTestUser(recorder)).user; const createRoom = await client.createRoom({ validFrom: new Date(recorder.variable("validFrom", validFrom.toString())), @@ -336,7 +331,7 @@ describe("RoomsClient", function () { } }); - it("successfully updates a room with an empty option", async function () { + it("successfully updates a room with an empty option", async () => { testUser1 = (await createTestUser(recorder)).user; const createRoom = await client.createRoom({ validFrom: new Date(recorder.variable("validFrom", validFrom.toString())), @@ -361,7 +356,7 @@ describe("RoomsClient", function () { } }); - it("successfully update room with an invalid room Id", async function () { + it("successfully update room with an invalid room Id", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; testUser1 = (await createTestUser(recorder)).user; @@ -388,7 +383,7 @@ describe("RoomsClient", function () { } }); - it("successfully update room with PSTN Dial-Out", async function () { + it("successfully update room with PSTN Dial-Out", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; testUser1 = (await createTestUser(recorder)).user; @@ -405,7 +400,7 @@ describe("RoomsClient", function () { verifyRoomsAttributes(updateRoomResult, updateOptions); }); - it("successfully update room with PSTN Dial-Out and valid time range", async function () { + it("successfully update room with PSTN Dial-Out and valid time range", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; testUser1 = (await createTestUser(recorder)).user; @@ -434,7 +429,7 @@ describe("RoomsClient", function () { verifyRoomsAttributes(updateRoomResult, updateOptions); }); - it("successfully list rooms", async function () { + it("successfully list rooms", async () => { const roomsPages = client.listRooms().byPage(); let counter: number = 1; // loop over each page @@ -457,7 +452,7 @@ describe("RoomsClient", function () { } }); - it("successfully deletes a room", async function () { + it("successfully deletes a room", async () => { const createRoom = await client.createRoom({}); roomId = createRoom.id; @@ -469,18 +464,18 @@ describe("RoomsClient", function () { }); }); -describe("Participants Operations", function () { +describe("Participants Operations", () => { let recorder: Recorder; let client: RoomsClient; let testUser1: CommunicationUserIdentifier; let roomId = ""; const delayInMs = 1000; - beforeEach(async function (this: Context) { - ({ client, recorder } = await createRecordedRoomsClient(this)); + beforeEach(async (ctx) => { + ({ client, recorder } = await createRecordedRoomsClient(ctx)); }); - afterEach(async function () { + afterEach(async () => { if (roomId !== "") { await client.deleteRoom(roomId); roomId = ""; @@ -488,11 +483,11 @@ describe("Participants Operations", function () { await recorder.stop(); if (isPlaybackMode()) { - sinon.restore(); + vi.restoreAllMocks(); } }); - it("successfully adds participants to the room", async function () { + it("successfully adds participants to the room", async () => { testUser1 = (await createTestUser(recorder)).user; const participants: RoomParticipantPatch[] = [ { @@ -517,7 +512,7 @@ describe("Participants Operations", function () { roomId = curRoomId; }); - it("successfully adds participants to the room with null role", async function () { + it("successfully adds participants to the room with null role", async () => { testUser1 = (await createTestUser(recorder)).user; const participants = [ { @@ -542,7 +537,7 @@ describe("Participants Operations", function () { roomId = curRoomId; }); - it("successfully updates a participant with role not specified", async function () { + it("successfully updates a participant with role not specified", async () => { testUser1 = (await createTestUser(recorder)).user; const participants = [ @@ -568,7 +563,7 @@ describe("Participants Operations", function () { roomId = curRoomId; }); - it("successfully removes participant not in the room", async function () { + it("successfully removes participant not in the room", async () => { testUser1 = (await createTestUser(recorder)).user; // Create a room @@ -589,7 +584,7 @@ describe("Participants Operations", function () { roomId = curRoomId; }); - it("successfully removes participants in the room", async function () { + it("successfully removes participants in the room", async () => { testUser1 = (await createTestUser(recorder)).user; // Create a room diff --git a/sdk/communication/communication-rooms/test/public/utils/connectionUtils.ts b/sdk/communication/communication-rooms/test/public/utils/connectionUtils.ts index 50c6b8245229..339bb57667cf 100644 --- a/sdk/communication/communication-rooms/test/public/utils/connectionUtils.ts +++ b/sdk/communication/communication-rooms/test/public/utils/connectionUtils.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { isNode } from "@azure/core-util"; +import { isNodeLike } from "@azure/core-util"; export const baseUri = "https://contoso.api.fake"; @@ -11,6 +11,6 @@ export const generateToken = (): string => { const validForMinutes = 60; const expiresOn = (Date.now() + validForMinutes * 60 * 1000) / 1000; const tokenString = JSON.stringify({ exp: expiresOn }); - const base64Token = isNode ? Buffer.from(tokenString).toString("base64") : btoa(tokenString); + const base64Token = isNodeLike ? Buffer.from(tokenString).toString("base64") : btoa(tokenString); return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${base64Token}.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs`; }; diff --git a/sdk/communication/communication-rooms/test/public/utils/recordedClient.ts b/sdk/communication/communication-rooms/test/public/utils/recordedClient.ts index 2d8778466867..d1caa2e15422 100644 --- a/sdk/communication/communication-rooms/test/public/utils/recordedClient.ts +++ b/sdk/communication/communication-rooms/test/public/utils/recordedClient.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { RecorderStartOptions, SanitizerOptions } from "@azure-tools/test-recorder"; +import type { RecorderStartOptions, SanitizerOptions, TestInfo } from "@azure-tools/test-recorder"; import { Recorder, assertEnvironmentVariable, @@ -12,11 +12,10 @@ import type { TokenCredential } from "@azure/core-auth"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; import { parseConnectionString } from "@azure/communication-common"; import { createTestCredential } from "@azure-tools/test-credential"; -import type { Context, Test } from "mocha"; -import { RoomsClient } from "../../../src"; +import { RoomsClient } from "../../../src/index.js"; import type { CommunicationUserToken } from "@azure/communication-identity"; import { CommunicationIdentityClient } from "@azure/communication-identity"; -import { generateToken } from "./connectionUtils"; +import { generateToken } from "./connectionUtils.js"; export interface RecordedClient { client: T; @@ -66,7 +65,7 @@ const recorderOptions: RecorderStartOptions = { ], }; -export async function createRecorder(context: Test | undefined): Promise { +export async function createRecorder(context: TestInfo | undefined): Promise { const recorder = new Recorder(context); await recorder.start(recorderOptions); await recorder.setMatcher("HeaderlessMatcher"); @@ -74,9 +73,9 @@ export async function createRecorder(context: Test | undefined): Promise> { - const recorder = await createRecorder(context.currentTest); + const recorder = await createRecorder(context); const client = new RoomsClient( env.COMMUNICATION_CONNECTION_STRING_ROOMS ?? "", @@ -89,9 +88,9 @@ export async function createRecordedRoomsClient( } export async function createRecordedRoomsClientWithToken( - context: Context, + context: TestInfo, ): Promise> { - const recorder = await createRecorder(context.currentTest); + const recorder = await createRecorder(context); let credential: TokenCredential; const endpoint = parseConnectionString(env.COMMUNICATION_CONNECTION_STRING_ROOMS ?? "").endpoint; diff --git a/sdk/communication/communication-rooms/tsconfig.browser.config.json b/sdk/communication/communication-rooms/tsconfig.browser.config.json new file mode 100644 index 000000000000..f772e6eb3b76 --- /dev/null +++ b/sdk/communication/communication-rooms/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/communication/communication-rooms/tsconfig.json b/sdk/communication/communication-rooms/tsconfig.json index 53166d96d55e..e287c0d8c4f2 100644 --- a/sdk/communication/communication-rooms/tsconfig.json +++ b/sdk/communication/communication-rooms/tsconfig.json @@ -1,11 +1,12 @@ { "extends": "../../../tsconfig", "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", "paths": { "@azure/communication-rooms": ["./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"] } diff --git a/sdk/communication/communication-rooms/vitest.browser.config.ts b/sdk/communication/communication-rooms/vitest.browser.config.ts new file mode 100644 index 000000000000..50ec2d5489b0 --- /dev/null +++ b/sdk/communication/communication-rooms/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/communication/communication-rooms/vitest.config.ts b/sdk/communication/communication-rooms/vitest.config.ts new file mode 100644 index 000000000000..d01fdec8ac69 --- /dev/null +++ b/sdk/communication/communication-rooms/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, + }, + }), +);