[communication] Migrate @azure/communication-job-router to ESM/vitest (#31748)

### Packages impacted by this PR

- @azure/communication-job-router 

### Issues associated with this PR

- https://github.com/Azure/azure-sdk-for-js/issues/31338

### Describe the problem that is addressed by this PR

Migrates @Azure/communication-job-router 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:
Matthew Podwysocki 2024-11-13 13:19:54 -05:00 коммит произвёл GitHub
Родитель ae84780ce1
Коммит 490ce4dfc5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
46 изменённых файлов: 492 добавлений и 545 удалений

Просмотреть файл

@ -18771,7 +18771,7 @@ packages:
dev: false
file:projects/communication-job-router-1.tgz:
resolution: {integrity: sha512-RZbsUhQkZUx5IKP0bXznxjTXhgPuBwPUEKVgusXlHstCp2/Qlo0Gj28SFhFxRIccGikPKPoTcLvspMSRJ/oQNg==, tarball: file:projects/communication-job-router-1.tgz}
resolution: {integrity: sha512-7NGs1l8E3JJ5oW9FXr+0jZnJyJkaCWcNqd/iA2rE1PqlEPv1bJ1GkPY+vh6cmDoZUSodOmWK4kn7Un4S5nsinw==, tarball: file:projects/communication-job-router-1.tgz}
name: '@rush-temp/communication-job-router-1'
version: 0.0.0
dependencies:
@ -18781,6 +18781,8 @@ packages:
'@types/node': 18.19.64
'@types/sinon': 17.0.3
'@types/uuid': 8.3.4
'@vitest/browser': 2.1.4(@types/node@18.19.64)(playwright@1.48.2)(typescript@5.6.3)(vitest@2.1.4)
'@vitest/coverage-istanbul': 2.1.4(vitest@2.1.4)
chai: 4.3.10
dotenv: 16.4.5
eslint: 9.14.0
@ -18799,20 +18801,34 @@ packages:
karma-sourcemap-loader: 0.3.8
mocha: 10.8.2
nyc: 17.1.0
playwright: 1.48.2
sinon: 17.0.1
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.4(@types/node@18.19.64)(@vitest/browser@2.1.4)
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-job-router.tgz:
@ -18898,7 +18914,7 @@ packages:
dev: false
file:projects/communication-phone-numbers.tgz:
resolution: {integrity: sha512-kRnm7dSlOcUN3BpxBqb6K3cAum4jdmmU4BdQ4o+BaHcS7s6yWImkZL4vKz0ELMgUSCSLu4w2FqV5XinSAg4eeA==, tarball: file:projects/communication-phone-numbers.tgz}
resolution: {integrity: sha512-24JG0UquvqCfpD2fHYVg31EE7Zu+1LadlqbxK1oIhPj3dnaQ152m8T++HHMAkFzfbNdaH/1yqWjLTpBVotKMXA==, tarball: file:projects/communication-phone-numbers.tgz}
name: '@rush-temp/communication-phone-numbers'
version: 0.0.0
dependencies:
@ -21182,7 +21198,7 @@ packages:
dev: false
file:projects/maps-render.tgz:
resolution: {integrity: sha512-DrEwi8UQP65AkDO5eQx9LbwzEGtngMa8+aoOuoEZ3XdfLM5te0RH2g1B2ugosRq7lbjmRpuex6xBKZE3tQw7Yw==, tarball: file:projects/maps-render.tgz}
resolution: {integrity: sha512-UsWhK4PLe8c4SueDX/MzVuOtEwAHCNrHYZHGSwEJ8nFvkT5qBQS0E6v0p87R+7dNE+2hUrXoXV2pYwTbM7NeMg==, tarball: file:projects/maps-render.tgz}
name: '@rush-temp/maps-render'
version: 0.0.0
dependencies:

Просмотреть файл

@ -1,10 +0,0 @@
{
"include": ["dist-esm/src/**/*.js"],
"exclude": ["**/*.d.ts", "dist-esm/src/generated/*"],
"reporter": ["text-summary", "html", "cobertura"],
"exclude-after-remap": false,
"sourceMap": true,
"produce-source-map": true,
"instrument": true,
"all": true
}

Просмотреть файл

@ -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-job-router.d.ts"
"publicTrimmedFilePath": "dist/communication-job-router.d.ts"
},
"messages": {
"tsdocMessageReporting": {

Просмотреть файл

@ -1,133 +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();
const { jsonRecordingFilterFunction, isRecordMode } = require("@azure-tools/test-recorder");
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",
"karma-json-to-file-reporter",
"karma-json-preprocessor",
],
// 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"],
"recordings/browsers/**/*.json": ["json"],
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
// Preprocess source file to calculate code coverage, however this will make source file unreadable
//"dist-test/index.browser.js": ["coverage"]
},
// inject following environment values into browser testing with window.__env__
// environment values MUST be exported or set with same console running "karma start"
// https://www.npmjs.com/package/karma-env-preprocessor
envPreprocessor: ["TEST_MODE", "COMMUNICATION_CONNECTION_STRING", "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", "json-to-file"],
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
},
jsonToFileReporter: {
filter: jsonRecordingFilterFunction,
outputPath: ".",
},
// 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,
browserConsoleLogOptions: {
terminal: !isRecordMode(),
},
client: {
mocha: {
// change Karma's debug.html to the mocha web reporter
reporter: "html",
timeout: "600000",
},
},
});
};

Просмотреть файл

@ -3,24 +3,24 @@
"version": "1.0.0-beta.2",
"description": "Azure client library for Azure Communication Job Router services",
"sdk-type": "client",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"types": "types/communication-job-router.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 --verbose",
"build": "npm run clean && dev-tool run build-package && dev-tool run extract-api",
"build:autorest": "autorest ./swagger/README.md && rushx format",
"build:browser": "tsc -p . && dev-tool run bundle && dev-tool run vendored cross-env ONLY_BROWSER=true ",
"build:node": "tsc -p . && dev-tool run bundle && dev-tool run vendored cross-env ONLY_NODE=true ",
"build:browser": "dev-tool run build-package && dev-tool run bundle && dev-tool run vendored cross-env ONLY_BROWSER=true ",
"build:node": "dev-tool run build-package && dev-tool run bundle && dev-tool run vendored cross-env ONLY_NODE=true ",
"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\" \"*.{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 --verbose",
"extract-api": "dev-tool run build-package && dev-tool run extract-api --verbose",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"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,21 +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-cpolicies:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/classificationPolicies.spec.ts'",
"unit-test-dpolicies:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/distributionPolicies.spec.ts'",
"unit-test-epolicies:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/exceptionPolicies.spec.ts'",
"unit-test-jobs:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/jobs.spec.ts'",
"unit-test-queues:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/queues.spec.ts'",
"unit-test-scenarios:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/scenarios/**.spec.ts'",
"unit-test-workers:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/workers.spec.ts'",
"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/src/",
"types/communication-job-router.d.ts",
"README.md",
"LICENSE"
],
@ -90,36 +81,60 @@
"uuid": "^8.3.0"
},
"devDependencies": {
"@azure-tools/test-recorder": "^3.0.0",
"@azure-tools/test-recorder": "^4.1.0",
"@azure-tools/test-utils-vitest": "^1.0.0",
"@azure/communication-identity": "^1.0.0",
"@azure/core-util": "^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",
"@types/sinon": "^17.0.0",
"@types/uuid": "^8.0.0",
"chai": "^4.2.0",
"@vitest/browser": "^2.1.4",
"@vitest/coverage-istanbul": "^2.1.4",
"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": "^17.0.0",
"ts-node": "^10.0.0",
"playwright": "^1.48.2",
"typescript": "~5.6.2",
"util": "^0.12.1"
"util": "^0.12.1",
"vitest": "^2.1.4"
},
"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"
}
}
}
}

Просмотреть файл

@ -11,7 +11,6 @@ import {
// Load the .env file (you will need to set these environment variables)
import * as dotenv from "dotenv";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -9,7 +9,6 @@ import {
DistributionPolicyItem,
JobRouterAdministrationClient,
} from "@azure/communication-job-router";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -10,7 +10,6 @@ import {
ExceptionPolicyItem,
JobRouterAdministrationClient,
} from "@azure/communication-job-router";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -7,7 +7,6 @@ import { RouterJobItem, JobRouterClient } from "@azure/communication-job-router"
// Load the .env file (you will need to set these environment variables)
import * as dotenv from "dotenv";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -7,7 +7,6 @@ import { RouterQueueItem, JobRouterAdministrationClient } from "@azure/communica
// Load the .env file (you will need to set these environment variables)
import * as dotenv from "dotenv";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -7,7 +7,6 @@ import { JobRouterClient, RouterWorkerItem } from "@azure/communication-job-rout
// Load the .env file (you will need to set these environment variables)
import * as dotenv from "dotenv";
import { assert } from "chai";
dotenv.config();
const connectionString = process.env["COMMUNICATION_CONNECTION_STRING"] || "";

Просмотреть файл

@ -7,7 +7,7 @@
*/
/// <reference lib="esnext.asynciterable" />
export { getContinuationToken } from "./pagingHelper";
export * from "./models";
export { JobRouterApiClient } from "./jobRouterApiClient";
export * from "./operationsInterfaces";
export { getContinuationToken } from "./pagingHelper.js";
export * from "./models/index.js";
export { JobRouterApiClient } from "./jobRouterApiClient.js";
export * from "./operationsInterfaces/index.js";

Просмотреть файл

@ -12,9 +12,9 @@ import {
PipelineResponse,
SendRequest
} from "@azure/core-rest-pipeline";
import { JobRouterAdministrationImpl, JobRouterImpl } from "./operations";
import { JobRouterAdministration, JobRouter } from "./operationsInterfaces";
import { JobRouterApiClientOptionalParams } from "./models";
import { JobRouterAdministrationImpl, JobRouterImpl } from "./operations/index.js";
import { JobRouterAdministration, JobRouter } from "./operationsInterfaces/index.js";
import { JobRouterApiClientOptionalParams } from "./models/index.js";
export class JobRouterApiClient extends coreClient.ServiceClient {
endpoint: string;

Просмотреть файл

@ -23,7 +23,7 @@ import {
UnassignJobRequest as UnassignJobRequestMapper,
DeclineJobOfferRequest as DeclineJobOfferRequestMapper,
RouterWorker as RouterWorkerMapper
} from "../models/mappers";
} from "../models/mappers.js";
export const contentType: OperationParameter = {
parameterPath: ["options", "contentType"],

Просмотреть файл

@ -6,5 +6,5 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
export * from "./jobRouterAdministration";
export * from "./jobRouter";
export * from "./jobRouterAdministration.js";
export * from "./jobRouter.js";

Просмотреть файл

@ -6,14 +6,14 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { tracingClient } from "../tracing";
import { tracingClient } from "../tracing.js";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { setContinuationToken } from "../pagingHelper";
import { JobRouter } from "../operationsInterfaces";
import { setContinuationToken } from "../pagingHelper.js";
import { JobRouter } from "../operationsInterfaces/index.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { JobRouterApiClient } from "../jobRouterApiClient";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
import { JobRouterApiClient } from "../jobRouterApiClient.js";
import {
RouterJobItem,
JobRouterListJobsNextOptionalParams,
@ -55,7 +55,7 @@ import {
JobRouterDeleteWorkerOptionalParams,
JobRouterListJobsNextResponse,
JobRouterListWorkersNextResponse
} from "../models";
} from "../models/index.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing JobRouter operations. */

Просмотреть файл

@ -6,14 +6,14 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { tracingClient } from "../tracing";
import { tracingClient } from "../tracing.js";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { setContinuationToken } from "../pagingHelper";
import { JobRouterAdministration } from "../operationsInterfaces";
import { setContinuationToken } from "../pagingHelper.js";
import { JobRouterAdministration } from "../operationsInterfaces/index.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { JobRouterApiClient } from "../jobRouterApiClient";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
import { JobRouterApiClient } from "../jobRouterApiClient.js";
import {
ClassificationPolicyItem,
JobRouterAdministrationListClassificationPoliciesNextOptionalParams,
@ -59,7 +59,7 @@ import {
JobRouterAdministrationListDistributionPoliciesNextResponse,
JobRouterAdministrationListExceptionPoliciesNextResponse,
JobRouterAdministrationListQueuesNextResponse
} from "../models";
} from "../models/index.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing JobRouterAdministration operations. */

Просмотреть файл

@ -6,5 +6,5 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
export * from "./jobRouterAdministration";
export * from "./jobRouter";
export * from "./jobRouterAdministration.js";
export * from "./jobRouter.js";

Просмотреть файл

@ -42,7 +42,7 @@ import {
JobRouterGetWorkerOptionalParams,
JobRouterGetWorkerResponse,
JobRouterDeleteWorkerOptionalParams
} from "../models";
} from "../models/index.js";
/// <reference lib="esnext.asynciterable" />
/** Interface representing a JobRouter. */

Просмотреть файл

@ -40,7 +40,7 @@ import {
JobRouterAdministrationGetQueueOptionalParams,
JobRouterAdministrationGetQueueResponse,
JobRouterAdministrationDeleteQueueOptionalParams
} from "../models";
} from "../models/index.js";
/// <reference lib="esnext.asynciterable" />
/** Interface representing a JobRouterAdministration. */

Просмотреть файл

@ -6,9 +6,9 @@
* JavaScript SDK for the Azure Communication Services Job Router Service.
*/
export * from "./models";
export * from "./options";
export * from "./responses";
export * from "./clientUtils";
export * from "./jobRouterClient";
export * from "./jobRouterAdministrationClient";
export * from "./models.js";
export * from "./options.js";
export * from "./responses.js";
export * from "./clientUtils.js";
export * from "./jobRouterClient.js";
export * from "./jobRouterAdministrationClient.js";

Просмотреть файл

@ -18,8 +18,8 @@ import type {
JobRouterAdministrationListDistributionPoliciesOptionalParams,
JobRouterAdministrationListExceptionPoliciesOptionalParams,
JobRouterAdministrationListQueuesOptionalParams,
} from "./generated/src";
import { JobRouterApiClient } from "./generated/src";
} from "./generated/src/index.js";
import { JobRouterApiClient } from "./generated/src/index.js";
import type {
ClassificationPolicyItem,
DistributionPolicyItem,
@ -29,7 +29,7 @@ import type {
ExceptionPolicy,
RouterQueue,
ClassificationPolicy,
} from "./models";
} from "./models.js";
import type {
CreateClassificationPolicyOptions,
CreateDistributionPolicyOptions,
@ -44,15 +44,15 @@ import type {
UpdateDistributionPolicyOptions,
UpdateExceptionPolicyOptions,
UpdateQueueOptions,
} from "./options";
} from "./options.js";
import type {
ClassificationPolicyResponse,
DistributionPolicyResponse,
ExceptionPolicyResponse,
RouterQueueResponse,
} from "./responses";
import { SDK_VERSION } from "./constants";
import { logger } from "./logger";
} from "./responses.js";
import { SDK_VERSION } from "./constants.js";
import { logger } from "./logger.js";
/**
* Checks whether a value is of type {@link JobRouterAdministrationClientOptions}.

Просмотреть файл

@ -12,7 +12,7 @@ import {
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
import type { OperationOptions } from "@azure/core-client";
import type { InternalPipelineOptions } from "@azure/core-rest-pipeline";
import { SDK_VERSION } from "./constants";
import { SDK_VERSION } from "./constants.js";
import type {
JobRouterListJobsOptionalParams,
JobRouterListWorkersOptionalParams,
@ -22,9 +22,9 @@ import type {
RouterJobItem as RouterJobItemGenerated,
RouterWorkerItem as RouterWorkerItemGenerated,
JobMatchingMode,
} from "./generated/src";
import { JobRouterApiClient, KnownJobMatchModeType } from "./generated/src";
import { logger } from "./logger";
} from "./generated/src/index.js";
import { JobRouterApiClient, KnownJobMatchModeType } from "./generated/src/index.js";
import { logger } from "./logger.js";
import type {
RouterJobItem,
RouterWorkerItem,
@ -33,7 +33,7 @@ import type {
RouterWorkerSelector,
RouterJobMatchingMode,
RouterWorkerState,
} from "./models";
} from "./models.js";
import type {
JobRouterClientOptions,
CreateJobOptions,
@ -48,7 +48,7 @@ import type {
CreateWorkerOptions,
UpdateWorkerOptions,
ListWorkersOptions,
} from "./options";
} from "./options.js";
import type {
RouterJobResponse,
CancelJobResponse,
@ -59,8 +59,8 @@ import type {
AcceptJobOfferResponse,
DeclineJobOfferResponse,
RouterWorkerResponse,
} from "./responses";
import { TransformingPagedAsyncIterableIterator } from "./clientUtils";
} from "./responses.js";
import { TransformingPagedAsyncIterableIterator } from "./clientUtils.js";
/**
* Checks whether a value is of type {@link JobRouterClientOptions}.

Просмотреть файл

@ -26,7 +26,7 @@ import type {
WorkerSelectorAttachment,
LongestIdleMode,
RoundRobinMode,
} from "./generated/src";
} from "./generated/src/index.js";
/** Safe type instead of 'any'. */
export type JSONValue = boolean | number | string | JSONArray | JSONObject;
@ -637,4 +637,4 @@ export {
RouterWorkerState,
RouterJobStatus,
LabelOperator,
} from "./generated/src";
} from "./generated/src/index.js";

Просмотреть файл

@ -13,7 +13,7 @@ import type {
JobRouterUpsertWorkerOptionalParams,
JobRouterUnassignJobActionOptionalParams,
ChannelConfiguration,
} from "./generated/src";
} from "./generated/src/index.js";
import type { CommonClientOptions, OperationOptions } from "@azure/core-client";
import type {
JSONObject,
@ -27,7 +27,7 @@ import type {
ExceptionRule,
RouterJobStatusSelector,
RouterWorkerStateSelector,
} from "./models";
} from "./models.js";
/**
* Options to create a job router administration client.
@ -391,4 +391,4 @@ export {
JobRouterUpsertWorkerOptionalParams,
DeclineJobOfferRequest,
UnassignJobRequest,
} from "./generated/src";
} from "./generated/src/index.js";

Просмотреть файл

@ -9,7 +9,7 @@ import type {
RouterJob,
RouterWorker,
JSONValue,
} from "./models";
} from "./models.js";
export interface RouterJobResponse extends RouterJob {
readonly id: string;
@ -68,4 +68,4 @@ export type DeclineJobOfferResponse = {
export {
AcceptJobOfferResult as AcceptJobOfferResponse,
UnassignJobResult as UnassignJobResponse,
} from "./generated/src";
} from "./generated/src/index.js";

Просмотреть файл

@ -1,17 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import sinon from "sinon";
import { AzureCommunicationTokenCredential } from "@azure/communication-common";
import { JobRouterClient } from "../../src";
import { baseUri, generateToken } from "../public/utils/connection";
import { JobRouterClient } from "../../src/index.js";
import { baseUri, generateToken } from "../public/utils/connection.js";
import { describe, it } from "vitest";
describe("[Mocked] JobRouterClient", async function () {
afterEach(function () {
sinon.restore();
});
it("can instantiate", async function () {
describe("[Mocked] JobRouterClient", async () => {
it("can instantiate", async () => {
new JobRouterClient(baseUri, new AzureCommunicationTokenCredential(generateToken()));
});
});

Просмотреть файл

@ -2,15 +2,17 @@
// Licensed under the MIT License.
import * as dotenv from "dotenv";
import type { Recorder } from "@azure-tools/test-recorder";
import type { Recorder, TestInfo } from "@azure-tools/test-recorder";
import { env } from "@azure-tools/test-recorder";
import { JobRouterAdministrationClient, JobRouterClient } from "../../../src";
import type { Context } from "mocha";
import { isNode } from "@azure/core-util";
import type { JobRouterAdministrationClientOptions, JobRouterClientOptions } from "../../../src";
import { createRecorder } from "./recordedClient";
import { JobRouterAdministrationClient, JobRouterClient } from "../../../src/index.js";
import { isNodeLike } from "@azure/core-util";
import type {
JobRouterAdministrationClientOptions,
JobRouterClientOptions,
} from "../../../src/index.js";
import { createRecorder } from "./recordedClient.js";
if (isNode) {
if (isNodeLike) {
dotenv.config();
}
@ -21,9 +23,9 @@ export interface RecordedRouterClient {
}
export async function createRecordedRouterClientWithConnectionString(
context: Context,
context: TestInfo,
): Promise<RecordedRouterClient> {
const recorder = await createRecorder(context.currentTest);
const recorder = await createRecorder(context);
return {
client: new JobRouterClient(

Просмотреть файл

@ -2,13 +2,12 @@
// Licensed under the MIT License.
import * as dotenv from "dotenv";
import { isNode } from "@azure/core-util";
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
import { isNodeLike } from "@azure/core-util";
import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
import { Recorder } from "@azure-tools/test-recorder";
import type { Test } from "mocha";
import { generateToken } from "../../public/utils/connection";
import { generateToken } from "../../public/utils/connection.js";
if (isNode) {
if (isNodeLike) {
dotenv.config();
}
@ -28,7 +27,7 @@ export const recorderOptions: RecorderStartOptions = {
],
};
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(recorderOptions);
await recorder.setMatcher("HeaderlessMatcher");

Просмотреть файл

@ -2,19 +2,18 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import { assert } from "chai";
import type { Context } from "mocha";
import type { ClassificationPolicy, JobRouterAdministrationClient } from "../../../src";
import type { ClassificationPolicy, JobRouterAdministrationClient } from "../../../src/index.js";
import {
getClassificationPolicyRequest,
getDistributionPolicyRequest,
getExceptionPolicyRequest,
getQueueRequest,
} from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { timeoutMs } from "../utils/constants";
} from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -27,10 +26,10 @@ describe("JobRouterClient", function () {
const { classificationPolicyId, classificationPolicyRequest } =
getClassificationPolicyRequest(testRunId);
describe("Classification Policy Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Classification Policy Operations", () => {
beforeEach(async (ctx) => {
({ administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -44,18 +43,18 @@ describe("JobRouterClient", function () {
);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await administrationClient.deleteClassificationPolicy(classificationPolicyId);
await administrationClient.deleteQueue(queueId);
await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
await administrationClient.deleteDistributionPolicy(distributionPolicyId);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create a classification policy", async function () {
it("should create a classification policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.createClassificationPolicy(
classificationPolicyId,
classificationPolicyRequest,
@ -64,16 +63,16 @@ describe("JobRouterClient", function () {
assert.isDefined(result);
assert.isDefined(result.id);
assert.equal(result.name, classificationPolicyRequest.name);
}).timeout(timeoutMs);
});
it("should get a classification policy", async function () {
it("should get a classification policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.getClassificationPolicy(classificationPolicyId);
assert.equal(result.id, classificationPolicyId);
assert.equal(result.name, classificationPolicyRequest.name);
}).timeout(timeoutMs);
});
it("should update a classification policy", async function () {
it("should update a classification policy", { timeout: timeoutMs }, async () => {
const updatePatch = { ...classificationPolicyRequest, name: "new name" };
const updateResult = await administrationClient.updateClassificationPolicy(
classificationPolicyId,
@ -92,9 +91,9 @@ describe("JobRouterClient", function () {
assert.isDefined(removeResult.id);
assert.equal(updatePatch.name, updateResult.name);
assert.isUndefined(removeResult.name);
}).timeout(timeoutMs);
});
it("should list classification policies", async function () {
it("should list classification policies", async () => {
const result: ClassificationPolicy[] = [];
for await (const policy of administrationClient.listClassificationPolicies({
maxPageSize: 20,
@ -103,12 +102,12 @@ describe("JobRouterClient", function () {
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should delete a classification policy", async function () {
it("should delete a classification policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.deleteClassificationPolicy(classificationPolicyId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -2,14 +2,13 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import { assert } from "chai";
import type { Context } from "mocha";
import type { DistributionPolicy, JobRouterAdministrationClient } from "../../../src";
import { getDistributionPolicyRequest } from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { timeoutMs } from "../utils/constants";
import type { DistributionPolicy, JobRouterAdministrationClient } from "../../../src/index.js";
import { getDistributionPolicyRequest } from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -18,19 +17,19 @@ describe("JobRouterClient", function () {
const { distributionPolicyId, distributionPolicyRequest } =
getDistributionPolicyRequest(testRunId);
describe("Distribution Policy Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Distribution Policy Operations", () => {
beforeEach(async (ctx) => {
({ administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
});
this.afterEach(async function (this: Context) {
if (!this.currentTest?.isPending() && recorder) {
afterEach(async (ctx) => {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create a distribution policy", async function () {
it("should create a distribution policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.createDistributionPolicy(
distributionPolicyId,
distributionPolicyRequest,
@ -39,9 +38,9 @@ describe("JobRouterClient", function () {
assert.isDefined(result);
assert.isDefined(result?.id);
assert.equal(result.name, distributionPolicyRequest.name);
}).timeout(timeoutMs);
});
it("should get a distribution policy", async function () {
it("should get a distribution policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.getDistributionPolicy(distributionPolicyId);
assert.equal(result.id, distributionPolicyId);
@ -51,9 +50,9 @@ describe("JobRouterClient", function () {
distributionPolicyRequest.offerExpiresAfterSeconds,
);
assert.deepEqual(result.mode, distributionPolicyRequest.mode);
}).timeout(timeoutMs);
});
it("should update a distribution policy", async function () {
it("should update a distribution policy", { timeout: timeoutMs }, async () => {
const updatePatch = { ...distributionPolicyRequest, name: "new-name" };
const updateResult = await administrationClient.updateDistributionPolicy(
distributionPolicyId,
@ -72,9 +71,9 @@ describe("JobRouterClient", function () {
assert.isDefined(removeResult.id);
assert.equal(updateResult.name, updatePatch.name);
assert.isUndefined(removeResult.name);
}).timeout(timeoutMs);
});
it("should list distribution policies", async function () {
it("should list distribution policies", { timeout: timeoutMs }, async () => {
const result: DistributionPolicy[] = [];
for await (const policy of administrationClient.listDistributionPolicies({
maxPageSize: 20,
@ -83,12 +82,12 @@ describe("JobRouterClient", function () {
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should delete a distribution policy", async function () {
it("should delete a distribution policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.deleteDistributionPolicy(distributionPolicyId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -2,14 +2,13 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import type { ExceptionPolicy, JobRouterAdministrationClient } from "../../../src";
import { assert } from "chai";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import type { Context } from "mocha";
import { getExceptionPolicyRequest } from "../utils/testData";
import { timeoutMs } from "../utils/constants";
import type { ExceptionPolicy, JobRouterAdministrationClient } from "../../../src/index.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { getExceptionPolicyRequest } from "../utils/testData.js";
import { timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -17,19 +16,19 @@ describe("JobRouterClient", function () {
const { exceptionPolicyId, exceptionPolicyRequest } = getExceptionPolicyRequest(testRunId);
describe("Exception Policy Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Exception Policy Operations", () => {
beforeEach(async (ctx) => {
({ administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
});
this.afterEach(async function (this: Context) {
if (!this.currentTest?.isPending() && recorder) {
afterEach(async (ctx) => {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create an exception policy", async function () {
it("should create an exception policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.createExceptionPolicy(
exceptionPolicyId,
exceptionPolicyRequest,
@ -38,17 +37,17 @@ describe("JobRouterClient", function () {
assert.isDefined(result);
assert.isDefined(result?.id);
assert.equal(result.name, exceptionPolicyRequest.name);
}).timeout(timeoutMs);
});
it("should get an exception policy", async function () {
it("should get an exception policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.getExceptionPolicy(exceptionPolicyId);
assert.equal(result.id, exceptionPolicyId);
assert.equal(result.name, exceptionPolicyRequest.name);
assert.deepEqual(result.exceptionRules, exceptionPolicyRequest.exceptionRules);
}).timeout(timeoutMs);
});
it("should update an exception policy", async function () {
it("should update an exception policy", { timeout: timeoutMs }, async () => {
const updatePatch = { ...exceptionPolicyRequest, name: "new-name" };
const updateResult = await administrationClient.updateExceptionPolicy(
exceptionPolicyId,
@ -67,21 +66,21 @@ describe("JobRouterClient", function () {
assert.isDefined(removeResult.id);
assert.equal(updateResult.name, updatePatch.name);
assert.isUndefined(removeResult.name);
}).timeout(timeoutMs);
});
it("should list exception policies", async function () {
it("should list exception policies", { timeout: timeoutMs }, async () => {
const result: ExceptionPolicy[] = [];
for await (const policy of administrationClient.listExceptionPolicies({ maxPageSize: 20 })) {
result.push(policy.exceptionPolicy!);
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should delete an exception policy", async function () {
it("should delete an exception policy", { timeout: timeoutMs }, async () => {
const result = await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -2,27 +2,38 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import { assert } from "chai";
import type {
CreateJobOptions,
JobRouterAdministrationClient,
JobRouterClient,
RouterJob,
UpdateJobOptions,
} from "../../../src";
import type { Context } from "mocha";
} from "../../../src/index.js";
import {
getClassificationPolicyRequest,
getDistributionPolicyRequest,
getExceptionPolicyRequest,
getJobRequest,
getQueueRequest,
} from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { sleep, timeoutMs } from "../utils/constants";
import { pollForJobQueued, retry } from "../utils/polling";
} from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { sleep, timeoutMs } from "../utils/constants.js";
import { pollForJobQueued, retry } from "../utils/polling.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import type { RunnerTestSuite, TaskContext } from "vitest";
describe("JobRouterClient", function () {
function getFullTitle(ctx: TaskContext): string {
function getTitlePath(suite: RunnerTestSuite | undefined): string[] {
if (suite) {
return [...getTitlePath(suite.suite), suite.name];
}
return [];
}
return [...getTitlePath(ctx.task.suite), ctx.task.name].join(" ");
}
describe("JobRouterClient", () => {
let client: JobRouterClient;
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -47,10 +58,10 @@ describe("JobRouterClient", function () {
};
}
describe("Job Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Job Operations", () => {
beforeEach(async (ctx) => {
({ client, administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -64,12 +75,10 @@ describe("JobRouterClient", function () {
);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await retry(
async () => {
if (
this.currentTest?.fullTitle() !== "JobRouterClient Job Operations should delete a job"
) {
if (getFullTitle(ctx) !== "JobRouterClient Job Operations should delete a job") {
const job = await client.getJob(jobId);
if (job.status !== "cancelled") {
await client.cancelJob(jobId);
@ -85,20 +94,20 @@ describe("JobRouterClient", function () {
{ retries: 5, retryIntervalMs: 1500 },
);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create a job", async function () {
it("should create a job", { timeout: timeoutMs }, async () => {
const result = await client.createJob(jobId, jobRequest);
assert.isDefined(result);
assert.isDefined(result.id);
assert.equal(result.id, jobId);
}).timeout(timeoutMs);
});
it("should create a scheduled job", async function () {
it("should create a scheduled job", { timeout: timeoutMs }, async () => {
const currentTime: Date = new Date();
currentTime.setSeconds(currentTime.getSeconds() + 30);
const scheduledTime: string = recorder.variable("scheduledTime", currentTime.toISOString());
@ -114,18 +123,18 @@ describe("JobRouterClient", function () {
result.matchingMode?.scheduleAndSuspendMode?.scheduleAt?.toISOString(),
scheduledTime,
);
}).timeout(timeoutMs);
});
it("should get a job", async function () {
it("should get a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
const result = await client.getJob(jobId);
assert.isDefined(result);
assert.isDefined(result.id);
assert.equal(result.id, jobId);
}).timeout(timeoutMs);
});
it("should update a job", async function () {
it("should update a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
await sleep(1500); // This test is flaky
@ -144,9 +153,9 @@ describe("JobRouterClient", function () {
assert.equal(updateResult.priority, updatePatch.priority);
assert.equal(removeResult.priority, 1);
assert.isUndefined(removeResult.dispositionCode);
}).timeout(timeoutMs);
});
it("should get queue position for a job", async function () {
it("should get queue position for a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
await pollForJobQueued(jobId, client);
const result = await client.getJobQueuePosition(jobId);
@ -154,9 +163,9 @@ describe("JobRouterClient", function () {
assert.isDefined(result);
assert.isDefined(result.position);
assert.equal(jobId, result.jobId);
}).timeout(timeoutMs);
});
it("should reclassify a job", async function () {
it("should reclassify a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
let result;
await retry(
@ -167,9 +176,9 @@ describe("JobRouterClient", function () {
);
assert.isDefined(result);
}).timeout(timeoutMs);
});
it("should list jobs", async function () {
it("should list jobs", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
const result: RouterJob[] = [];
@ -178,9 +187,9 @@ describe("JobRouterClient", function () {
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should list scheduled jobs", async function () {
it("should list scheduled jobs", { timeout: timeoutMs }, async () => {
const currentTime: Date = new Date();
currentTime.setSeconds(currentTime.getSeconds() + 30);
const scheduledTime: string = recorder.variable("scheduledTime", currentTime.toISOString());
@ -197,9 +206,9 @@ describe("JobRouterClient", function () {
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should cancel a job", async function () {
it("should cancel a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
let result;
await retry(
@ -210,15 +219,15 @@ describe("JobRouterClient", function () {
);
assert.isDefined(result);
}).timeout(timeoutMs);
});
it("should delete a job", async function () {
it("should delete a job", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
await sleep(500); // This test is flaky
await client.cancelJob(jobId, jobRequest);
const result = await client.deleteJob(jobId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -2,18 +2,17 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import { assert } from "chai";
import type { RouterQueue, JobRouterAdministrationClient } from "../../../src";
import type { Context } from "mocha";
import type { RouterQueue, JobRouterAdministrationClient } from "../../../src/index.js";
import {
getDistributionPolicyRequest,
getExceptionPolicyRequest,
getQueueRequest,
} from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { timeoutMs } from "../utils/constants";
} from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -24,10 +23,10 @@ describe("JobRouterClient", function () {
const { exceptionPolicyId, exceptionPolicyRequest } = getExceptionPolicyRequest(testRunId);
const { queueId, queueRequest } = getQueueRequest(testRunId);
describe("Queue Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Queue Operations", () => {
beforeEach(async (ctx) => {
({ administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -37,32 +36,32 @@ describe("JobRouterClient", function () {
await administrationClient.createQueue(queueId, queueRequest);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await administrationClient.deleteQueue(queueId);
await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
await administrationClient.deleteDistributionPolicy(distributionPolicyId);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create a queue", async function () {
it("should create a queue", { timeout: timeoutMs }, async () => {
const result = await administrationClient.createQueue(queueId, queueRequest);
assert.isDefined(result);
assert.isDefined(result?.id);
assert.equal(result.name, queueRequest.name);
}).timeout(timeoutMs);
});
it("should get a queue", async function () {
it("should get a queue", { timeout: timeoutMs }, async () => {
const result = await administrationClient.getQueue(queueId);
assert.equal(result.id, queueId);
assert.equal(result.name, queueRequest.name);
}).timeout(timeoutMs);
});
it("should update a queue", async function () {
it("should update a queue", { timeout: timeoutMs }, async () => {
const updatePatch = { ...queueRequest, name: "new-name" };
const updateResult = await administrationClient.updateQueue(queueId, updatePatch);
@ -75,21 +74,21 @@ describe("JobRouterClient", function () {
assert.isDefined(removeResult.id);
assert.equal(updateResult.name, updatePatch.name);
assert.isUndefined(removeResult.name);
}).timeout(timeoutMs);
});
it("should list queues", async function () {
it("should list queues", { timeout: timeoutMs }, async () => {
const result: RouterQueue[] = [];
for await (const queue of administrationClient.listQueues({ maxPageSize: 20 })) {
result.push(queue.queue!);
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should delete a queue", async function () {
it("should delete a queue", { timeout: timeoutMs }, async () => {
const result = await administrationClient.deleteQueue(queueId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -2,19 +2,22 @@
// Licensed under the MIT License.
import type { Recorder } from "@azure-tools/test-recorder";
import { assert } from "chai";
import type { Context } from "mocha";
import type { JobRouterAdministrationClient, JobRouterClient, RouterWorker } from "../../../src";
import type {
JobRouterAdministrationClient,
JobRouterClient,
RouterWorker,
} from "../../../src/index.js";
import {
getDistributionPolicyRequest,
getExceptionPolicyRequest,
getQueueRequest,
getWorkerRequest,
} from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { sleep, timeoutMs } from "../utils/constants";
} from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { sleep, timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let client: JobRouterClient;
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -28,10 +31,10 @@ describe("JobRouterClient", function () {
const { workerId, workerRequest } = getWorkerRequest(testRunId);
// Order matters (registration idempotency)
describe("Worker Operations", function () {
this.beforeEach(async function (this: Context) {
describe("Worker Operations", () => {
beforeEach(async (ctx) => {
({ client, administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -42,34 +45,34 @@ describe("JobRouterClient", function () {
await client.createWorker(workerId, workerRequest);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await client.deleteWorker(workerId);
await administrationClient.deleteQueue(queueId);
await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
await administrationClient.deleteDistributionPolicy(distributionPolicyId);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should create a worker", async function () {
it("should create a worker", { timeout: timeoutMs }, async () => {
const result = await client.createWorker(workerId, workerRequest);
assert.isDefined(result);
assert.isDefined(result.id);
assert.equal(result.totalCapacity, workerRequest.totalCapacity);
}).timeout(timeoutMs);
});
it("should get a worker", async function () {
it("should get a worker", { timeout: timeoutMs }, async () => {
const result = await client.getWorker(workerId);
assert.equal(result.id, workerId);
assert.equal(result.totalCapacity, workerRequest.totalCapacity);
assert.deepEqual(result.channelConfigurations, workerRequest.channelConfigurations);
}).timeout(timeoutMs);
});
it("should update a worker", async function () {
it("should update a worker", { timeout: timeoutMs }, async () => {
const updatePatch = {
...workerRequest,
totalCapacity: 100,
@ -87,9 +90,9 @@ describe("JobRouterClient", function () {
assert.isDefined(removeResult?.id);
assert.equal(updateResult.totalCapacity, updatePatch.totalCapacity);
assert.isEmpty(removeResult.tags);
}).timeout(timeoutMs);
});
it("should register and deregister a worker", async function () {
it("should register and deregister a worker", { timeout: timeoutMs }, async () => {
const registerResult = await client.updateWorker(workerId, {
...workerRequest,
availableForOffers: true,
@ -107,21 +110,21 @@ describe("JobRouterClient", function () {
assert.isDefined(deregisterResult);
assert.isDefined(deregisterResult?.id);
assert.equal(deregisterResult.availableForOffers, false);
}).timeout(timeoutMs);
});
it("should list workers", async function () {
it("should list workers", { timeout: timeoutMs }, async () => {
const result: RouterWorker[] = [];
for await (const worker of client.listWorkers({ maxPageSize: 20 })) {
result.push(worker.worker!);
}
assert.isNotEmpty(result);
}).timeout(timeoutMs);
});
it("should delete a worker", async function () {
it("should delete a worker", { timeout: timeoutMs }, async () => {
const result = await client.deleteWorker(workerId);
assert.isDefined(result);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -8,21 +8,20 @@ import {
getJobRequest,
getQueueRequest,
getWorkerRequest,
} from "../utils/testData";
import { assert } from "chai";
} from "../utils/testData.js";
import type {
RouterJobAssignment,
RouterJobOffer,
JobRouterAdministrationClient,
JobRouterClient,
} from "../../../src";
import type { Context } from "mocha";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { timeoutMs } from "../utils/constants";
} from "../../../src/index.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { timeoutMs } from "../utils/constants.js";
import type { Recorder } from "@azure-tools/test-recorder";
import { pollForJobAssignment, pollForJobOffer } from "../utils/polling";
import { pollForJobAssignment, pollForJobOffer } from "../utils/polling.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let client: JobRouterClient;
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -38,10 +37,10 @@ describe("JobRouterClient", function () {
const { jobId, jobRequest } = getJobRequest(testRunId);
const { workerId, workerRequest } = getWorkerRequest(testRunId);
describe("Assignment Scenario", function () {
this.beforeEach(async function (this: Context) {
describe("Assignment Scenario", () => {
beforeEach(async (ctx) => {
({ client, administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createExceptionPolicy(exceptionPolicyId, exceptionPolicyRequest);
await administrationClient.createDistributionPolicy(
@ -56,7 +55,7 @@ describe("JobRouterClient", function () {
await client.createWorker(workerId, { ...workerRequest, availableForOffers: true });
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await client.deleteWorker(workerId);
await client.deleteJob(jobId);
await administrationClient.deleteClassificationPolicy(classificationPolicyId);
@ -64,12 +63,12 @@ describe("JobRouterClient", function () {
await administrationClient.deleteDistributionPolicy(distributionPolicyId);
await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should complete assignment scenario", async () => {
it("should complete assignment scenario", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
const offer: RouterJobOffer = await pollForJobOffer(workerId, client);
@ -93,6 +92,6 @@ describe("JobRouterClient", function () {
const closeJobResponse = await client.closeJob(jobId, acceptOfferResponse.assignmentId);
assert.isNotNull(closeJobResponse);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -7,16 +7,15 @@ import {
getExceptionPolicyRequest,
getJobRequest,
getQueueRequest,
} from "../utils/testData";
import { assert } from "chai";
import type { Context } from "mocha";
} from "../utils/testData.js";
import type { Recorder } from "@azure-tools/test-recorder";
import type { JobRouterAdministrationClient, JobRouterClient } from "../../../src";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { pollForJobCancelled, pollForJobQueued } from "../utils/polling";
import { timeoutMs } from "../utils/constants";
import type { JobRouterAdministrationClient, JobRouterClient } from "../../../src/index.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { pollForJobCancelled, pollForJobQueued } from "../utils/polling.js";
import { timeoutMs } from "../utils/constants.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let client: JobRouterClient;
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -32,10 +31,10 @@ describe("JobRouterClient", function () {
const { jobId, jobRequest } = getJobRequest(testRunId);
const dispositionCode = `disposition-${testRunId}`;
describe("Cancellation Scenario", function () {
this.beforeEach(async function (this: Context) {
describe("Cancellation Scenario", () => {
beforeEach(async (ctx) => {
({ client, administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -49,19 +48,19 @@ describe("JobRouterClient", function () {
);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await client.deleteJob(jobId);
await administrationClient.deleteClassificationPolicy(classificationPolicyId);
await administrationClient.deleteQueue(queueId);
await administrationClient.deleteExceptionPolicy(exceptionPolicyId);
await administrationClient.deleteDistributionPolicy(distributionPolicyId);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should complete cancellation scenario", async () => {
it("should complete cancellation scenario", { timeout: timeoutMs }, async () => {
await client.createJob(jobId, jobRequest);
await pollForJobQueued(jobId, client);
@ -70,6 +69,6 @@ describe("JobRouterClient", function () {
assert.equal(result.status, "cancelled");
assert.equal(result.dispositionCode, dispositionCode);
}).timeout(timeoutMs);
});
});
});

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { assert } from "chai";
import type { JobRouterAdministrationClient, JobRouterClient } from "../../../src";
import type { Context } from "mocha";
import type { JobRouterAdministrationClient, JobRouterClient } from "../../../src/index.js";
import {
getClassificationPolicyCombined,
getClassificationPolicyConditional,
@ -19,13 +16,14 @@ import {
getQueueEnglish,
getQueueFrench,
getQueueRequest,
} from "../utils/testData";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient";
import { timeoutMs } from "../utils/constants";
} from "../utils/testData.js";
import { createRecordedRouterClientWithConnectionString } from "../../internal/utils/mockClient.js";
import { timeoutMs } from "../utils/constants.js";
import type { Recorder } from "@azure-tools/test-recorder";
import { pollForJobQueued, retry } from "../utils/polling";
import { pollForJobQueued, retry } from "../utils/polling.js";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
describe("JobRouterClient", function () {
describe("JobRouterClient", () => {
let client: JobRouterClient;
let administrationClient: JobRouterAdministrationClient;
let recorder: Recorder;
@ -46,10 +44,10 @@ describe("JobRouterClient", function () {
return id;
}
describe("Queueing Scenario", function () {
this.beforeEach(async function (this: Context) {
describe("Queueing Scenario", () => {
beforeEach(async (ctx) => {
({ client, administrationClient, recorder } =
await createRecordedRouterClientWithConnectionString(this));
await createRecordedRouterClientWithConnectionString(ctx));
await administrationClient.createDistributionPolicy(
distributionPolicyId,
@ -59,7 +57,7 @@ describe("JobRouterClient", function () {
await administrationClient.createQueue(queueId, queueRequest);
});
this.afterEach(async function (this: Context) {
afterEach(async (ctx) => {
await retry(
async () => {
await administrationClient.deleteQueue(queueId);
@ -69,86 +67,102 @@ describe("JobRouterClient", function () {
{ retries: 1, retryIntervalMs: 500 },
);
if (!this.currentTest?.isPending() && recorder) {
if (!ctx.task.pending && recorder) {
await recorder.stop();
}
});
it("should complete queueing scenario with fallback queue", async () => {
const policy = getClassificationPolicyFallback(testRunId);
const { id, options } = getJobFallback(testRunId);
it(
"should complete queueing scenario with fallback queue",
{ timeout: timeoutMs },
async () => {
const policy = getClassificationPolicyFallback(testRunId);
const { id, options } = getJobFallback(testRunId);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueRequest.id);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueRequest.id);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
}).timeout(timeoutMs);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
},
);
it("should complete queueing scenario with conditional selector", async () => {
const policy = getClassificationPolicyConditional(testRunId);
const { id, options } = getJobConditional(testRunId);
it(
"should complete queueing scenario with conditional selector",
{ timeout: timeoutMs },
async () => {
const policy = getClassificationPolicyConditional(testRunId);
const { id, options } = getJobConditional(testRunId);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueId);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueId);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
}).timeout(timeoutMs);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
},
);
it("should complete queueing scenario with passthrough selectors", async () => {
const policy = getClassificationPolicyPassthrough(testRunId);
const { id, options } = getJobPassthrough(testRunId);
it(
"should complete queueing scenario with passthrough selectors",
{ timeout: timeoutMs },
async () => {
const policy = getClassificationPolicyPassthrough(testRunId);
const { id, options } = getJobPassthrough(testRunId);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await client.createJob(id, options);
const queuedJob = await pollForJobQueued(id, client);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueId);
assert.equal(queuedJob.status, "queued");
assert.equal(queuedJob.queueId, queueId);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
}).timeout(timeoutMs);
await client.cancelJob(id);
await client.deleteJob(id);
await administrationClient.deleteClassificationPolicy(policy.id!);
},
);
it("should complete queueing scenario with combined selectors", async () => {
const policy = getClassificationPolicyCombined(testRunId);
const jobEnglish = getJobEnglish(testRunId);
const jobFrench = getJobFrench(testRunId);
const queueEnglish = getQueueEnglish(testRunId);
const queueFrench = getQueueFrench(testRunId);
it(
"should complete queueing scenario with combined selectors",
{ timeout: timeoutMs },
async () => {
const policy = getClassificationPolicyCombined(testRunId);
const jobEnglish = getJobEnglish(testRunId);
const jobFrench = getJobFrench(testRunId);
const queueEnglish = getQueueEnglish(testRunId);
const queueFrench = getQueueFrench(testRunId);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await administrationClient.createQueue(queueEnglish.id!, queueEnglish);
await administrationClient.createQueue(queueFrench.id!, queueFrench);
await client.createJob(jobEnglish.id!, jobEnglish.options);
await client.createJob(jobFrench.id!, jobFrench.options);
const queuedJobEnglish = await pollForJobQueued(jobEnglish.id!, client);
const queuedJobFrench = await pollForJobQueued(jobFrench.id!, client);
await administrationClient.createClassificationPolicy(policy.id!, policy);
await administrationClient.createQueue(queueEnglish.id!, queueEnglish);
await administrationClient.createQueue(queueFrench.id!, queueFrench);
await client.createJob(jobEnglish.id!, jobEnglish.options);
await client.createJob(jobFrench.id!, jobFrench.options);
const queuedJobEnglish = await pollForJobQueued(jobEnglish.id!, client);
const queuedJobFrench = await pollForJobQueued(jobFrench.id!, client);
assert.equal(queuedJobEnglish.status, "queued");
assert.equal(queuedJobFrench.status, "queued");
assert.equal(queueIdFixup(queuedJobEnglish.queueId), queueEnglish.id!);
assert.equal(queueIdFixup(queuedJobFrench.queueId), queueFrench.id!);
assert.equal(queuedJobEnglish.status, "queued");
assert.equal(queuedJobFrench.status, "queued");
assert.equal(queueIdFixup(queuedJobEnglish.queueId), queueEnglish.id!);
assert.equal(queueIdFixup(queuedJobFrench.queueId), queueFrench.id!);
await client.cancelJob(jobEnglish.id!);
await client.cancelJob(jobFrench.id!);
await client.deleteJob(jobEnglish.id!);
await client.deleteJob(jobFrench.id!);
await administrationClient.deleteClassificationPolicy(policy.id!);
await administrationClient.deleteQueue(queueEnglish.id!);
await administrationClient.deleteQueue(queueFrench.id!);
}).timeout(timeoutMs);
await client.cancelJob(jobEnglish.id!);
await client.cancelJob(jobFrench.id!);
await client.deleteJob(jobEnglish.id!);
await client.deleteJob(jobFrench.id!);
await administrationClient.deleteClassificationPolicy(policy.id!);
await administrationClient.deleteQueue(queueEnglish.id!);
await administrationClient.deleteQueue(queueFrench.id!);
},
);
});
});

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { isNode } from "@azure/core-util";
import { isNodeLike } from "@azure/core-util";
export const baseUri = "https://contoso.api.fake";
@ -11,6 +11,6 @@ export const generateToken = (): string => {
const validForMinutes = 60;
const expiresOn = (Date.now() + validForMinutes * 60 * 1000) / 1000;
const tokenString = JSON.stringify({ exp: expiresOn });
const base64Token = isNode ? Buffer.from(tokenString).toString("base64") : btoa(tokenString);
const base64Token = isNodeLike ? Buffer.from(tokenString).toString("base64") : btoa(tokenString);
return `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.${base64Token}.adM-ddBZZlQ1WlN3pdPBOF5G4Wh9iZpxNP_fSvpF4cWs`;
};

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { v4 as uuid } from "uuid";
import { randomUUID } from "@azure/core-util";
import { env } from "@azure-tools/test-recorder";
// HACK: Intentionally block to:
@ -12,5 +13,5 @@ export function sleep(ms: number): Promise<any> {
export const timeoutMs: number = 15000;
export const getTestRunId = (staticId: string): string => {
return ["record", "playback", "undefined"].includes(env.TEST_MODE!) ? staticId : uuid();
return ["record", "playback", "undefined"].includes(env.TEST_MODE!) ? staticId : randomUUID();
};

Просмотреть файл

@ -1,8 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import type { JobRouterClient } from "../../../src/jobRouterClient";
import type { RouterJob, RouterWorker, RouterJobAssignment, RouterJobOffer } from "../../../src";
import type { JobRouterClient } from "../../../src/jobRouterClient.js";
import type {
RouterJob,
RouterWorker,
RouterJobAssignment,
RouterJobOffer,
} from "../../../src/index.js";
export async function pollForJobOffer(
workerId: string,
@ -62,7 +67,7 @@ export const retry = async <T>(
fn: () => Promise<T> | T,
{ retries, retryIntervalMs }: { retries: number; retryIntervalMs: number },
): Promise<T> => {
const sleep = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
const sleep = (ms = 0): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
try {
return await fn();
} catch (error) {

Просмотреть файл

@ -15,7 +15,7 @@ import type {
StaticQueueSelectorAttachment,
CreateJobOptions,
CreateClassificationPolicyOptions,
} from "../../../src";
} from "../../../src/index.js";
const queueId = "test-queue";
const exceptionPolicyId = "test-e-policy";

Просмотреть файл

@ -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,12 +1,13 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"outDir": "./dist-esm",
"declarationDir": "./types",
"paths": {
"@azure/communication-job-router": ["./src/index"]
}
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"exclude": ["node_modules", "types", "temp", "browser", "dist", "dist-esm", "./samples/**/*.ts"],
"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.js";
export default mergeConfig(
viteConfig,
defineConfig({
test: {
include: ["test/**/*.spec.ts"],
hookTimeout: 5000000,
testTimeout: 5000000,
},
}),
);