diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e2ac4a887b9b..83d3be1d5dda 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -15416,7 +15416,7 @@ packages: dev: false file:projects/arm-hybridcompute.tgz: - resolution: {integrity: sha512-+DX7eIMt7WAbn6AD+QZpjVyoMuXdNpGH452FuoUH2UvFhOBtlZD3B5y8bwW/oE8d3E/u2eZ3B4N2cAFV32bgbw==, tarball: file:projects/arm-hybridcompute.tgz} + resolution: {integrity: sha512-IxFMCCeH0D2P6u+4Vwi9ROrWBKeO0DJEfs2jxyfJnrGNMrRKAWfplx0QVZY6ETK5Thjlm3myTMffxO2BT5PBiA==, tarball: file:projects/arm-hybridcompute.tgz} name: '@rush-temp/arm-hybridcompute' version: 0.0.0 dependencies: @@ -18977,7 +18977,7 @@ packages: dev: false file:projects/communication-chat.tgz: - resolution: {integrity: sha512-J1sRuvQkiaeWZtnBmgo0F7yz38gSppMo/+b42TnKyPoRq+Es1UaUXkdo8CMpQfOW79FtH0Oo95HLKs43eq/rgw==, tarball: file:projects/communication-chat.tgz} + resolution: {integrity: sha512-b8v2dH6bvbYnjZtQtKl6ReggBc4gkDHx66jdrHCgqW4yEpxfFsQAqHDQgZftlGhJCUe5eKKRJ6vqBEwhTOGWDA==, tarball: file:projects/communication-chat.tgz} name: '@rush-temp/communication-chat' version: 0.0.0 dependencies: @@ -18989,6 +18989,8 @@ packages: '@types/node': 18.19.64 '@types/sinon': 17.0.3 '@types/uuid': 8.3.4 + '@vitest/browser': 2.1.5(@types/node@18.19.64)(playwright@1.48.2)(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 @@ -19007,20 +19009,34 @@ packages: karma-sourcemap-loader: 0.3.8 mocha: 10.8.2 nyc: 17.1.0 + playwright: 1.48.2 sinon: 19.0.2 ts-node: 10.9.2(@types/node@18.19.64)(typescript@5.6.3) tslib: 2.8.1 typescript: 5.6.3 util: 0.12.5 uuid: 8.3.2 + 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-common.tgz: @@ -19240,7 +19256,7 @@ packages: dev: false file:projects/communication-job-router.tgz: - resolution: {integrity: sha512-xPt7oEFIEnDcZHXkEsgPlaOBwbjSF6dQq4uDtXsp/yeslQgiTdGNnO5bUMfuqpTTiiwSsXCyCKEy2FmmrcRHLw==, tarball: file:projects/communication-job-router.tgz} + resolution: {integrity: sha512-2asWr03USbfs287ufZkj8sgX94e8AIkX8BU9mVvBxqPp+5NwM8F2I2OeKa/ZRb9z7dcawliux8IwyB2kNGIEAg==, tarball: file:projects/communication-job-router.tgz} name: '@rush-temp/communication-job-router' version: 0.0.0 dependencies: diff --git a/sdk/communication/communication-chat/.nycrc b/sdk/communication/communication-chat/.nycrc deleted file mode 100644 index 67064d0c1c56..000000000000 --- a/sdk/communication/communication-chat/.nycrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "include": [ - "dist-esm/src/**/*.js" - ], - "exclude": [ - "**/*.d.ts" - ], - "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-chat/api-extractor.json b/sdk/communication/communication-chat/api-extractor.json index 2a104fbc673f..0bf786c9a4ea 100644 --- a/sdk/communication/communication-chat/api-extractor.json +++ b/sdk/communication/communication-chat/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-chat.d.ts" + "publicTrimmedFilePath": "dist/communication-chat.d.ts" }, "messages": { "tsdocMessageReporting": { diff --git a/sdk/communication/communication-chat/karma.conf.js b/sdk/communication/communication-chat/karma.conf.js deleted file mode 100644 index 5d2e27fbbd74..000000000000 --- a/sdk/communication/communication-chat/karma.conf.js +++ /dev/null @@ -1,125 +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_LIVETEST_DYNAMIC_CONNECTION_STRING", - "BASE_URL", - "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-chat/package.json b/sdk/communication/communication-chat/package.json index 18ef9fb36904..48f0f30418a1 100644 --- a/sdk/communication/communication-chat/package.json +++ b/sdk/communication/communication-chat/package.json @@ -3,24 +3,24 @@ "version": "1.5.5", "description": "Azure client library for Azure Communication Chat services", "sdk-type": "client", - "main": "dist/index.js", - "module": "dist-esm/src/index.js", - "types": "types/communication-chat.d.ts", + "main": "./dist/commonjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/commonjs/index.d.ts", "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": "echo Obsolete.", - "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 ./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'", + "integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", + "integration-test:node": "dev-tool run test:vitest", "lint": "eslint package.json api-extractor.json README.md src test", "lint:fix": "eslint package.json api-extractor.json README.md src test --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", @@ -28,20 +28,16 @@ "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 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" }, "files": [ "dist/", - "dist-esm/src/", - "types/communication-chat.d.ts", "README.md", "LICENSE" ], - "browser": { - "./dist-esm/src/signaling/signalingClient.js": "./dist-esm/src/signaling/signalingClient.browser.js" - }, + "browser": "./dist/browser/index.js", "repository": "github:Azure/azure-sdk-for-js", "keywords": [ "azure", @@ -62,52 +58,34 @@ "sideEffects": false, "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", "dependencies": { - "@azure/abort-controller": "^2.0.0", + "@azure/abort-controller": "^2.1.2", "@azure/communication-common": "^2.3.1", "@azure/communication-signaling": "1.0.0-beta.29", - "@azure/core-auth": "^1.3.0", + "@azure/core-auth": "^1.9.0", "@azure/core-client": "^1.9.2", "@azure/core-paging": "^1.1.1", - "@azure/core-rest-pipeline": "^1.16.3", + "@azure/core-rest-pipeline": "^1.18.0", "@azure/core-tracing": "^1.0.0", "@azure/logger": "^1.0.0", "events": "^3.0.0", - "tslib": "^2.2.0", - "uuid": "^8.3.0" + "tslib": "^2.8.1" }, "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.5.1", + "@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/core-util": "^1.0.0", + "@azure/core-util": "^1.11.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@types/chai": "^4.1.6", - "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", - "@types/sinon": "^17.0.3", - "@types/uuid": "^8.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", - "inherits": "^2.0.3", - "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-json-preprocessor": "^0.3.3", - "karma-json-to-file-reporter": "^1.0.1", - "karma-junit-reporter": "^2.0.1", - "karma-mocha": "^2.0.1", - "karma-mocha-reporter": "^2.2.5", - "karma-sourcemap-loader": "^0.3.8", - "mocha": "^10.0.0", - "nyc": "^17.0.0", - "sinon": "^19.0.2", - "ts-node": "^10.0.0", + "playwright": "^1.48.2", "typescript": "~5.6.2", - "util": "^0.12.1" + "vitest": "^2.1.5" }, "//metadata": { "constantPaths": [ @@ -134,5 +112,42 @@ "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 + }, + "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-chat/src/chatClient.ts b/sdk/communication/communication-chat/src/chatClient.ts index 50d6790f20b9..43129217fb46 100644 --- a/sdk/communication/communication-chat/src/chatClient.ts +++ b/sdk/communication/communication-chat/src/chatClient.ts @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/// import type { ChatClientOptions, CreateChatThreadOptions, DeleteChatThreadOptions, ListChatThreadsOptions, -} from "./models/options"; +} from "./models/options.js"; import type { ChatEventId, ChatMessageDeletedEvent, @@ -20,28 +19,27 @@ import type { ParticipantsRemovedEvent, ReadReceiptReceivedEvent, TypingIndicatorReceivedEvent, -} from "./models/events"; -import type { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from "./models/models"; +} from "./models/events.js"; +import type { ChatThreadItem, CreateChatThreadResult, ListPageSettings } from "./models/models.js"; import type { SignalingClient, SignalingClientOptions } from "@azure/communication-signaling"; import { ConnectionState } from "@azure/communication-signaling"; import { mapToChatParticipantRestModel, mapToCreateChatThreadOptionsRestModel, mapToCreateChatThreadResultSdkModel, -} from "./models/mappers"; - -import { ChatApiClient } from "./generated/src"; -import { ChatThreadClient } from "./chatThreadClient"; +} from "./models/mappers.js"; +import { ChatApiClient } from "./generated/src/index.js"; +import { ChatThreadClient } from "./chatThreadClient.js"; import type { CommunicationTokenCredential } from "@azure/communication-common"; -import type { CreateChatThreadRequest } from "./models/requests"; +import type { CreateChatThreadRequest } from "./models/requests.js"; import { EventEmitter } from "events"; import type { InternalPipelineOptions } from "@azure/core-rest-pipeline"; import type { PagedAsyncIterableIterator } from "@azure/core-paging"; -import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy"; -import { generateUuid } from "./models/uuid"; -import { getSignalingClient } from "./signaling/signalingClient"; -import { logger } from "./models/logger"; -import { tracingClient } from "./generated/src/tracing"; +import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy.js"; +import { generateUuid } from "./models/uuid.js"; +import { getSignalingClient } from "./signaling/signalingClient.js"; +import { logger } from "./models/logger.js"; +import { tracingClient } from "./generated/src/tracing.js"; declare interface InternalChatClientOptions extends ChatClientOptions { signalingClientOptions?: SignalingClientOptions; diff --git a/sdk/communication/communication-chat/src/chatThreadClient.ts b/sdk/communication/communication-chat/src/chatThreadClient.ts index 47d151e327a5..8737cbead5f6 100644 --- a/sdk/communication/communication-chat/src/chatThreadClient.ts +++ b/sdk/communication/communication-chat/src/chatThreadClient.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { logger } from "./models/logger"; +import { logger } from "./models/logger.js"; import type { CommunicationIdentifier, CommunicationTokenCredential, @@ -12,7 +12,7 @@ import type { AddParticipantsRequest, SendMessageRequest, SendReadReceiptRequest, -} from "./models/requests"; +} from "./models/requests.js"; import type { AddChatParticipantsResult, @@ -22,14 +22,14 @@ import type { ChatThreadProperties, ListPageSettings, SendChatMessageResult, -} from "./models/models"; +} from "./models/models.js"; import { mapToAddChatParticipantsRequestRestModel, mapToChatMessageSdkModel, mapToChatParticipantSdkModel, mapToChatThreadPropertiesSdkModel, mapToReadReceiptSdkModel, -} from "./models/mappers"; +} from "./models/mappers.js"; import type { AddParticipantsOptions, ChatThreadClientOptions, @@ -45,11 +45,11 @@ import type { SendTypingNotificationOptions, UpdateMessageOptions, UpdateTopicOptions, -} from "./models/options"; -import { ChatApiClient } from "./generated/src"; +} from "./models/options.js"; +import { ChatApiClient } from "./generated/src/index.js"; import type { InternalPipelineOptions } from "@azure/core-rest-pipeline"; -import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy"; -import { tracingClient } from "./generated/src/tracing"; +import { createCommunicationTokenCredentialPolicy } from "./credential/communicationTokenCredentialPolicy.js"; +import { tracingClient } from "./generated/src/tracing.js"; const minimumTypingIntervalInMilliSeconds: number = 8000; diff --git a/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts b/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts index ce8fc717920a..410a5eb545ae 100644 --- a/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts +++ b/sdk/communication/communication-chat/src/generated/src/chatApiClient.ts @@ -12,9 +12,9 @@ import { PipelineResponse, SendRequest, } from "@azure/core-rest-pipeline"; -import { ChatThreadImpl, ChatImpl } from "./operations"; -import { ChatThread, Chat } from "./operationsInterfaces"; -import { ChatApiClientOptionalParams } from "./models"; +import { ChatThreadImpl, ChatImpl } from "./operations/index.js"; +import { ChatThread, Chat } from "./operationsInterfaces/index.js"; +import { ChatApiClientOptionalParams } from "./models/index.js"; export class ChatApiClient extends coreClient.ServiceClient { endpoint: string; diff --git a/sdk/communication/communication-chat/src/generated/src/index.ts b/sdk/communication/communication-chat/src/generated/src/index.ts index 5fbcb82d87b8..401c33a0b740 100644 --- a/sdk/communication/communication-chat/src/generated/src/index.ts +++ b/sdk/communication/communication-chat/src/generated/src/index.ts @@ -6,6 +6,6 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -export * from "./models"; -export { ChatApiClient } from "./chatApiClient"; -export * from "./operationsInterfaces"; +export * from "./models/index.js"; +export { ChatApiClient } from "./chatApiClient.js"; +export * from "./operationsInterfaces/index.js"; diff --git a/sdk/communication/communication-chat/src/generated/src/models/parameters.ts b/sdk/communication/communication-chat/src/generated/src/models/parameters.ts index 0a776737a053..e20be5d3844f 100644 --- a/sdk/communication/communication-chat/src/generated/src/models/parameters.ts +++ b/sdk/communication/communication-chat/src/generated/src/models/parameters.ts @@ -20,7 +20,7 @@ import { UpdateChatThreadRequest as UpdateChatThreadRequestMapper, SendTypingNotificationRequest as SendTypingNotificationRequestMapper, CreateChatThreadRequest as CreateChatThreadRequestMapper, -} from "../models/mappers"; +} from "../models/mappers.js"; export const accept: OperationParameter = { parameterPath: "accept", diff --git a/sdk/communication/communication-chat/src/generated/src/operations/chat.ts b/sdk/communication/communication-chat/src/generated/src/operations/chat.ts index c27cc83c3336..b4275363eedc 100644 --- a/sdk/communication/communication-chat/src/generated/src/operations/chat.ts +++ b/sdk/communication/communication-chat/src/generated/src/operations/chat.ts @@ -6,12 +6,12 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { tracingClient } from "../tracing"; -import { Chat } from "../operationsInterfaces"; +import { tracingClient } from "../tracing.js"; +import { Chat } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; -import * as Mappers from "../models/mappers"; -import * as Parameters from "../models/parameters"; -import { ChatApiClient } from "../chatApiClient"; +import * as Mappers from "../models/mappers.js"; +import * as Parameters from "../models/parameters.js"; +import { ChatApiClient } from "../chatApiClient.js"; import { CreateChatThreadRequest, ChatCreateChatThreadOptionalParams, @@ -21,7 +21,7 @@ import { ChatDeleteChatThreadOptionalParams, ChatListChatThreadsNextOptionalParams, ChatListChatThreadsNextResponse, -} from "../models"; +} from "../models/index.js"; /** Class containing Chat operations. */ export class ChatImpl implements Chat { diff --git a/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts b/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts index 6b64f7a6df85..197ed97ff95b 100644 --- a/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts +++ b/sdk/communication/communication-chat/src/generated/src/operations/chatThread.ts @@ -6,12 +6,12 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { tracingClient } from "../tracing"; -import { ChatThread } from "../operationsInterfaces"; +import { tracingClient } from "../tracing.js"; +import { ChatThread } from "../operationsInterfaces/index.js"; import * as coreClient from "@azure/core-client"; -import * as Mappers from "../models/mappers"; -import * as Parameters from "../models/parameters"; -import { ChatApiClient } from "../chatApiClient"; +import * as Mappers from "../models/mappers.js"; +import * as Parameters from "../models/parameters.js"; +import { ChatApiClient } from "../chatApiClient.js"; import { ChatThreadListChatReadReceiptsOptionalParams, ChatThreadListChatReadReceiptsResponse, @@ -45,7 +45,7 @@ import { ChatThreadListChatMessagesNextResponse, ChatThreadListChatParticipantsNextOptionalParams, ChatThreadListChatParticipantsNextResponse, -} from "../models"; +} from "../models/index.js"; /** Class containing ChatThread operations. */ export class ChatThreadImpl implements ChatThread { diff --git a/sdk/communication/communication-chat/src/generated/src/operations/index.ts b/sdk/communication/communication-chat/src/generated/src/operations/index.ts index 504f4a5f4ea3..ee6ace6812b6 100644 --- a/sdk/communication/communication-chat/src/generated/src/operations/index.ts +++ b/sdk/communication/communication-chat/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 "./chatThread"; -export * from "./chat"; +export * from "./chatThread.js"; +export * from "./chat.js"; diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts index 91f81f122c1e..1c69466f51e0 100644 --- a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts +++ b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chat.ts @@ -15,7 +15,7 @@ import { ChatDeleteChatThreadOptionalParams, ChatListChatThreadsNextOptionalParams, ChatListChatThreadsNextResponse, -} from "../models"; +} from "../models/index.js"; /** Interface representing a Chat. */ export interface Chat { diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts index e7e9e69d109a..de952d00a650 100644 --- a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts +++ b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/chatThread.ts @@ -39,7 +39,7 @@ import { ChatThreadListChatMessagesNextResponse, ChatThreadListChatParticipantsNextOptionalParams, ChatThreadListChatParticipantsNextResponse, -} from "../models"; +} from "../models/index.js"; /** Interface representing a ChatThread. */ export interface ChatThread { diff --git a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts b/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts index 504f4a5f4ea3..ee6ace6812b6 100644 --- a/sdk/communication/communication-chat/src/generated/src/operationsInterfaces/index.ts +++ b/sdk/communication/communication-chat/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 "./chatThread"; -export * from "./chat"; +export * from "./chatThread.js"; +export * from "./chat.js"; diff --git a/sdk/communication/communication-chat/src/index.ts b/sdk/communication/communication-chat/src/index.ts index fb1d72ffe543..ff9c47365cd8 100644 --- a/sdk/communication/communication-chat/src/index.ts +++ b/sdk/communication/communication-chat/src/index.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -export * from "./models/options"; -export * from "./models/requests"; -export * from "./models/models"; -export * from "./models/events"; -export * from "./chatClient"; -export * from "./chatThreadClient"; +export * from "./models/options.js"; +export * from "./models/requests.js"; +export * from "./models/models.js"; +export * from "./models/events.js"; +export * from "./chatClient.js"; +export * from "./chatThreadClient.js"; diff --git a/sdk/communication/communication-chat/src/models/mappers.ts b/sdk/communication/communication-chat/src/models/mappers.ts index 754e22d2e1df..2b98a5c22327 100644 --- a/sdk/communication/communication-chat/src/models/mappers.ts +++ b/sdk/communication/communication-chat/src/models/mappers.ts @@ -6,9 +6,9 @@ import { deserializeCommunicationIdentifier, serializeCommunicationIdentifier, } from "@azure/communication-common"; -import type * as RestModel from "../generated/src/models"; -import type { AddParticipantsRequest } from "./requests"; -import type { CreateChatThreadOptions } from "./options"; +import type * as RestModel from "../generated/src/models/index.js"; +import type { AddParticipantsRequest } from "./requests.js"; +import type { CreateChatThreadOptions } from "./options.js"; import type { ChatMessage, ChatMessageContent, @@ -16,7 +16,7 @@ import type { ChatParticipant, ChatThreadProperties, CreateChatThreadResult, -} from "./models"; +} from "./models.js"; export const mapToCreateChatThreadOptionsRestModel = ( options: CreateChatThreadOptions, diff --git a/sdk/communication/communication-chat/src/models/models.ts b/sdk/communication/communication-chat/src/models/models.ts index db9505b68c76..bfb800b6721b 100644 --- a/sdk/communication/communication-chat/src/models/models.ts +++ b/sdk/communication/communication-chat/src/models/models.ts @@ -5,7 +5,7 @@ import type { CommunicationIdentifier, CommunicationIdentifierKind, } from "@azure/communication-common"; -import type { ChatError, ChatMessageType } from "../generated/src"; +import type { ChatError, ChatMessageType } from "../generated/src/index.js"; export { AddChatParticipantsResult, @@ -13,7 +13,7 @@ export { ChatThreadItem, ChatError, SendChatMessageResult, -} from "../generated/src/models"; +} from "../generated/src/models/index.js"; /** Chat thread. */ export interface ChatThreadProperties { diff --git a/sdk/communication/communication-chat/src/models/options.ts b/sdk/communication/communication-chat/src/models/options.ts index c1c7611362af..d30f72dc24c3 100644 --- a/sdk/communication/communication-chat/src/models/options.ts +++ b/sdk/communication/communication-chat/src/models/options.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import type { CommonClientOptions, OperationOptions } from "@azure/core-client"; -import type { ChatMessageType } from "../generated/src/models"; +import type { ChatMessageType } from "../generated/src/models/index.js"; import { ChatListChatThreadsOptionalParams as RestListChatThreadsOptions, ChatThreadListChatMessagesOptionalParams as RestListMessagesOptions, ChatThreadListChatParticipantsOptionalParams as RestListParticipantsOptions, ChatThreadListChatReadReceiptsOptionalParams as RestListReadReceiptsOptions, -} from "../generated/src/models"; -import type { ChatParticipant } from "./models"; +} from "../generated/src/models/index.js"; +import type { ChatParticipant } from "./models.js"; export { RestListMessagesOptions, diff --git a/sdk/communication/communication-chat/src/models/requests.ts b/sdk/communication/communication-chat/src/models/requests.ts index bc1d5f08638f..70b3cf12c7bb 100644 --- a/sdk/communication/communication-chat/src/models/requests.ts +++ b/sdk/communication/communication-chat/src/models/requests.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { ChatParticipant } from "./models"; +import type { ChatParticipant } from "./models.js"; -export { SendReadReceiptRequest } from "../generated/src/models"; +export { SendReadReceiptRequest } from "../generated/src/models/index.js"; /** Participants to be added to the thread. */ export interface AddParticipantsRequest { diff --git a/sdk/communication/communication-chat/src/models/uuid.ts b/sdk/communication/communication-chat/src/models/uuid.ts index ebdd946ae2c0..5da555263c58 100644 --- a/sdk/communication/communication-chat/src/models/uuid.ts +++ b/sdk/communication/communication-chat/src/models/uuid.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { v4 as uuidv4 } from "uuid"; +import { randomUUID } from "@azure/core-util"; /** * Generated Universally Unique Identifier @@ -10,5 +10,5 @@ import { v4 as uuidv4 } from "uuid"; * @internal */ export function generateUuid(): string { - return uuidv4(); + return randomUUID(); } diff --git a/sdk/communication/communication-chat/src/signaling/signalingClient.browser.ts b/sdk/communication/communication-chat/src/signaling/signalingClient-browser.mts similarity index 91% rename from sdk/communication/communication-chat/src/signaling/signalingClient.browser.ts rename to sdk/communication/communication-chat/src/signaling/signalingClient-browser.mts index c61d6859c722..e1e1a59c161c 100644 --- a/sdk/communication/communication-chat/src/signaling/signalingClient.browser.ts +++ b/sdk/communication/communication-chat/src/signaling/signalingClient-browser.mts @@ -5,7 +5,7 @@ import type { SignalingClient } from "@azure/communication-signaling"; import { CommunicationSignalingClient } from "@azure/communication-signaling"; import type { CommunicationTokenCredential } from "@azure/communication-common"; import type { AzureLogger } from "@azure/logger"; -import type { SignalingClientOptions } from "./signalingClient"; +import type { SignalingClientOptions } from "./signalingClientOptions.js"; export const getSignalingClient = ( credential: CommunicationTokenCredential, diff --git a/sdk/communication/communication-chat/src/signaling/signalingClient-react-native.mts b/sdk/communication/communication-chat/src/signaling/signalingClient-react-native.mts new file mode 100644 index 000000000000..e1e1a59c161c --- /dev/null +++ b/sdk/communication/communication-chat/src/signaling/signalingClient-react-native.mts @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { SignalingClient } from "@azure/communication-signaling"; +import { CommunicationSignalingClient } from "@azure/communication-signaling"; +import type { CommunicationTokenCredential } from "@azure/communication-common"; +import type { AzureLogger } from "@azure/logger"; +import type { SignalingClientOptions } from "./signalingClientOptions.js"; + +export const getSignalingClient = ( + credential: CommunicationTokenCredential, + logger: AzureLogger, + options?: SignalingClientOptions, +): SignalingClient | undefined => { + return new CommunicationSignalingClient(credential, logger, { + resourceEndpoint: options?.resourceEndpoint ?? undefined, + gatewayApiVersion: options?.gatewayApiVersion ?? undefined, + additionalPolicies: options?.additionalPolicies ?? undefined, + userAgentOptions: options?.userAgentOptions ?? undefined, + }); +}; diff --git a/sdk/communication/communication-chat/src/signaling/signalingClient.ts b/sdk/communication/communication-chat/src/signaling/signalingClient.ts index df7a25836733..ad1e2771f917 100644 --- a/sdk/communication/communication-chat/src/signaling/signalingClient.ts +++ b/sdk/communication/communication-chat/src/signaling/signalingClient.ts @@ -2,31 +2,15 @@ // Licensed under the MIT License. import type { SignalingClient } from "@azure/communication-signaling"; -import { CommunicationSignalingClient } from "@azure/communication-signaling"; import type { CommunicationTokenCredential } from "@azure/communication-common"; import type { AzureLogger } from "@azure/logger"; -import type { ChatClientOptions } from "@azure/communication-chat"; - -export interface SignalingClientOptions extends ChatClientOptions { - resourceEndpoint?: string; - gatewayApiVersion?: string; -} +import type { SignalingClientOptions } from "./signalingClientOptions.js"; export const getSignalingClient = ( - credential: CommunicationTokenCredential, - logger: AzureLogger, - options?: SignalingClientOptions, + _credential: CommunicationTokenCredential, + _logger: AzureLogger, + _options?: SignalingClientOptions, ): SignalingClient | undefined => { - if (typeof navigator !== "undefined" && navigator.product === "ReactNative") { - // In React Native - return new CommunicationSignalingClient(credential, logger, { - resourceEndpoint: options?.resourceEndpoint ?? undefined, - gatewayApiVersion: options?.gatewayApiVersion ?? undefined, - additionalPolicies: options?.additionalPolicies ?? undefined, - userAgentOptions: options?.userAgentOptions ?? undefined, - }); - } - // In node js return undefined; }; diff --git a/sdk/communication/communication-chat/src/signaling/signalingClientOptions.ts b/sdk/communication/communication-chat/src/signaling/signalingClientOptions.ts new file mode 100644 index 000000000000..0e79943e0890 --- /dev/null +++ b/sdk/communication/communication-chat/src/signaling/signalingClientOptions.ts @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { ChatClientOptions } from "../models/options.js"; + +export interface SignalingClientOptions extends ChatClientOptions { + resourceEndpoint?: string; + gatewayApiVersion?: string; +} diff --git a/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts b/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts index 6b50c5faf3f7..69758244785e 100644 --- a/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts +++ b/sdk/communication/communication-chat/test/internal/chatClient.mocked.spec.ts @@ -1,13 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import sinon from "sinon"; -import { assert, expect } from "chai"; -import type { ChatClientOptions, CreateChatThreadRequest } from "../../src"; -import { ChatClient } from "../../src"; -import type * as RestModel from "../../src/generated/src/models"; -import { apiVersion } from "../../src/generated/src/models/parameters"; -import { baseUri, generateToken } from "../public/utils/connectionUtils"; +import type { ChatClientOptions, CreateChatThreadRequest } from "../../src/index.js"; +import { ChatClient } from "../../src/index.js"; +import type * as RestModel from "../../src/generated/src/models/index.js"; +import { apiVersion } from "../../src/generated/src/models/parameters.js"; +import { baseUri, generateToken } from "../public/utils/connectionUtils.js"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; import { AzureCommunicationTokenCredential } from "@azure/communication-common"; import { @@ -16,26 +14,23 @@ import { mockCreateThreadResult, mockThread, mockThreadItem, -} from "./utils/mockClient"; -import { isNode } from "@azure/core-util"; +} from "./utils/mockClient.js"; +import { isNodeLike } from "@azure/core-util"; +import { describe, it, assert, expect, vi } from "vitest"; const API_VERSION = apiVersion.mapper.defaultValue; -describe("[Mocked] ChatClient", async function () { +describe("[Mocked] ChatClient", async () => { let chatClient: ChatClient; - let listener: () => { + const listener = (): void => { // Intentionally empty listener for testing purposes }; - afterEach(function () { - sinon.restore(); - }); - - it("can instantiate", async function () { + it("can instantiate", async () => { new ChatClient(baseUri, new AzureCommunicationTokenCredential(generateToken())); }); - it("can instantiate with custom api version policy", async function () { + it("can instantiate with custom api version policy", async () => { const customizedVersion = `2021-03-07`; const mockHttpClient = generateHttpClient(201, mockCreateThreadResult); const options = { apiVersion: customizedVersion, httpClient: mockHttpClient }; @@ -45,17 +40,17 @@ describe("[Mocked] ChatClient", async function () { options as ChatClientOptions, ); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); await chatClient.createChatThread({ topic: mockThread.topic }); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.url, `${baseUri}/chat/threads?api-version=${customizedVersion}`); }); - it("makes successful create thread request", async function () { + it("makes successful create thread request", async () => { const mockHttpClient = generateHttpClient(201, mockCreateThreadResult); chatClient = createChatClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendRequest: CreateChatThreadRequest = { topic: mockThread.topic!, @@ -65,7 +60,7 @@ describe("[Mocked] ChatClient", async function () { const createThreadResult = await chatClient.createChatThread(sendRequest, sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.isDefined(createThreadResult.chatThread); assert.equal(createThreadResult.chatThread?.id, mockThread.id); assert.equal(createThreadResult.chatThread?.createdBy?.kind, "communicationUser"); @@ -74,7 +69,7 @@ describe("[Mocked] ChatClient", async function () { mockCreateThreadResult.chatThread?.createdByCommunicationIdentifier.communicationUser?.id, ); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.url, `${baseUri}/chat/threads?api-version=${API_VERSION}`); assert.equal(request.method, "POST"); @@ -82,14 +77,14 @@ describe("[Mocked] ChatClient", async function () { assert.isNotEmpty(request.headers.get("repeatability-request-id")); }); - it("makes successful list threads request", async function () { + it("makes successful list threads request", async () => { const mockResponse: RestModel.ChatThreadsItemCollection = { value: [mockThreadItem, mockThreadItem], }; const mockHttpClient = generateHttpClient(200, mockResponse); chatClient = createChatClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); let count = 0; for await (const info of chatClient.listChatThreads()) { @@ -98,22 +93,22 @@ describe("[Mocked] ChatClient", async function () { assert.deepEqual(info, mockThreadItem); } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, mockResponse.value?.length); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.url, `${baseUri}/chat/threads?api-version=${API_VERSION}`); assert.equal(request.method, "GET"); }); - it("makes successful list threads request by page", async function () { + it("makes successful list threads request by page", async () => { const mockResponse: RestModel.ChatThreadsItemCollection = { value: [mockThreadItem, mockThreadItem, mockThreadItem, mockThreadItem, mockThreadItem], }; const mockHttpClient = generateHttpClient(200, mockResponse); chatClient = createChatClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const chatThreadsIterator = chatClient.listChatThreads({ maxPageSize: 2 }); let count = 0; @@ -127,23 +122,23 @@ describe("[Mocked] ChatClient", async function () { } } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, mockResponse.value?.length); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.url, `${baseUri}/chat/threads?maxPageSize=2&api-version=${API_VERSION}`); assert.equal(request.method, "GET"); }); - it("makes successful delete thread request", async function () { + it("makes successful delete thread request", async () => { const mockHttpClient = generateHttpClient(204); chatClient = createChatClient(mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); await chatClient.deleteChatThread(mockThread.id!); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${mockThread.id}?api-version=${API_VERSION}`, @@ -151,9 +146,9 @@ describe("[Mocked] ChatClient", async function () { assert.equal(request.method, "DELETE"); }); - it("should throw an error to start real time notifications in node", async function () { - if (!isNode) { - this.skip(); + it("should throw an error to start real time notifications in node", async function (ctx) { + if (!isNodeLike) { + ctx.skip(); } try { @@ -167,9 +162,9 @@ describe("[Mocked] ChatClient", async function () { } }); - it("should throw an error to stop real time notifications in node", async function () { - if (!isNode) { - this.skip(); + it("should throw an error to stop real time notifications in node", async function (ctx) { + if (!isNodeLike) { + ctx.skip(); } try { @@ -183,9 +178,9 @@ describe("[Mocked] ChatClient", async function () { } }); - it("should throw an error to unsubscribe an event in node", function () { - if (!isNode) { - this.skip(); + it("should throw an error to unsubscribe an event in node", function (ctx) { + if (!isNodeLike) { + ctx.skip(); } try { @@ -199,163 +194,163 @@ describe("[Mocked] ChatClient", async function () { } }); - it("should throw an error to subscribe chatMessageReceived event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatMessageReceived", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe chatMessageEdited event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatMessageEdited", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe chatMessageDeleted event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatMessageDeleted", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe typingIndicatorReceived event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("typingIndicatorReceived", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe readReceiptReceived event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("readReceiptReceived", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe chatThreadCreated event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatThreadCreated", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe chatThreadDeleted event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatThreadDeleted", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe chatThreadPropertiesUpdated event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("chatThreadPropertiesUpdated", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe participantsAdded event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("participantsAdded", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); - - it("should throw an error to subscribe participantsRemoved event in node", function () { - if (!isNode) { - this.skip(); - } - - try { - chatClient.on("participantsRemoved", listener); - throw new Error("Error is expected."); - } catch (error) { - expect(error).to.be.an.instanceof(Error); - expect((error as Error).message).to.equal( - "Realtime notifications are only supported in the browser.", - ); - } - }); + it( + "should throw an error to subscribe chatMessageReceived event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatMessageReceived", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe chatMessageEdited event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatMessageEdited", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe chatMessageDeleted event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatMessageDeleted", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe typingIndicatorReceived event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("typingIndicatorReceived", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe readReceiptReceived event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("readReceiptReceived", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe chatThreadCreated event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatThreadCreated", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe chatThreadDeleted event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatThreadDeleted", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe chatThreadPropertiesUpdated event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("chatThreadPropertiesUpdated", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe participantsAdded event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("participantsAdded", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); + + it( + "should throw an error to subscribe participantsRemoved event in node", + { skip: !isNodeLike }, + () => { + try { + chatClient.on("participantsRemoved", listener); + throw new Error("Error is expected."); + } catch (error) { + expect(error).to.be.an.instanceof(Error); + expect((error as Error).message).to.equal( + "Realtime notifications are only supported in the browser.", + ); + } + }, + ); }); diff --git a/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts b/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts index 072f476a560f..4248d152965c 100644 --- a/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts +++ b/sdk/communication/communication-chat/test/internal/chatThreadClient.mocked.spec.ts @@ -1,8 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. - -import sinon from "sinon"; -import { assert } from "chai"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; import { AzureCommunicationTokenCredential } from "@azure/communication-common"; import type { @@ -10,11 +7,11 @@ import type { SendMessageOptions, SendMessageRequest, UpdateMessageOptions, -} from "../../src"; -import { ChatThreadClient } from "../../src"; -import type * as RestModel from "../../src/generated/src/models"; -import { apiVersion } from "../../src/generated/src/models/parameters"; -import { baseUri, generateToken } from "../public/utils/connectionUtils"; +} from "../../src/index.js"; +import { ChatThreadClient } from "../../src/index.js"; +import type * as RestModel from "../../src/generated/src/models/index.js"; +import { apiVersion } from "../../src/generated/src/models/parameters.js"; +import { baseUri, generateToken } from "../public/utils/connectionUtils.js"; import { createChatThreadClient, generateHttpClient, @@ -25,32 +22,33 @@ import { mockParticipant, mockSdkModelParticipant, mockThread, -} from "./utils/mockClient"; +} from "./utils/mockClient.js"; +import { describe, it, assert, expect, vi, afterEach } from "vitest"; const API_VERSION = apiVersion.mapper.defaultValue; -describe("[Mocked] ChatThreadClient", async function () { +describe("[Mocked] ChatThreadClient", async () => { const threadId: string = "threadId"; let chatThreadClient: ChatThreadClient; - afterEach(function () { - sinon.restore(); + afterEach(() => { + vi.restoreAllMocks(); }); - it("can instantiate", async function () { + it("can instantiate", async () => { new ChatThreadClient(threadId, baseUri, new AzureCommunicationTokenCredential(generateToken())); }); - it("makes successful get properties request", async function () { + it("makes successful get properties request", async () => { const mockHttpClient = generateHttpClient(200, mockThread); chatThreadClient = createChatThreadClient(mockThread.id, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const { createdBy: responseUser, ...response } = await chatThreadClient.getProperties(); const { createdByCommunicationIdentifier: expectedIdentifier, ...expected } = mockThread; - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.deepEqual(response, expected); assert.equal(responseUser?.kind, "communicationUser"); @@ -59,7 +57,7 @@ describe("[Mocked] ChatThreadClient", async function () { expectedIdentifier.communicationUser?.id, ); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -68,29 +66,29 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful update thread topic", async function () { + it("makes successful update thread topic", async () => { const mockHttpClient = generateHttpClient(204); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const topic = "mockTopic"; await chatThreadClient.updateTopic(topic); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal(request.url, `${baseUri}/chat/threads/${threadId}?api-version=${API_VERSION}`); assert.equal(request.method, "PATCH"); assert.deepEqual(JSON.parse(request.body as string), { topic: topic }); }); - it("makes successful send message request", async function () { + it("makes successful send message request", async () => { const mockHttpClient = generateHttpClient(201, { id: mockMessage.id, }); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendRequest: SendMessageRequest = { content: mockMessage.content?.message as string, @@ -103,10 +101,10 @@ describe("[Mocked] ChatThreadClient", async function () { const response = await chatThreadClient.sendMessage(sendRequest, sendOptions); - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(response.id, mockMessage.id); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -119,10 +117,10 @@ describe("[Mocked] ChatThreadClient", async function () { }); }); - it("makes successful get message request", async function () { + it("makes successful get message request", async () => { const mockHttpClient = generateHttpClient(200, mockMessage); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const { sender: responseUser, @@ -137,7 +135,7 @@ describe("[Mocked] ChatThreadClient", async function () { const { participants: expectedParticipants, ...expectedContents } = expectedContent!; const { participants: responseParticipants, ...repsonseContents } = responseContent!; - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.deepEqual(responseMessage, expectedMessage); assert.equal(responseUser?.kind, "communicationUser"); assert.equal( @@ -146,7 +144,7 @@ describe("[Mocked] ChatThreadClient", async function () { ); assert.deepEqual(repsonseContents, expectedContents); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -155,10 +153,10 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful get message with image attachments request", async function () { + it("makes successful get message with image attachments request", async () => { const mockHttpClient = generateHttpClient(200, mockMessageWithImageAttachment); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const { sender: responseUser, @@ -180,20 +178,20 @@ describe("[Mocked] ChatThreadClient", async function () { attachments: responseAttachments, ...repsonseContents } = responseContent!; - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.deepEqual(responseMessage, expectedMessage); assert.deepEqual(responseAttachments, expectedAttachments); assert.deepEqual(repsonseContents, expectedContents); assert.equal(responseAttachments![0].attachmentType, "image"); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "GET"); }); - it("makes successful get message with file attachments request", async function () { + it("makes successful get message with file attachments request", async () => { const mockHttpClient = generateHttpClient(200, mockMessageWithFileAttachment); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const { sender: responseUser, @@ -215,17 +213,17 @@ describe("[Mocked] ChatThreadClient", async function () { attachments: responseAttachments, ...repsonseContents } = responseContent!; - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.deepEqual(responseMessage, expectedMessage); assert.deepEqual(responseAttachments, expectedAttachments); assert.deepEqual(repsonseContents, expectedContents); assert.equal(responseAttachments![0].attachmentType, "file"); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal(request.method, "GET"); }); - it("makes successful list messages request", async function () { + it("makes successful list messages request", async () => { const { senderCommunicationIdentifier, ...rest } = mockMessage; const mockResponse: RestModel.ChatMessagesCollection = { @@ -235,7 +233,7 @@ describe("[Mocked] ChatThreadClient", async function () { const mockHttpClient = generateHttpClient(200, mockResponse); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); let count = 0; for await (const message of chatThreadClient.listMessages()) { @@ -263,10 +261,10 @@ describe("[Mocked] ChatThreadClient", async function () { ++count; } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, mockResponse.value?.length); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -275,7 +273,7 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful list messages request by page", async function () { + it("makes successful list messages request by page", async () => { const { senderCommunicationIdentifier, ...rest } = mockMessage; const mockResponse: RestModel.ChatMessagesCollection = { @@ -285,7 +283,7 @@ describe("[Mocked] ChatThreadClient", async function () { const mockHttpClient = generateHttpClient(200, mockResponse); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const iterator = chatThreadClient.listMessages({ maxPageSize: 2 }); @@ -298,10 +296,10 @@ describe("[Mocked] ChatThreadClient", async function () { } } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, mockResponse.value?.length); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -310,10 +308,10 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful update message request", async function () { + it("makes successful update message request", async () => { const mockHttpClient = generateHttpClient(204); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendOptions: UpdateMessageOptions = { content: mockMessage.content?.message, @@ -322,8 +320,8 @@ describe("[Mocked] ChatThreadClient", async function () { await chatThreadClient.updateMessage(mockMessage.id!, sendOptions); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/messages/${mockMessage.id}?api-version=${API_VERSION}`, @@ -335,15 +333,15 @@ describe("[Mocked] ChatThreadClient", async function () { }); }); - it("makes successful delete message request", async function () { + it("makes successful delete message request", async () => { const mockHttpClient = generateHttpClient(204); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); await chatThreadClient.deleteMessage(mockMessage.id!); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/messages/${mockMessage.id}?api-version=${API_VERSION}`, @@ -351,10 +349,10 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "DELETE"); }); - it("makes successful add chat participants request", async function () { + it("makes successful add chat participants request", async () => { const mockHttpClient = generateHttpClient(201); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const sendRequest: AddParticipantsRequest = { participants: [mockSdkModelParticipant], @@ -362,8 +360,8 @@ describe("[Mocked] ChatThreadClient", async function () { await chatThreadClient.addParticipants(sendRequest); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -382,12 +380,12 @@ describe("[Mocked] ChatThreadClient", async function () { ); }); - it("makes successful list chat participants request", async function () { + it("makes successful list chat participants request", async () => { const mockHttpClient = generateHttpClient(200, { value: [mockParticipant], }); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); let count = 0; for await (const participant of chatThreadClient.listParticipants()) { @@ -402,10 +400,10 @@ describe("[Mocked] ChatThreadClient", async function () { assert.deepEqual(requestParticipant, expectedParticipant); } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, 1); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -414,12 +412,12 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful list chat participants request by page", async function () { + it("makes successful list chat participants request by page", async () => { const mockHttpClient = generateHttpClient(200, { value: [mockParticipant, mockParticipant, mockParticipant], }); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const iterator = chatThreadClient.listParticipants({ maxPageSize: 2 }); let count = 0; @@ -431,10 +429,10 @@ describe("[Mocked] ChatThreadClient", async function () { } } - sinon.assert.calledOnce(spy); + expect(spy).toHaveBeenCalledOnce(); assert.equal(count, 3); - const request = spy.getCall(0).args[0]; + const request = spy.mock.calls[0][0]; assert.equal( request.url, @@ -443,15 +441,15 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "GET"); }); - it("makes successful remove chat participant request", async function () { + it("makes successful remove chat participant request", async () => { const mockHttpClient = generateHttpClient(204); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); await chatThreadClient.removeParticipant(mockSdkModelParticipant.id); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/participants/:remove?api-version=${API_VERSION}`, @@ -461,16 +459,16 @@ describe("[Mocked] ChatThreadClient", async function () { assert.deepEqual(mockParticipant.communicationIdentifier, requestJson); }); - it("makes successful sent typing notification request", async function () { + it("makes successful sent typing notification request", async () => { const mockHttpClient = generateHttpClient(200); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const result = await chatThreadClient.sendTypingNotification(); assert.isTrue(result); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/typing?api-version=${API_VERSION}`, @@ -478,10 +476,10 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "POST"); }); - it("makes only one sent typing notification request within 8 secs", async function () { + it("makes only one sent typing notification request within 8 secs", async () => { const mockHttpClient = generateHttpClient(400); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); try { await chatThreadClient.sendTypingNotification(); @@ -492,8 +490,8 @@ describe("[Mocked] ChatThreadClient", async function () { const result = await chatThreadClient.sendTypingNotification(); assert.isFalse(result); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/typing?api-version=${API_VERSION}`, @@ -502,17 +500,17 @@ describe("[Mocked] ChatThreadClient", async function () { } }); - it("makes successful sent typing notification request with sender display name", async function () { + it("makes successful sent typing notification request with sender display name", async () => { const mockHttpClient = generateHttpClient(200); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); const options = { senderDisplayName: "Bob Admin" }; const result = await chatThreadClient.sendTypingNotification(options); assert.isTrue(result); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/typing?api-version=${API_VERSION}`, @@ -521,15 +519,15 @@ describe("[Mocked] ChatThreadClient", async function () { assert.deepEqual(JSON.parse(request.body as string), options); }); - it("makes successful sent read receipt request", async function () { + it("makes successful sent read receipt request", async () => { const mockHttpClient = generateHttpClient(200); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); await chatThreadClient.sendReadReceipt({ chatMessageId: mockMessage.id! }); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/readReceipts?api-version=${API_VERSION}`, @@ -537,12 +535,12 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(request.method, "POST"); }); - it("makes successful list read receipts request", async function () { + it("makes successful list read receipts request", async () => { const mockHttpClient = generateHttpClient(200, { value: [mockChatMessageReadReceipt, mockChatMessageReadReceipt], }); chatThreadClient = createChatThreadClient(threadId, mockHttpClient); - const spy = sinon.spy(mockHttpClient, "sendRequest"); + const spy = vi.spyOn(mockHttpClient, "sendRequest"); let count = 0; for await (const readReceipt of chatThreadClient.listReadReceipts()) { @@ -560,8 +558,8 @@ describe("[Mocked] ChatThreadClient", async function () { assert.equal(count, 2); - sinon.assert.calledOnce(spy); - const request = spy.getCall(0).args[0]; + expect(spy).toHaveBeenCalledOnce(); + const request = spy.mock.calls[0][0]; assert.equal( request.url, `${baseUri}/chat/threads/${threadId}/readReceipts?api-version=${API_VERSION}`, diff --git a/sdk/communication/communication-chat/test/internal/utils/mockClient.ts b/sdk/communication/communication-chat/test/internal/utils/mockClient.ts index 87cf11d3c71a..ccff7fa59f20 100644 --- a/sdk/communication/communication-chat/test/internal/utils/mockClient.ts +++ b/sdk/communication/communication-chat/test/internal/utils/mockClient.ts @@ -4,11 +4,11 @@ import { AzureCommunicationTokenCredential } from "@azure/communication-common"; 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 type { ChatParticipant } from "../../../src"; -import { ChatClient, ChatThreadClient } from "../../../src"; -import type { CommunicationIdentifierModel } from "../../../src/generated/src"; -import { baseUri, generateToken } from "../../public/utils/connectionUtils"; +import type * as RestModel from "../../../src/generated/src/models/index.js"; +import type { ChatParticipant } from "../../../src/index.js"; +import { ChatClient, ChatThreadClient } from "../../../src/index.js"; +import type { CommunicationIdentifierModel } from "../../../src/generated/src/index.js"; +import { baseUri, generateToken } from "../../public/utils/connectionUtils.js"; export const mockCommunicationIdentifier: CommunicationIdentifierModel = { communicationUser: { id: "id" }, diff --git a/sdk/communication/communication-chat/test/public/chatClient.spec.ts b/sdk/communication/communication-chat/test/public/chatClient.spec.ts index b987f7d4aeb9..465dc0571d41 100644 --- a/sdk/communication/communication-chat/test/public/chatClient.spec.ts +++ b/sdk/communication/communication-chat/test/public/chatClient.spec.ts @@ -3,16 +3,14 @@ import type { Recorder } from "@azure-tools/test-recorder"; import { isLiveMode } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { ChatClient, ChatThreadClient } from "../../src"; -import { createChatClient, createRecorder, createTestUser } from "./utils/recordedClient"; -import { isNode } from "@azure/core-util"; -import sinon from "sinon"; +import { isNodeLike } from "@azure/core-util"; +import type { ChatClient, ChatThreadClient } from "../../src/index.js"; +import { createChatClient, createRecorder, createTestUser } from "./utils/recordedClient.js"; import type { CommunicationIdentifier } from "@azure/communication-common"; -import type { Context } from "mocha"; import type { CommunicationUserToken } from "@azure/communication-identity"; +import { describe, it, assert, expect, vi, beforeEach, afterEach, beforeAll } from "vitest"; -describe("ChatClient", function () { +describe("ChatClient", () => { let threadId: string | undefined; let recorder: Recorder; let chatClient: ChatClient; @@ -21,15 +19,9 @@ describe("ChatClient", function () { let testUser: CommunicationIdentifier; let testUser2: CommunicationIdentifier; - after(async function () { - // await deleteTestUser(testUser); - // await deleteTestUser(testUser2); - // await deleteTestUser(testUser3); - }); - - describe("Chat Operations", function () { - beforeEach(async function (this: Context) { - recorder = await createRecorder(this.currentTest); + describe("Chat Operations", () => { + beforeEach(async (ctx) => { + recorder = await createRecorder(ctx); await recorder.setMatcher("HeaderlessMatcher"); if (!communicationUserToken) { communicationUserToken = await createTestUser(recorder); @@ -37,11 +29,11 @@ describe("ChatClient", function () { chatClient = createChatClient(communicationUserToken.token, recorder); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it("successfully creates a thread", async function () { + it("successfully creates a thread", { timeout: 8000 }, async () => { testUser = communicationUserToken.user; testUser2 = (await createTestUser(recorder)).user; @@ -59,29 +51,24 @@ describe("ChatClient", function () { assert.isDefined(chatThread); assert.isDefined(chatThread?.id); - }).timeout(8000); + }); - it("successfully retrieves a thread client", async function () { + it("successfully retrieves a thread client", async () => { chatThreadClient = chatClient.getChatThreadClient(threadId!); assert.isNotNull(chatThreadClient); assert.equal(chatThreadClient.threadId, threadId); }); - it("successfully deletes a thread", async function () { + it("successfully deletes a thread", async () => { await chatClient.deleteChatThread(threadId!); }); }); - describe("Realtime Notifications", function () { - before(async function (this: Context) { - // Realtime notifications are browser only - if (isNode || !isLiveMode()) { - this.skip(); - } - + describe("Realtime Notifications", { skip: isNodeLike || !isLiveMode() }, () => { + beforeAll(async () => { // Create a thread const request = { - topic: "notifcation tests", + topic: "notification tests", participants: [{ id: testUser }], }; const chatThreadResult = await chatClient.createChatThread(request); @@ -91,13 +78,13 @@ describe("ChatClient", function () { chatThreadClient = chatClient.getChatThreadClient(threadId!); }); - beforeEach(async function () { + beforeEach(async () => { // Start notifications await chatClient.startRealtimeNotifications(); }); - it("successfully stops realtime notifications", async function () { - const listener = sinon.spy(); + it("successfully stops realtime notifications", async () => { + const listener = vi.fn(); chatClient.on("typingIndicatorReceived", listener); await chatClient.stopRealtimeNotifications(); @@ -106,173 +93,227 @@ describe("ChatClient", function () { // Allow time to see if notification comes in await new Promise((resolve) => setTimeout(resolve, 5000)); - sinon.assert.notCalled(listener); + expect(listener).not.toHaveBeenCalled(); }); - it("successfully unsubscribes a listener", function (done) { - function listener(): void { - assert.fail(); - } - - chatClient.on("typingIndicatorReceived", listener); - chatClient.off("typingIndicatorReceived", listener); - - // Send typing notification - chatThreadClient.sendTypingNotification(); - - // Wait a bit and fail if the notification comes in - setTimeout(done, 5000); - }).timeout(8000); - - it("successfully listens to typingIndicatorReceivedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("typingIndicatorReceived", listener); - - // Send typing notification - chatThreadClient.sendTypingNotification(); - }).timeout(8000); - - it("successfully listens to chatMessageEditedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatMessageEdited", listener); - - // Edit message - const message = { content: "content" }; - chatThreadClient - .sendMessage(message) - .then((result) => { - return chatThreadClient.updateMessage(result.id, { - content: "new content", - }); - }) - .catch((error) => console.error(error)); - }).timeout(8000); - - it("successfully listens to chatMessageReceivedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatMessageReceived", listener); - - // Send message - const message = { content: `content` }; - chatThreadClient.sendMessage(message); - }).timeout(8000); - - it("successfully listens to chatMessageDeletedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatMessageDeleted", listener); - - // Delete message - const message = { content: `content` }; - chatThreadClient - .sendMessage(message) - .then((result) => { - return chatThreadClient.deleteMessage(result.id); - }) - .catch((error) => console.error(error)); - }).timeout(8000); - - it("successfully listens to chatThreadCreatedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatThreadCreated", listener); - - // Create thread - const request = { - topic: "test create thread event", - participants: [{ id: testUser }], - }; - chatClient.createChatThread(request); - }).timeout(8000); - - it("successfully listens to chatThreadDeletedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatThreadDeleted", listener); - - // Delete thread - const request = { - topic: "test delete thread event", - participants: [{ id: testUser }], - }; - chatClient - .createChatThread(request) - .then((result) => { - return chatClient.deleteChatThread(result.chatThread?.id as string); - }) - .catch((error) => console.error(error)); - }).timeout(8000); - - it("successfully listens to chatThreadPropertiesUpdatedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("chatThreadPropertiesUpdated", listener); - - // Update thread - chatThreadClient.updateTopic("updated topic"); - }).timeout(8000); - - it("successfully listens to participantsAddedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("participantsAdded", listener); - - // Add participant - const request = { - participants: [{ id: testUser2 }], - }; - chatThreadClient.addParticipants(request); - }).timeout(8000); - - it("successfully listens to participantsRemovedEvents", function (done) { - function listener(): void { - done(); - } - - chatClient.on("participantsRemoved", listener); - - // Remove participant - chatThreadClient.removeParticipant(testUser2); - }).timeout(8000); - - it("successfully listens to readReceiptReceivedEvents", function (this: Context, done) { - // TODO: Read receipt notification is timing out even with increased timeout - this.skip(); - function listener(): void { - done(); - } - - chatClient.on("readReceiptReceived", listener); - - // Send read receipt - const message = { content: "content" }; - chatThreadClient - .sendMessage(message) - .then((result) => { - return chatThreadClient.sendReadReceipt({ - chatMessageId: result.id, - }); - }) - .catch((error) => console.error(error)); - }).timeout(8000); + it( + "successfully unsubscribes a listener", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + assert.fail(); + } + + chatClient.on("typingIndicatorReceived", listener); + chatClient.off("typingIndicatorReceived", listener); + + // Send typing notification + chatThreadClient.sendTypingNotification(); + + // Wait a bit and fail if the notification comes in + setTimeout(resolve, 5000); + }), + ); + + it( + "successfully listens to typingIndicatorReceivedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("typingIndicatorReceived", listener); + + // Send typing notification + chatThreadClient.sendTypingNotification(); + }), + ); + + it( + "successfully listens to chatMessageEditedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatMessageEdited", listener); + + // Edit message + const message = { content: "content" }; + chatThreadClient + .sendMessage(message) + .then((result) => { + return chatThreadClient.updateMessage(result.id, { + content: "new content", + }); + }) + .catch((error) => console.error(error)); + }), + ); + + it( + "successfully listens to chatMessageReceivedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatMessageReceived", listener); + + // Send message + const message = { content: `content` }; + chatThreadClient.sendMessage(message); + }), + ); + + it( + "successfully listens to chatMessageDeletedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatMessageDeleted", listener); + + // Delete message + const message = { content: `content` }; + chatThreadClient + .sendMessage(message) + .then((result) => { + return chatThreadClient.deleteMessage(result.id); + }) + .catch((error) => console.error(error)); + }), + ); + + it( + "successfully listens to chatThreadCreatedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatThreadCreated", listener); + + // Create thread + const request = { + topic: "test create thread event", + participants: [{ id: testUser }], + }; + chatClient.createChatThread(request); + }), + ); + + it( + "successfully listens to chatThreadDeletedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatThreadDeleted", listener); + + // Delete thread + const request = { + topic: "test delete thread event", + participants: [{ id: testUser }], + }; + chatClient + .createChatThread(request) + .then((result) => { + return chatClient.deleteChatThread(result.chatThread?.id as string); + }) + .catch((error) => console.error(error)); + }), + ); + + it( + "successfully listens to chatThreadPropertiesUpdatedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("chatThreadPropertiesUpdated", listener); + + // Update thread + chatThreadClient.updateTopic("updated topic"); + }), + ); + + it( + "successfully listens to participantsAddedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("participantsAdded", listener); + + // Add participant + const request = { + participants: [{ id: testUser2 }], + }; + chatThreadClient.addParticipants(request); + }), + ); + + it( + "successfully listens to participantsRemovedEvents", + { timeout: 8000 }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("participantsRemoved", listener); + + // Remove participant + chatThreadClient.removeParticipant(testUser2); + }), + ); + + // TODO: Read receipt notification is timing out even with increased timeout + it( + "successfully listens to readReceiptReceivedEvents", + { timeout: 8000, skip: true }, + () => + new Promise((resolve) => { + function listener(): void { + resolve(); + } + + chatClient.on("readReceiptReceived", listener); + + // Send read receipt + const message = { content: "content" }; + chatThreadClient + .sendMessage(message) + .then((result) => { + return chatThreadClient.sendReadReceipt({ + chatMessageId: result.id, + }); + }) + .catch((error) => console.error(error)); + }), + ); }); }); diff --git a/sdk/communication/communication-chat/test/public/chatThreadClient.spec.ts b/sdk/communication/communication-chat/test/public/chatThreadClient.spec.ts index 69a0de1a2d55..d1bf9fad5445 100644 --- a/sdk/communication/communication-chat/test/public/chatThreadClient.spec.ts +++ b/sdk/communication/communication-chat/test/public/chatThreadClient.spec.ts @@ -1,17 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/* eslint-disable @typescript-eslint/no-invalid-this */ import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { ChatClient, ChatMessage, ChatThreadClient } from "../../src"; -import { createChatClient, createRecorder, createTestUser } from "./utils/recordedClient"; +import type { ChatClient, ChatMessage, ChatThreadClient } from "../../src/index.js"; +import { createChatClient, createRecorder, createTestUser } from "./utils/recordedClient.js"; import type { CommunicationIdentifier } from "@azure/communication-common"; import { getIdentifierKind } from "@azure/communication-common"; -import type { Context } from "mocha"; import type { CommunicationUserToken } from "@azure/communication-identity"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; +import { isNodeLike } from "@azure/core-util"; -describe("ChatThreadClient", function () { +// TODO: Re-record the tests with the new recorder +describe("ChatThreadClient", { skip: !isNodeLike }, () => { let messageId: string; let recorder: Recorder; let chatClient: ChatClient; @@ -22,8 +22,8 @@ describe("ChatThreadClient", function () { let testUser2: CommunicationIdentifier; let testUser3: CommunicationIdentifier; - beforeEach(async function (this: Context) { - recorder = await createRecorder(this.currentTest); + beforeEach(async (ctx) => { + recorder = await createRecorder(ctx); if (!communicationUserToken) { communicationUserToken = await createTestUser(recorder); await recorder.setMatcher("HeaderlessMatcher"); @@ -33,14 +33,14 @@ describe("ChatThreadClient", function () { chatThreadClient = chatClient.getChatThreadClient(threadId); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); /** * This test intialized chatThreadClient for other tests with recorder enabled */ - it("successfully initializes chatThreadClient", async function () { + it("successfully initializes chatThreadClient", { timeout: 8000 }, async () => { // Create ChatClient testUser = communicationUserToken.user; testUser2 = (await createTestUser(recorder)).user; @@ -53,15 +53,15 @@ describe("ChatThreadClient", function () { const chatThreadResult = await chatClient.createChatThread(request, options); threadId = chatThreadResult.chatThread?.id as string; - }).timeout(8000); + }); - it("successfully gets the thread properties", async function () { + it("successfully gets the thread properties", async () => { const thread = await chatThreadClient.getProperties(); assert.equal(threadId, thread.id); }); - it("successfully updates the thread topic", async function () { + it("successfully updates the thread topic", async () => { const topic = "new topic"; await chatThreadClient.updateTopic(topic); @@ -69,7 +69,7 @@ describe("ChatThreadClient", function () { assert.equal(topic, thread.topic); }); - it("successfully sends a message", async function () { + it("successfully sends a message", async () => { const request = { content: `content` }; const options = { metadata: { tags: "sometag" } }; const result = await chatThreadClient.sendMessage(request, options); @@ -78,17 +78,17 @@ describe("ChatThreadClient", function () { messageId = result.id!; }); - it("successfully sends typing notification", async function () { + it("successfully sends typing notification", async () => { const result = await chatThreadClient.sendTypingNotification(); assert.isTrue(result); }); - it("successfully sends read receipt", async function () { + it("successfully sends read receipt", async () => { await chatThreadClient.sendReadReceipt({ chatMessageId: messageId }); }); - it("successfully retrieves a message", async function () { + it("successfully retrieves a message", async () => { const message = await chatThreadClient.getMessage(messageId); assert.isNotNull(message); @@ -96,7 +96,7 @@ describe("ChatThreadClient", function () { assert.isDefined(message.metadata?.tags); }); - it("successfully lists messages one by one and by page", async function () { + it("successfully lists messages one by one and by page", async () => { const receivedItems: ChatMessage[] = []; for await (const message of chatThreadClient.listMessages()) { receivedItems.push(message); @@ -119,18 +119,18 @@ describe("ChatThreadClient", function () { assert.deepEqual(receivedPagedItems, receivedItems); }); - it("successfully deletes a message", async function () { + it("successfully deletes a message", async () => { await chatThreadClient.deleteMessage(messageId); }); - it("successfully adds participants", async function () { + it("successfully adds participants", async () => { testUser3 = (await createTestUser(recorder)).user; const request = { participants: [{ id: testUser3 }] }; await chatThreadClient.addParticipants(request); }); - it("successfully lists participants", async function () { + it("successfully lists participants", async () => { const list: string[] = []; for await (const participant of chatThreadClient.listParticipants()) { const id = getIdentifierKind(participant.id); @@ -151,11 +151,11 @@ describe("ChatThreadClient", function () { } }); - it("successfully remove a participant", async function () { + it("successfully remove a participant", async () => { await chatThreadClient.removeParticipant(testUser2); }); - it("successfully lists read receipts", async function () { + it("successfully lists read receipts", async () => { const list: string[] = []; for await (const receipt of chatThreadClient.listReadReceipts()) { list.push(receipt.chatMessageId!); diff --git a/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts b/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts index 50c6b8245229..5200c78a6a74 100644 --- a/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts +++ b/sdk/communication/communication-chat/test/public/utils/connectionUtils.ts @@ -1,16 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { isNode } from "@azure/core-util"; +import { getToken } from "./getToken.js"; export const baseUri = "https://contoso.api.fake"; -declare function btoa(stringToEncode: string): string; - 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 = getToken(tokenString); return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${base64Token}.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs`; }; diff --git a/sdk/communication/communication-chat/test/public/utils/getToken-browser.mts b/sdk/communication/communication-chat/test/public/utils/getToken-browser.mts new file mode 100644 index 000000000000..537f640b72d8 --- /dev/null +++ b/sdk/communication/communication-chat/test/public/utils/getToken-browser.mts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export function getToken(tokenString: string): string { + return btoa(tokenString); +} diff --git a/sdk/communication/communication-chat/test/public/utils/getToken.ts b/sdk/communication/communication-chat/test/public/utils/getToken.ts new file mode 100644 index 000000000000..3fda5484c077 --- /dev/null +++ b/sdk/communication/communication-chat/test/public/utils/getToken.ts @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { Buffer } from "node:buffer"; + +export function getToken(tokenString: string): string { + return Buffer.from(tokenString).toString("base64"); +} diff --git a/sdk/communication/communication-chat/test/public/utils/recordedClient.ts b/sdk/communication/communication-chat/test/public/utils/recordedClient.ts index c264f74f5871..da7a730b5c39 100644 --- a/sdk/communication/communication-chat/test/public/utils/recordedClient.ts +++ b/sdk/communication/communication-chat/test/public/utils/recordedClient.ts @@ -1,16 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { Test } from "mocha"; - -import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder"; import { Recorder, assertEnvironmentVariable, env, isPlaybackMode, } from "@azure-tools/test-recorder"; -import { ChatClient } from "../../../src"; +import { ChatClient } from "../../../src/index.js"; import type { CommunicationUserIdentifier } from "@azure/communication-common"; import { AzureCommunicationTokenCredential, @@ -18,7 +16,7 @@ import { } from "@azure/communication-common"; import type { CommunicationUserToken } from "@azure/communication-identity"; import { CommunicationIdentityClient } from "@azure/communication-identity"; -import { generateToken } from "./connectionUtils"; +import { generateToken } from "./connectionUtils.js"; import { NoOpCredential } from "@azure-tools/test-credential"; export interface RecordedClient { @@ -67,7 +65,7 @@ export async function deleteTestUser(testUser: CommunicationUserIdentifier): Pro } } -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); return recorder; diff --git a/sdk/communication/communication-chat/tsconfig.browser.config.json b/sdk/communication/communication-chat/tsconfig.browser.config.json new file mode 100644 index 000000000000..f772e6eb3b76 --- /dev/null +++ b/sdk/communication/communication-chat/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-chat/tsconfig.json b/sdk/communication/communication-chat/tsconfig.json index 0b6b6563bf0f..f056035f201d 100644 --- a/sdk/communication/communication-chat/tsconfig.json +++ b/sdk/communication/communication-chat/tsconfig.json @@ -1,11 +1,20 @@ { "extends": "../../../tsconfig", "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", "paths": { "@azure/communication-chat": ["./src/index"] - } + }, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": "." }, - "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] + "include": [ + "src/**/*.ts", + "src/**/*.mts", + "src/**/*.cts", + "samples-dev/**/*.ts", + "test/**/*.ts", + "test/**/*.mts", + "test/**/*.cts" + ] } diff --git a/sdk/communication/communication-chat/vitest.browser.config.ts b/sdk/communication/communication-chat/vitest.browser.config.ts new file mode 100644 index 000000000000..50ec2d5489b0 --- /dev/null +++ b/sdk/communication/communication-chat/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-chat/vitest.config.ts b/sdk/communication/communication-chat/vitest.config.ts new file mode 100644 index 000000000000..3dd2a27d3024 --- /dev/null +++ b/sdk/communication/communication-chat/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, + }), +);