diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e04ede93e17c..a825d8cd8b84 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -12258,7 +12258,7 @@ packages: dev: false file:projects/ai-translation-text.tgz: - resolution: {integrity: sha512-sKlY84hVWOP+lM3tsInKK2iJWx8pCCu0f010wiGj85UvYFdfL54aFoFMfHGrkHO4HNCRM/VZdrpcCDKMOYbclw==, tarball: file:projects/ai-translation-text.tgz} + resolution: {integrity: sha512-3XHDssLX0ri0CjiccRr82uxLp55vWhz/mOIB2bz6zjrGD7QRPSsvIjzh1enrZwVX1/w73UcBKtPMxioOvDyfJA==, tarball: file:projects/ai-translation-text.tgz} name: '@rush-temp/ai-translation-text' version: 0.0.0 dependencies: @@ -12268,6 +12268,8 @@ packages: '@types/chai': 4.3.20 '@types/mocha': 10.0.10 '@types/node': 18.19.65 + '@vitest/browser': 2.1.5(@types/node@18.19.65)(playwright@1.49.0)(typescript@5.6.3)(vitest@2.1.5) + '@vitest/coverage-istanbul': 2.1.5(vitest@2.1.5) autorest: 3.7.1 chai: 4.3.10 dotenv: 16.4.5 @@ -12284,18 +12286,32 @@ packages: karma-sourcemap-loader: 0.3.8 mocha: 10.8.2 nyc: 17.1.0 + playwright: 1.49.0 source-map-support: 0.5.21 ts-node: 10.9.2(@types/node@18.19.65)(typescript@5.6.3) tslib: 2.8.1 typescript: 5.6.3 + vitest: 2.1.5(@types/node@18.19.65)(@vitest/browser@2.1.5) transitivePeerDependencies: - - '@swc/core' - - '@swc/wasm' + - '@edge-runtime/vm' + - '@vitest/ui' - bufferutil - - debug + - happy-dom - jiti + - jsdom + - less + - lightningcss + - msw + - safaridriver + - sass + - sass-embedded + - stylus + - sugarss - supports-color + - terser - utf-8-validate + - vite + - webdriverio dev: false file:projects/ai-vision-face.tgz: diff --git a/sdk/translation/ai-translation-text-rest/README.md b/sdk/translation/ai-translation-text-rest/README.md index 335e193f1dbe..abcd0c6dd096 100644 --- a/sdk/translation/ai-translation-text-rest/README.md +++ b/sdk/translation/ai-translation-text-rest/README.md @@ -291,7 +291,7 @@ You can find the different error codes returned by the service in the [Service D Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: -```javascript +```ts const { setLogLevel } = require("@azure/logger"); setLogLevel("info"); diff --git a/sdk/translation/ai-translation-text-rest/api-extractor.json b/sdk/translation/ai-translation-text-rest/api-extractor.json index ebfd2ff45058..2f2a279d7336 100644 --- a/sdk/translation/ai-translation-text-rest/api-extractor.json +++ b/sdk/translation/ai-translation-text-rest/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/ai-translation-text.d.ts" + "publicTrimmedFilePath": "dist/ai-translation-text.d.ts" }, "messages": { "tsdocMessageReporting": { diff --git a/sdk/translation/ai-translation-text-rest/karma.conf.js b/sdk/translation/ai-translation-text-rest/karma.conf.js deleted file mode 100644 index 5e421fa3be28..000000000000 --- a/sdk/translation/ai-translation-text-rest/karma.conf.js +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// https://github.com/karma-runner/karma-chrome-launcher -process.env.CHROME_BIN = require("puppeteer").executablePath(); -require("dotenv").config(); -const { relativeRecordingsPath } = require("@azure-tools/test-recorder"); -process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath(); - -module.exports = function (config) { - config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: "./", - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ["source-map-support", "mocha"], - - plugins: [ - "karma-mocha", - "karma-mocha-reporter", - "karma-chrome-launcher", - "karma-firefox-launcher", - "karma-env-preprocessor", - "karma-coverage", - "karma-sourcemap-loader", - "karma-junit-reporter", - "karma-source-map-support", - ], - - // list of files / patterns to load in the browser - files: [ - "dist-test/index.browser.js", - { - pattern: "dist-test/index.browser.js.map", - type: "html", - included: false, - served: true, - }, - ], - - // list of files / patterns to exclude - exclude: [], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - "**/*.js": ["sourcemap", "env"], - // IMPORTANT: COMMENT following line if you want to debug in your browsers!! - // Preprocess source file to calculate code coverage, however this will make source file unreadable - // "dist-test/index.js": ["coverage"] - }, - - envPreprocessor: [ - "TEST_MODE", - "TEXT_TRANSLATION_TENANT_ID", - "TEXT_TRANSLATION_CLIENT_ID", - "TEXT_TRANSLATION_CLIENT_SECRET", - "TEXT_TRANSLATION_ENDPOINT", - "TEXT_TRANSLATION_CUSTOM_ENDPOINT", - "TEXT_TRANSLATION_API_KEY", - "TEXT_TRANSLATION_REGION", - "RECORDINGS_RELATIVE_PATH", - "TEXT_TRANSLATION_AAD_REGION", - "TEXT_TRANSLATION_RESOURCE_ID", - ], - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ["mocha", "coverage", "junit"], - - coverageReporter: { - // specify a common output directory - dir: "coverage-browser/", - reporters: [ - { type: "json", subdir: ".", file: "coverage.json" }, - { type: "lcovonly", subdir: ".", file: "lcov.info" }, - { type: "html", subdir: "html" }, - { type: "cobertura", subdir: ".", file: "cobertura-coverage.xml" }, - ], - }, - - junitReporter: { - outputDir: "", // results will be saved as $outputDir/$browserName.xml - outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile - suite: "", // suite will become the package name attribute in xml testsuite element - useBrowserName: false, // add browser name to report and classes names - nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element - classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element - properties: {}, // key value pair of properties to add to the section of the report - }, - - // web server port - port: 9876, - - // enable / disable colors in the output (reporters and logs) - colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - // --no-sandbox allows our tests to run in Linux without having to change the system. - // --disable-web-security allows us to authenticate from the browser without having to write tests using interactive auth, which would be far more complex. - browsers: ["ChromeHeadlessNoSandbox"], - customLaunchers: { - ChromeHeadlessNoSandbox: { - base: "ChromeHeadless", - flags: ["--no-sandbox", "--disable-web-security"], - }, - }, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: 1, - - browserNoActivityTimeout: 60000000, - browserDisconnectTimeout: 10000, - browserDisconnectTolerance: 3, - - client: { - mocha: { - // change Karma's debug.html to the mocha web reporter - reporter: "html", - timeout: "600000", - }, - }, - }); -}; diff --git a/sdk/translation/ai-translation-text-rest/package.json b/sdk/translation/ai-translation-text-rest/package.json index 794109140966..96328a06c0ef 100644 --- a/sdk/translation/ai-translation-text-rest/package.json +++ b/sdk/translation/ai-translation-text-rest/package.json @@ -16,19 +16,16 @@ "translation" ], "license": "MIT", - "main": "dist/index.js", - "module": "./dist-esm/src/index.js", - "types": "./types/ai-translation-text.d.ts", + "main": "./dist/commonjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/commonjs/index.d.ts", "repository": "github:Azure/azure-sdk-for-js", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, "files": [ "dist/", - "dist-esm/src/", - "types/ai-translation-text.d.ts", "README.md", - "CHANGELOG.md", "LICENSE" ], "engines": { @@ -46,12 +43,12 @@ } }, "scripts": { - "build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", - "build:browser": "tsc -p . && dev-tool run bundle", - "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api", - "build:node": "tsc -p . && dev-tool run bundle --browser-test false", + "build": "npm run clean && dev-tool run build-package && dev-tool run extract-api", + "build:browser": "dev-tool run build-package && dev-tool run bundle", + "build:debug": "dev-tool run build-package && dev-tool run bundle && dev-tool run extract-api", + "build:node": "dev-tool run build-package && dev-tool run bundle --browser-test false", "build:samples": "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-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "dev-tool samples run samples-dev", @@ -59,8 +56,8 @@ "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "generate:client": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "integration-test:browser": "dev-tool run test:browser", - "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'", + "integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", + "integration-test:node": "dev-tool run test:vitest", "lint": "eslint package.json api-extractor.json src test", "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", @@ -68,47 +65,35 @@ "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", "test:node": "npm run clean && npm run build:test && npm run unit-test:node", "unit-test": "npm run unit-test:node && npm run unit-test:browser", - "unit-test:browser": "dev-tool run test:browser", - "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", + "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", + "unit-test:node": "dev-tool run test:vitest", "update-snippets": "echo skipped" }, "sideEffects": false, "autoPublish": false, "dependencies": { - "@azure-rest/core-client": "^1.1.0", - "@azure/core-auth": "^1.3.0", - "@azure/core-rest-pipeline": "^1.8.0", - "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" + "@azure-rest/core-client": "^2.3.1", + "@azure/core-auth": "^1.9.0", + "@azure/core-rest-pipeline": "^1.18.0", + "@azure/logger": "^1.1.4", + "tslib": "^2.8.1" }, "devDependencies": { - "@azure-tools/test-credential": "^1.0.0", - "@azure-tools/test-recorder": "^3.0.0", + "@azure-tools/test-credential": "^2.0.0", + "@azure-tools/test-recorder": "^4.1.0", + "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@azure/identity": "^4.0.1", - "@types/chai": "^4.2.8", - "@types/mocha": "^10.0.0", + "@azure/identity": "^4.5.0", "@types/node": "^18.0.0", + "@vitest/browser": "^2.1.5", + "@vitest/coverage-istanbul": "^2.1.5", "autorest": "latest", - "chai": "^4.2.0", "dotenv": "^16.0.0", "eslint": "^9.9.0", - "karma": "^6.2.0", - "karma-chrome-launcher": "^3.0.0", - "karma-coverage": "^2.0.0", - "karma-env-preprocessor": "^0.1.1", - "karma-firefox-launcher": "^1.1.0", - "karma-junit-reporter": "^2.0.1", - "karma-mocha": "^2.0.1", - "karma-mocha-reporter": "^2.2.5", - "karma-source-map-support": "~1.4.0", - "karma-sourcemap-loader": "^0.3.8", - "mocha": "^10.0.0", - "nyc": "^17.0.0", - "source-map-support": "^0.5.9", - "ts-node": "^10.0.0", - "typescript": "~5.6.2" + "playwright": "^1.49.0", + "typescript": "~5.6.2", + "vitest": "^2.1.5" }, "//metadata": { "constantPaths": [ @@ -117,5 +102,43 @@ "prefix": "userAgentInfo" } ] + }, + "type": "module", + "tshy": { + "exports": { + "./package.json": "./package.json", + ".": "./src/index.ts" + }, + "dialects": [ + "esm", + "commonjs" + ], + "esmDialects": [ + "browser", + "react-native" + ], + "selfLink": false + }, + "browser": "./dist/browser/index.js", + "exports": { + "./package.json": "./package.json", + ".": { + "browser": { + "types": "./dist/browser/index.d.ts", + "default": "./dist/browser/index.js" + }, + "react-native": { + "types": "./dist/react-native/index.d.ts", + "default": "./dist/react-native/index.js" + }, + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/commonjs/index.js" + } + } } } diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts index 25bf03b92b0e..fb3895b6a8fc 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentence.ts @@ -4,20 +4,15 @@ /** * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Get Sentence Boundaries sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts index 9489d2b0cca9..edcf6419ab10 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/breakSentenceWithAutoDetection.ts @@ -4,20 +4,15 @@ /** * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get sentences' boundaries. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Sentence Boundaries with auto-detection sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts index 6915fa3eadf6..0db913ef279f 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryExamples.ts @@ -4,20 +4,18 @@ /** * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get grammatical structure and context examples for the source term and target term pair. */ -import TextTranslationClient, { +import type { TranslatorCredential, DictionaryExampleTextItem, - isUnexpected, } from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Dictionary Examples sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts index 744810e487fb..7f654885f4e3 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/dictionaryLookup.ts @@ -4,20 +4,15 @@ /** * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get equivalent words for the source term in the target language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Dictionary Lookup sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts index 78f67211e3c3..e1293af14472 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguages.ts @@ -5,13 +5,11 @@ * @summary This sample demonstrates how to make a simple call to the Azure Text Translator service to get a list of supported languages */ import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -export async function main() { +export async function main(): Promise { console.log("== List supported languages sample =="); const translationClient = TextTranslationClient(endpoint); diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts index 0b2ce50e715b..3c091c57b800 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesAcceptLanguage.ts @@ -12,17 +12,13 @@ * Names are provided in the English language when a target language is not specified * or when localization is not available. */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { GetSupportedLanguagesParameters } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -export async function main() { +export async function main(): Promise { console.log("== List supported localized languages sample =="); const parameters: GetSupportedLanguagesParameters = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts index adedf0e2895d..710c1a0b531b 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/getLanguagesScope.ts @@ -5,17 +5,13 @@ * @summary This sample demonstrates how to make a simple call to the Azure Text Translator * service to get a list of supported languages for a selected scope */ -import TextTranslationClient, { - GetSupportedLanguagesParameters, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { GetSupportedLanguagesParameters } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; -export async function main() { +export async function main(): Promise { console.log("== Scoped list supported languages sample =="); const parameters: GetSupportedLanguagesParameters = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts index 2435f494285e..8abc7fc4b598 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translate.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how to make a simple call to the Azure Text Translator * service to get translation for a text which language is know to a target language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Simple translate sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts index 9baf6597850e..5f549e5657eb 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateAlignments.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how you can ask translation service to include alignment * projection from source text to translated text. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Translation with alignments sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts index 83159f47a366..714de1f653c1 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateCustom.ts @@ -17,20 +17,15 @@ * category, the request will return a 400 status code. `allowFallback=true` specifies that * the service is allowed to fall back to a general system when a custom system doesn't exist. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Custom translator sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts index cf5c1a188366..c6be9ef2b27d 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateDetection.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how to make a simple call to the Azure Text Translator * service to get translation without specifying the source language to a target language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Translate sample with auto-detection =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts index 23eb715449dc..cf7b3c9b3ec6 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateDictionary.ts @@ -8,21 +8,19 @@ * * Note You must include the From parameter in your API translation request instead of using the autodetect feature. */ -import TextTranslationClient, { +import type { TranslatorCredential, InputTextItem, TranslatedTextItemOutput, - isUnexpected, } from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Translation with Dictionary sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts index ffb5a49f6f7e..6305dae2fca3 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleSources.ts @@ -6,20 +6,15 @@ * service to get translation for a multiple text fields and each input text * is in different language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Multiple input texts =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts index 20c00ed4e0ee..fc82dbe6c940 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateMultipleTargets.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how you can provide multiple target languages which results * to each input element be translated to all target languages. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Multiple target languages translation =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts index d505a78ba34d..dc9700b24135 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateNoTranslate.ts @@ -7,20 +7,15 @@ * in its original language. In the following example, the content inside the first div * element won't be translated, while the content in the second div element will be translated. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Marking text input with notranslate div sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts index aa126e6baf74..a21a1d5a74da 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateProfanity.ts @@ -15,20 +15,15 @@ * or you want no action taken. The accepted values of `ProfanityAction` are `Deleted`, `Marked` * and `NoAction` (default). */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Profanity handling sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts index 972f4358725a..7ed01185a5d2 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateSenteceLength.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how to you can ask translator service to include sentence boundaries * for the input text and the translated text. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Translation with sentence boundaries sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts index 51609a958959..34b78f1cb89c 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateTextType.ts @@ -5,20 +5,15 @@ * @summary This sample demonstrates how you can select whether the translated text is plain text or HTML text. * Any HTML needs to be a well-formed, complete element. Possible values are: plain (default) or html. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== HTML translation sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts b/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts index c3f0471edec4..2ec383d80ef2 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/translateWithTransliteration.ts @@ -6,20 +6,15 @@ * Your source Text can be in non-standard Script of a language as well as you * can ask for non-standard Script of a target language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Translate with transliteration sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts b/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts index 555211ce1ed0..6cf635cb781f 100644 --- a/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts +++ b/sdk/translation/ai-translation-text-rest/samples-dev/transliterate.ts @@ -6,20 +6,15 @@ * service to convert characters or letters of a source language to the corresponding * characters or letters of a target language. */ -import TextTranslationClient, { - TranslatorCredential, - InputTextItem, - isUnexpected, -} from "@azure-rest/ai-translation-text"; - -import * as dotenv from "dotenv"; -dotenv.config(); +import type { TranslatorCredential, InputTextItem } from "@azure-rest/ai-translation-text"; +import TextTranslationClient, { isUnexpected } from "@azure-rest/ai-translation-text"; +import "dotenv/config"; const endpoint = process.env["ENDPOINT"] || "https://api.cognitive.microsofttranslator.com"; const apiKey = process.env["TEXT_TRANSLATOR_API_KEY"] || ""; const region = process.env["TEXT_TRANSLATOR_REGION"] || ""; -export async function main() { +export async function main(): Promise { console.log("== Simple transliterate sample =="); const translateCedential: TranslatorCredential = { diff --git a/sdk/translation/ai-translation-text-rest/src/customClient.ts b/sdk/translation/ai-translation-text-rest/src/customClient.ts index 62522b421709..fa1db50f5561 100644 --- a/sdk/translation/ai-translation-text-rest/src/customClient.ts +++ b/sdk/translation/ai-translation-text-rest/src/customClient.ts @@ -3,16 +3,16 @@ import type { ClientOptions } from "@azure-rest/core-client"; import { getClient } from "@azure-rest/core-client"; -import { logger } from "./generated/logger"; +import { logger } from "./generated/logger.js"; import * as coreRestPipeline from "@azure/core-rest-pipeline"; -import type { TextTranslationClient } from "./generated/clientDefinitions"; -import type { TranslatorCredential, TranslatorTokenCredential } from "./authentication"; +import type { TextTranslationClient } from "./generated/clientDefinitions.js"; +import type { TranslatorCredential, TranslatorTokenCredential } from "./authentication.js"; import { DEFAULT_SCOPE, TranslatorAuthenticationPolicy, TranslatorAzureKeyAuthenticationPolicy, TranslatorTokenCredentialAuthenticationPolicy, -} from "./authentication"; +} from "./authentication.js"; import type { AzureKeyCredential, KeyCredential, TokenCredential } from "@azure/core-auth"; const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com"; @@ -49,9 +49,9 @@ function isCredentials(credential: any): boolean { /** * Initialize a new instance of `TextTranslationClient` - * @param credential type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials + * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials * used to authenticate the service with. - * @param options type: ClientOptions, the parameter for all optional parameters + * @param options - type: ClientOptions, the parameter for all optional parameters */ export default function createClient( credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, @@ -60,9 +60,9 @@ export default function createClient( /** * Initialize a new instance of `TextTranslationClient` - * @param endpoint type: string, Supported Text Translation endpoints (protocol and hostname, for example: + * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example: * https://api.cognitive.microsofttranslator.com). - * @param options type: ClientOptions, the parameter for all optional parameters + * @param options - type: ClientOptions, the parameter for all optional parameters */ export default function createClient( endpoint: string, @@ -71,11 +71,11 @@ export default function createClient( /** * Initialize a new instance of `TextTranslationClient` - * @param endpoint type: string, Supported Text Translation endpoints (protocol and hostname, for example: + * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example: * https://api.cognitive.microsofttranslator.com). - * @param credential type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials + * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials * used to authenticate the service with. - * @param options type: ClientOptions, the parameter for all optional parameters + * @param options - type: ClientOptions, the parameter for all optional parameters */ export default function createClient( endpoint: string, diff --git a/sdk/translation/ai-translation-text-rest/src/index.ts b/sdk/translation/ai-translation-text-rest/src/index.ts index 668e25ec2b7d..3a414add33d4 100644 --- a/sdk/translation/ai-translation-text-rest/src/index.ts +++ b/sdk/translation/ai-translation-text-rest/src/index.ts @@ -1,16 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import TextTranslationClient from "./customClient"; +import TextTranslationClient from "./customClient.js"; -export * from "./customClient"; -export * from "./generated/parameters"; -export * from "./generated/responses"; -export * from "./generated/clientDefinitions"; -export * from "./generated/isUnexpected"; -export * from "./generated/models"; -export * from "./generated/outputModels"; -export * from "./generated/serializeHelper"; -export { TranslatorCredential, TranslatorTokenCredential } from "./authentication"; +export * from "./customClient.js"; +export * from "./generated/parameters.js"; +export * from "./generated/responses.js"; +export * from "./generated/clientDefinitions.js"; +export * from "./generated/isUnexpected.js"; +export * from "./generated/models.js"; +export * from "./generated/outputModels.js"; +export * from "./generated/serializeHelper.js"; +export { TranslatorCredential, TranslatorTokenCredential } from "./authentication.js"; +// eslint-disable-next-line @azure/azure-sdk/ts-modules-only-named export default TextTranslationClient; diff --git a/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts index be5bd29a27d1..261377ed02df 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/breakSentenceTest.spec.ts @@ -2,22 +2,21 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import type { Context } from "mocha"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; +import { createTranslationClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("BreakSentence tests", () => { let recorder: Recorder; let client: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts index e644a7f4dd15..9455dc0b8cce 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/dictionaryExamplesTest.spec.ts @@ -2,22 +2,21 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import type { Context } from "mocha"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; +import { createTranslationClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("DictionaryExamples tests", () => { let recorder: Recorder; let client: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts index 11dcf377ba2c..356915c161e6 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/dictionaryLookupTest.spec.ts @@ -2,22 +2,21 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import type { Context } from "mocha"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; +import { createTranslationClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("DictionaryLookup tests", () => { let recorder: Recorder; let client: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts index 6a24cd096658..38ef61ce1484 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/getLanguagesTest.spec.ts @@ -2,22 +2,21 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import type { Context } from "mocha"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; +import { createTranslationClient, startRecorder } from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("GetLanguages tests", () => { let recorder: Recorder; let client: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts index d57985fb46de..71c5e421ad56 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/translateTest.spec.ts @@ -2,30 +2,29 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; import { createCustomTranslationClient, createTranslationClient, createTokenTranslationClient, createAADAuthenticationTranslationClient, startRecorder, -} from "./utils/recordedClient"; -import type { Context } from "mocha"; +} from "./utils/recordedClient.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("Translate tests", () => { let recorder: Recorder; let client: TextTranslationClient; let customClient: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); customClient = await createCustomTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts b/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts index 2fef24892a57..f1eef77f5e1a 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/transliterateTest.spec.ts @@ -2,23 +2,22 @@ // Licensed under the MIT License. import type { Recorder } from "@azure-tools/test-recorder"; -import { assert } from "chai"; -import type { TextTranslationClient } from "../../src"; -import { isUnexpected } from "../../src"; -import { createTranslationClient, startRecorder } from "./utils/recordedClient"; -import type { Context } from "mocha"; -import { editDistance } from "./utils/testHelper"; +import type { TextTranslationClient } from "../../src/index.js"; +import { isUnexpected } from "../../src/index.js"; +import { createTranslationClient, startRecorder } from "./utils/recordedClient.js"; +import { editDistance } from "./utils/testHelper.js"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("Transliterate tests", () => { let recorder: Recorder; let client: TextTranslationClient; - beforeEach(async function (this: Context) { - recorder = await startRecorder(this); + beforeEach(async (ctx) => { + recorder = await startRecorder(ctx); client = await createTranslationClient({ recorder }); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); diff --git a/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts b/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts index 60664ffa55de..e3ce3eb5fb48 100644 --- a/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts +++ b/sdk/translation/ai-translation-text-rest/test/public/utils/recordedClient.ts @@ -1,16 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { Context } from "mocha"; -import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder"; import { Recorder, isPlaybackMode, assertEnvironmentVariable } from "@azure-tools/test-recorder"; -import { StaticAccessTokenCredential } from "./StaticAccessTokenCredential"; +import { StaticAccessTokenCredential } from "./StaticAccessTokenCredential.js"; import type { TranslatorCredential, TranslatorTokenCredential, TextTranslationClient, -} from "../../../src"; -import createTextTranslationClient from "../../../src"; +} from "../../../src/index.js"; +import createTextTranslationClient from "../../../src/index.js"; import type { ClientOptions } from "@azure-rest/core-client"; import { createDefaultHttpClient, createPipelineRequest } from "@azure/core-rest-pipeline"; import type { TokenCredential } from "@azure/core-auth"; @@ -29,8 +28,8 @@ const recorderEnvSetup: RecorderStartOptions = { envSetupForPlayback, }; -export async function startRecorder(context: Context): Promise { - const recorder = new Recorder(context.currentTest); +export async function startRecorder(context: TestInfo): Promise { + const recorder = new Recorder(context); await recorder.start(recorderEnvSetup); return recorder; } diff --git a/sdk/translation/ai-translation-text-rest/tsconfig.browser.config.json b/sdk/translation/ai-translation-text-rest/tsconfig.browser.config.json new file mode 100644 index 000000000000..f772e6eb3b76 --- /dev/null +++ b/sdk/translation/ai-translation-text-rest/tsconfig.browser.config.json @@ -0,0 +1,10 @@ +{ + "extends": "./.tshy/build.json", + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts"], + "compilerOptions": { + "outDir": "./dist-test/browser", + "rootDir": ".", + "skipLibCheck": true + } +} diff --git a/sdk/translation/ai-translation-text-rest/tsconfig.json b/sdk/translation/ai-translation-text-rest/tsconfig.json index ae41228e0bda..1280d8197838 100644 --- a/sdk/translation/ai-translation-text-rest/tsconfig.json +++ b/sdk/translation/ai-translation-text-rest/tsconfig.json @@ -1,11 +1,12 @@ { "extends": "../../../tsconfig", "compilerOptions": { - "outDir": "./dist-esm", - "declarationDir": "./types", "paths": { "@azure-rest/ai-translation-text": ["./src/index"] - } + }, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "rootDir": "." }, - "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] + "include": ["src/**/*.ts", "src/**/*.mts", "src/**/*.cts", "samples-dev/**/*.ts", "test/**/*.ts"] } diff --git a/sdk/translation/ai-translation-text-rest/vitest.browser.config.ts b/sdk/translation/ai-translation-text-rest/vitest.browser.config.ts new file mode 100644 index 000000000000..50ec2d5489b0 --- /dev/null +++ b/sdk/translation/ai-translation-text-rest/vitest.browser.config.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.browser.shared.config.ts"; + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["dist-test/browser/test/**/*.spec.js"], + hookTimeout: 5000000, + testTimeout: 5000000, + }, + }), +); diff --git a/sdk/translation/ai-translation-text-rest/vitest.config.ts b/sdk/translation/ai-translation-text-rest/vitest.config.ts new file mode 100644 index 000000000000..d01fdec8ac69 --- /dev/null +++ b/sdk/translation/ai-translation-text-rest/vitest.config.ts @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "../../../vitest.shared.config.ts"; + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ["test/**/*.spec.ts"], + hookTimeout: 5000000, + testTimeout: 5000000, + }, + }), +);