[communication] Migrate @azure/communication-email to ESM/vitest (#31770)
### Packages impacted by this PR - @azure/communication-email ### Issues associated with this PR - https://github.com/Azure/azure-sdk-for-js/issues/31338 ### Describe the problem that is addressed by this PR Migrates the @azure/communication-email package to ESM/vitest. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
This commit is contained in:
Родитель
6b0ec887ea
Коммит
35680de9a6
|
@ -19061,7 +19061,7 @@ packages:
|
|||
dev: false
|
||||
|
||||
file:projects/communication-email.tgz:
|
||||
resolution: {integrity: sha512-ZOPSfMCI6uWwWm9OUsw6AHSJzn7SAMKxJOFFDbrj1jkvcQ9f1V+m2qa1NwV7FywuGMuKjN7wumpI284OIjxSxg==, tarball: file:projects/communication-email.tgz}
|
||||
resolution: {integrity: sha512-QhLsLLokYOq6xNcg5alwSd7zmjUr5iul+3/p1yq7jzXk2vDsxGU32Wq5S1ALu5jX+eTLPpxjm8WPdCFc37UtIg==, tarball: file:projects/communication-email.tgz}
|
||||
name: '@rush-temp/communication-email'
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
|
@ -19070,6 +19070,8 @@ packages:
|
|||
'@types/chai': 4.3.20
|
||||
'@types/mocha': 10.0.9
|
||||
'@types/node': 18.19.64
|
||||
'@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
|
||||
|
@ -19086,17 +19088,31 @@ packages:
|
|||
karma-sourcemap-loader: 0.3.8
|
||||
mocha: 10.8.2
|
||||
nyc: 17.1.0
|
||||
playwright: 1.48.2
|
||||
ts-node: 10.9.2(@types/node@18.19.64)(typescript@5.6.3)
|
||||
tslib: 1.14.1
|
||||
tslib: 2.8.1
|
||||
typescript: 5.6.3
|
||||
vitest: 2.1.5(@types/node@18.19.64)(@vitest/browser@2.1.5)
|
||||
transitivePeerDependencies:
|
||||
- '@swc/core'
|
||||
- '@swc/wasm'
|
||||
- '@edge-runtime/vm'
|
||||
- '@vitest/ui'
|
||||
- bufferutil
|
||||
- debug
|
||||
- happy-dom
|
||||
- jiti
|
||||
- jsdom
|
||||
- less
|
||||
- lightningcss
|
||||
- msw
|
||||
- safaridriver
|
||||
- sass
|
||||
- sass-embedded
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
- utf-8-validate
|
||||
- vite
|
||||
- webdriverio
|
||||
dev: false
|
||||
|
||||
file:projects/communication-identity.tgz:
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
@ -12,7 +12,7 @@
|
|||
"dtsRollup": {
|
||||
"enabled": true,
|
||||
"untrimmedFilePath": "",
|
||||
"publicTrimmedFilePath": "./types/communication-email.d.ts"
|
||||
"publicTrimmedFilePath": "dist/communication-email.d.ts"
|
||||
},
|
||||
"messages": {
|
||||
"tsdocMessageReporting": {
|
||||
|
|
|
@ -1,126 +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: [
|
||||
"COMMUNICATION_CONNECTION_STRING_EMAIL",
|
||||
"RECIPIENT_ADDRESS",
|
||||
"SENDER_ADDRESS",
|
||||
"TEST_MODE",
|
||||
"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 <properties> 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", "--disable-web-security"],
|
||||
},
|
||||
},
|
||||
|
||||
// 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",
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
|
@ -5,22 +5,22 @@
|
|||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"sdk-type": "client",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist-esm/src/index.js",
|
||||
"types": "types/communication-email.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 --browser-test=false && dev-tool run extract-api",
|
||||
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
|
||||
"build:samples": "dev-tool samples publish -f",
|
||||
"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 src test",
|
||||
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
|
||||
"pack": "npm pack 2>&1",
|
||||
|
@ -28,14 +28,12 @@
|
|||
"test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser",
|
||||
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-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"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"dist-esm/",
|
||||
"types/communication-email.d.ts",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
|
@ -47,41 +45,28 @@
|
|||
"email"
|
||||
],
|
||||
"dependencies": {
|
||||
"@azure/communication-common": "^2.2.0",
|
||||
"@azure/core-auth": "^1.3.0",
|
||||
"@azure/core-client": "^1.3.2",
|
||||
"@azure/communication-common": "^2.3.1",
|
||||
"@azure/core-auth": "^1.9.0",
|
||||
"@azure/core-client": "^1.9.2",
|
||||
"@azure/core-lro": "^2.5.0",
|
||||
"@azure/core-rest-pipeline": "^1.8.0",
|
||||
"@azure/core-util": "^1.6.1",
|
||||
"@azure/logger": "^1.0.0",
|
||||
"tslib": "^1.9.3"
|
||||
"@azure/core-rest-pipeline": "^1.18.0",
|
||||
"@azure/core-util": "^1.11.0",
|
||||
"@azure/logger": "^1.1.4",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@azure-tools/test-recorder": "^3.0.0",
|
||||
"@azure-tools/test-utils": "^1.0.1",
|
||||
"@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",
|
||||
"@types/chai": "^4.1.6",
|
||||
"@types/mocha": "^10.0.0",
|
||||
"@types/node": "^18.0.0",
|
||||
"chai": "^4.2.0",
|
||||
"@vitest/browser": "^2.1.5",
|
||||
"@vitest/coverage-istanbul": "^2.1.5",
|
||||
"dotenv": "^16.0.0",
|
||||
"eslint": "^9.9.0",
|
||||
"karma": "^6.2.0",
|
||||
"karma-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",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "~5.6.2"
|
||||
"playwright": "^1.48.2",
|
||||
"typescript": "~5.6.2",
|
||||
"vitest": "^2.1.5"
|
||||
},
|
||||
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-email/",
|
||||
"bugs": {
|
||||
|
@ -103,5 +88,43 @@
|
|||
"Azure Communication Services Resource": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource",
|
||||
"Email Communication Services Resource": "https://aka.ms/acsemail/createemailresource"
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { EmailClientOptions, EmailMessage, EmailSendOptionalParams } from "./models";
|
||||
import type { EmailClientOptions, EmailMessage, EmailSendOptionalParams } from "./models.js";
|
||||
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
|
||||
import { isTokenCredential } from "@azure/core-auth";
|
||||
import type { PollerLike, PollOperationState } from "@azure/core-lro";
|
||||
|
@ -10,10 +10,10 @@ import {
|
|||
isKeyCredential,
|
||||
parseClientArguments,
|
||||
} from "@azure/communication-common";
|
||||
import { EmailRestApiClient } from "./generated/src/emailRestApiClient";
|
||||
import { EmailRestApiClient } from "./generated/src/emailRestApiClient.js";
|
||||
import type { InternalPipelineOptions } from "@azure/core-rest-pipeline";
|
||||
import { logger } from "./logger";
|
||||
import type { EmailSendResponse } from "./generated/src";
|
||||
import { logger } from "./logger.js";
|
||||
import type { EmailSendResponse } from "./generated/src/index.js";
|
||||
|
||||
/**
|
||||
* Checks whether the type of a value is EmailClientOptions or not.
|
||||
|
|
|
@ -12,9 +12,9 @@ import {
|
|||
PipelineResponse,
|
||||
SendRequest
|
||||
} from "@azure/core-rest-pipeline";
|
||||
import { EmailImpl } from "./operations";
|
||||
import { Email } from "./operationsInterfaces";
|
||||
import { EmailRestApiClientOptionalParams } from "./models";
|
||||
import { EmailImpl } from "./operations/index.js";
|
||||
import { Email } from "./operationsInterfaces/index.js";
|
||||
import { EmailRestApiClientOptionalParams } from "./models/index.js";
|
||||
|
||||
export class EmailRestApiClient extends coreClient.ServiceClient {
|
||||
endpoint: string;
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
export * from "./models";
|
||||
export { EmailRestApiClient } from "./emailRestApiClient";
|
||||
export * from "./operationsInterfaces";
|
||||
export * from "./models/index.js";
|
||||
export { EmailRestApiClient } from "./emailRestApiClient.js";
|
||||
export * from "./operationsInterfaces/index.js";
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
OperationURLParameter,
|
||||
OperationQueryParameter
|
||||
} from "@azure/core-client";
|
||||
import { EmailMessage as EmailMessageMapper } from "../models/mappers";
|
||||
import { EmailMessage as EmailMessageMapper } from "../models/mappers.js";
|
||||
|
||||
export const accept: OperationParameter = {
|
||||
parameterPath: "accept",
|
||||
|
|
|
@ -6,20 +6,20 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
import { Email } from "../operationsInterfaces";
|
||||
import { Email } from "../operationsInterfaces/index.js";
|
||||
import * as coreClient from "@azure/core-client";
|
||||
import * as Mappers from "../models/mappers";
|
||||
import * as Parameters from "../models/parameters";
|
||||
import { EmailRestApiClient } from "../emailRestApiClient";
|
||||
import * as Mappers from "../models/mappers.js";
|
||||
import * as Parameters from "../models/parameters.js";
|
||||
import { EmailRestApiClient } from "../emailRestApiClient.js";
|
||||
import { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro";
|
||||
import { LroImpl } from "../lroImpl";
|
||||
import { LroImpl } from "../lroImpl.js";
|
||||
import {
|
||||
EmailGetSendResultOptionalParams,
|
||||
EmailGetSendResultResponse,
|
||||
EmailMessage,
|
||||
EmailSendOptionalParams,
|
||||
EmailSendResponse
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Class containing Email operations. */
|
||||
export class EmailImpl implements Email {
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
export * from "./email";
|
||||
export * from "./email.js";
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
EmailMessage,
|
||||
EmailSendOptionalParams,
|
||||
EmailSendResponse
|
||||
} from "../models";
|
||||
} from "../models/index.js";
|
||||
|
||||
/** Interface representing a Email. */
|
||||
export interface Email {
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
||||
*/
|
||||
|
||||
export * from "./email";
|
||||
export * from "./email.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
export * from "./emailClient";
|
||||
export * from "./models";
|
||||
export * from "./emailClient.js";
|
||||
export * from "./models.js";
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT License.
|
||||
|
||||
import type { CommonClientOptions, OperationOptions } from "@azure/core-client";
|
||||
import type { EmailRecipients, EmailAttachment, EmailAddress } from "./models";
|
||||
import type { EmailRecipients, EmailAttachment, EmailAddress } from "./models.js";
|
||||
|
||||
/**
|
||||
* Client options used to configure Email Client API requests.
|
||||
|
@ -71,4 +71,4 @@ export {
|
|||
ErrorDetail,
|
||||
ErrorAdditionalInfo,
|
||||
KnownEmailSendStatus,
|
||||
} from "./generated/src/models";
|
||||
} from "./generated/src/models/index.js";
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { EmailClient, EmailMessage } from "../../src";
|
||||
import { KnownEmailSendStatus } from "../../src";
|
||||
import type { EmailClient, EmailMessage } from "../../src/index.js";
|
||||
import { KnownEmailSendStatus } from "../../src/index.js";
|
||||
import type { Recorder } from "@azure-tools/test-recorder";
|
||||
import { env } from "@azure-tools/test-recorder";
|
||||
import type { Context } from "mocha";
|
||||
import { assert } from "chai";
|
||||
import { createRecordedEmailClientWithConnectionString } from "./utils/recordedClient";
|
||||
import { createRecordedEmailClientWithConnectionString } from "./utils/recordedClient.js";
|
||||
import { describe, it, assert, beforeEach, afterEach } from "vitest";
|
||||
|
||||
describe(`EmailClient [Playback/Live]`, function () {
|
||||
describe(`EmailClient [Playback/Live]`, () => {
|
||||
let recorder: Recorder;
|
||||
let client: EmailClient;
|
||||
|
||||
beforeEach(async function (this: Context) {
|
||||
({ client, recorder } = await createRecordedEmailClientWithConnectionString(this));
|
||||
beforeEach(async (ctx) => {
|
||||
({ client, recorder } = await createRecordedEmailClientWithConnectionString(ctx));
|
||||
});
|
||||
|
||||
afterEach(async function (this: Context) {
|
||||
if (!this.currentTest?.isPending()) {
|
||||
afterEach(async (ctx) => {
|
||||
if (!ctx.task.pending) {
|
||||
await recorder.stop();
|
||||
}
|
||||
});
|
||||
|
||||
it("successfully sends an email to a single recipient", async function () {
|
||||
it("successfully sends an email to a single recipient", { timeout: 120000 }, async () => {
|
||||
const emailMessage: EmailMessage = {
|
||||
senderAddress: env.SENDER_ADDRESS || "",
|
||||
recipients: {
|
||||
|
@ -45,49 +44,53 @@ describe(`EmailClient [Playback/Live]`, function () {
|
|||
const response = await poller.pollUntilDone();
|
||||
|
||||
assert.isTrue(response.status === KnownEmailSendStatus.Succeeded);
|
||||
}).timeout(120000);
|
||||
});
|
||||
|
||||
it("successfully sends an email to multiple types of recipients", async function () {
|
||||
const emailMessage: EmailMessage = {
|
||||
senderAddress: env.SENDER_ADDRESS ?? "",
|
||||
recipients: {
|
||||
to: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
cc: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
bcc: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
},
|
||||
content: {
|
||||
subject: "someSubject",
|
||||
plainText: "somePlainTextBody",
|
||||
html: "<html><h1>someHtmlBody</html>",
|
||||
},
|
||||
};
|
||||
it(
|
||||
"successfully sends an email to multiple types of recipients",
|
||||
{ timeout: 120000 },
|
||||
async () => {
|
||||
const emailMessage: EmailMessage = {
|
||||
senderAddress: env.SENDER_ADDRESS ?? "",
|
||||
recipients: {
|
||||
to: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
cc: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
bcc: [
|
||||
{
|
||||
address: env.RECIPIENT_ADDRESS ?? "",
|
||||
displayName: "someRecipient",
|
||||
},
|
||||
],
|
||||
},
|
||||
content: {
|
||||
subject: "someSubject",
|
||||
plainText: "somePlainTextBody",
|
||||
html: "<html><h1>someHtmlBody</html>",
|
||||
},
|
||||
};
|
||||
|
||||
const poller = await client.beginSend(emailMessage);
|
||||
const response = await poller.pollUntilDone();
|
||||
const poller = await client.beginSend(emailMessage);
|
||||
const response = await poller.pollUntilDone();
|
||||
|
||||
assert.isTrue(response.status === KnownEmailSendStatus.Succeeded);
|
||||
}).timeout(120000);
|
||||
assert.isTrue(response.status === KnownEmailSendStatus.Succeeded);
|
||||
},
|
||||
);
|
||||
|
||||
it("successfully sends an email with an attachment", async function () {
|
||||
it("successfully sends an email with an attachment", { timeout: 120000 }, async () => {
|
||||
const emailMessage: EmailMessage = {
|
||||
senderAddress: env.SENDER_ADDRESS ?? "",
|
||||
recipients: {
|
||||
|
@ -116,9 +119,9 @@ describe(`EmailClient [Playback/Live]`, function () {
|
|||
const response = await poller.pollUntilDone();
|
||||
|
||||
assert.isTrue(response.status === KnownEmailSendStatus.Succeeded);
|
||||
}).timeout(120000);
|
||||
});
|
||||
|
||||
it("successfully sends an email with an inline attachment", async function () {
|
||||
it("successfully sends an email with an inline attachment", { timeout: 120000 }, async () => {
|
||||
const emailMessage: EmailMessage = {
|
||||
senderAddress: env.SENDER_ADDRESS ?? "",
|
||||
recipients: {
|
||||
|
@ -148,5 +151,5 @@ describe(`EmailClient [Playback/Live]`, function () {
|
|||
const response = await poller.pollUntilDone();
|
||||
|
||||
assert.isTrue(response.status === KnownEmailSendStatus.Succeeded);
|
||||
}).timeout(120000);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import type { Context, Test } from "mocha";
|
||||
import type { SanitizerOptions } from "@azure-tools/test-recorder";
|
||||
import type { SanitizerOptions, TestInfo } from "@azure-tools/test-recorder";
|
||||
import { Recorder, env } from "@azure-tools/test-recorder";
|
||||
import { EmailClient } from "../../../src";
|
||||
import { EmailClient } from "../../../src/index.js";
|
||||
|
||||
export interface RecordedEmailClient {
|
||||
client: EmailClient;
|
||||
|
@ -47,7 +45,7 @@ const sanitizerOptions: SanitizerOptions = {
|
|||
],
|
||||
};
|
||||
|
||||
export async function createRecorder(context: Test | undefined): Promise<Recorder> {
|
||||
export async function createRecorder(context: TestInfo | undefined): Promise<Recorder> {
|
||||
const recorder = new Recorder(context);
|
||||
await recorder.start({ envSetupForPlayback });
|
||||
await recorder.addSanitizers(sanitizerOptions, ["record", "playback"]);
|
||||
|
@ -61,9 +59,9 @@ export async function createRecorder(context: Test | undefined): Promise<Recorde
|
|||
}
|
||||
|
||||
export async function createRecordedEmailClientWithConnectionString(
|
||||
context: Context,
|
||||
context: TestInfo,
|
||||
): Promise<RecordedEmailClient> {
|
||||
const recorder = await createRecorder(context.currentTest);
|
||||
const recorder = await createRecorder(context);
|
||||
|
||||
const client = new EmailClient(
|
||||
env.COMMUNICATION_CONNECTION_STRING_EMAIL ?? "",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"extends": "../../../tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-esm",
|
||||
"declarationDir": "./types",
|
||||
"paths": {
|
||||
"@azure/communication-email": ["./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"]
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}),
|
||||
);
|
|
@ -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,
|
||||
},
|
||||
}),
|
||||
);
|
Загрузка…
Ссылка в новой задаче