[notification-hubs] Move to vitest (#28943)

### Packages impacted by this PR

- @azure/notification-hubs

### Issues associated with this PR


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

Moves the `@azure/notification-hubs` to `vitest` with different configs
for browser, and node.js with different configs for unit tests versus
integration tests.

### 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
- [x] 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-04-12 11:16:22 -04:00 коммит произвёл GitHub
Родитель 08366cb8b9
Коммит c980494803
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
41 изменённых файлов: 792 добавлений и 746 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -44,10 +44,20 @@ export default leafCommand(commandInfo, async (options) => {
await playwrightInstall();
}
const args = options["browser"] ? "-c vitest.browser.config.ts" : "";
const updatedArgs = options["--"]?.map((opt) =>
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
);
let args = "";
// Only set if we didn't provide a config file path
if (
options["browser"] &&
updatedArgs?.indexOf("-c") !== -1 &&
updatedArgs?.indexOf("--config") !== -1
) {
args = "-c vitest.browser.config.ts";
}
const vitestArgs = updatedArgs?.length ? updatedArgs.join(" ") : "";
const command = {
command: `vitest ${args} ${vitestArgs}`,

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

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

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

@ -0,0 +1,12 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx"
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build/browser"
}
}

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

@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}

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

@ -0,0 +1,15 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx"
],
"exclude": [
"../src/**/*.mts",
"../src/auth/hmacSha256-browser.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}

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

@ -0,0 +1,14 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx"
],
"exclude": [
".././src/auth/hmacSha256-browser.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}

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

@ -0,0 +1,14 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx"
],
"exclude": [
".././src/auth/hmacSha256-browser.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build/react-native"
}
}

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

@ -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/latest/notification-hubs.d.ts"
"publicTrimmedFilePath": "./dist/notification-hubs.d.ts"
},
"messages": {
"tsdocMessageReporting": {

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

@ -1,131 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// https://github.com/karma-runner/karma-chrome-launcher
process.env.CHROME_BIN = require("puppeteer").executablePath();
require("dotenv").config();
const { relativeRecordingsPath } = require("@azure-tools/test-recorder");
process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: "./",
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ["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",
{ pattern: "dist-test/index.browser.js.map", type: "html", included: false, served: true },
],
// list of files / patterns to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"**/*.js": ["sourcemap", "env"],
// IMPORTANT: COMMENT following line if you want to debug in your browsers!!
// Preprocess source file to calculate code coverage, however this will make source file unreadable
//"dist-test/index.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",
"WIDGET_SERVICE_ENDPOINT",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"AZURE_TENANT_ID",
"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: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', "--disable-web-security"]
}
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: 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",
},
},
});
};

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

@ -3,30 +3,8 @@
"version": "1.2.1",
"description": "Azure Notification Hubs SDK for JavaScript",
"sdk-type": "client",
"main": "dist/index.cjs",
"module": "dist-esm/src/index.js",
"browser": {
"./dist-esm/src/auth/hmacSha256.js": "./dist-esm/src/auth/hmacSha256.browser.js"
},
"react-native": {
"./dist/index.js": "./dist-esm/src/index.js"
},
"main": "./dist/commonjs/index.js",
"type": "module",
"exports": {
".": {
"types": "./types/src/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist-esm/src/index.js"
},
"./api": {
"types": "./types/src/api/index.d.ts",
"import": "./dist-esm/src/api/index.js"
},
"./models": {
"types": "./types/src/models/index.d.ts",
"import": "./dist-esm/src/models/index.js"
}
},
"//metadata": {
"constantPaths": [
{
@ -35,36 +13,32 @@
}
]
},
"types": "types/latest/notification-hubs.d.ts",
"types": "./dist/commonjs/index.d.ts",
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf -G node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"bundle": "tsc -p . && dev-tool run bundle",
"build:samples": "echo Obsolete",
"build:test": "npm run bundle",
"build": "npm run build:test && npm run extract-api",
"build:test": "tshy && dev-tool run build-test",
"build": "npm run build:test && api-extractor run --local",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"samples-dev/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "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": "tshy && api-extractor run --local",
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "echo skipped",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 600000 \"dist-esm/test/internal/**/*.spec.js\" \"dist-esm/test/public/**/*.spec.js\"",
"integration-test:browser": "npm run build:test && dev-tool run test:vitest --browser -- -c vitest.browser.int.config.ts",
"integration-test:node": "dev-tool run test:vitest -- -c vitest.int.config.ts",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint README.md package.json api-extractor.json src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]",
"lint": "eslint README.md package.json api-extractor.json src test --ext .ts,.javascript,.js",
"pack": "npm pack 2>&1",
"test:browser": "npm run clean && npm run build:test && npm run integration-test:browser",
"test:node": "npm run clean && tsc -p . && npm run integration-test:node",
"test": "npm run clean && tsc -p . && npm run unit-test:node && npm run bundle && npm run unit-test:browser && npm run integration-test",
"unit-test:browser": "karma start karma.conf.cjs --single-run",
"unit-test:node": "dev-tool run test:node-tsx-ts --no-test-proxy -- --exclude \"test/**/browser/*.spec.ts\" \"test/internal/unit/{,!(browser)/**/}*.spec.ts\" \"test/public/unit/{,!(browser)/**/}*.spec.ts\"",
"test:node": "npm run clean && tshy && npm run integration-test:node",
"test": "npm run clean && tshy && npm run unit-test:node && npm run build:test && npm run unit-test:browser && npm run integration-test",
"unit-test:browser": "npm run build:test && dev-tool run test:vitest --no-test-proxy --browser -- -c vitest.browser.unit.config.ts",
"unit-test:node": "dev-tool run test:vitest --no-test-proxy -- -c vitest.unit.config.ts",
"unit-test": "npm run unit-test:node && npm run unit-test:browser"
},
"files": [
"dist/",
"dist-esm/src/",
"types/src",
"types/latest/",
"README.md",
"LICENSE"
],
@ -88,44 +62,105 @@
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure-tools/test-recorder": "^3.0.0",
"@azure/test-utils": "^1.0.0",
"@microsoft/api-extractor": "^7.40.1",
"@types/chai": "^4.3.1",
"@types/mocha": "^10.0.0",
"@azure-tools/test-recorder": "^4.0.0",
"@microsoft/api-extractor": "^7.43.1",
"@types/node": "^18.0.0",
"c8": "^9.1.0",
"chai": "^4.3.10",
"@vitest/browser": "^1.5.0",
"@vitest/coverage-istanbul": "^1.5.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "^2.2.0",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^2.1.2",
"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",
"puppeteer": "^22.2.0",
"playwright": "^1.43.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"tsx": "^4.7.1",
"typescript": "~5.4.5"
"tshy": "^1.13.1",
"typescript": "~5.4.5",
"vitest": "^1.5.0"
},
"dependencies": {
"@azure/core-auth": "^1.7.0",
"@azure/abort-controller": "^2.1.0",
"@azure/core-lro": "^2.7.0",
"@azure/core-paging": "^1.6.0",
"@azure/core-rest-pipeline": "^1.15.0",
"@azure/core-tracing": "^1.1.0",
"@azure/core-util": "^1.8.0",
"@azure/core-xml": "^1.4.0",
"@azure/logger": "^1.1.0",
"@azure-rest/core-client": "^1.3.0",
"@azure/core-auth": "^1.7.2",
"@azure/abort-controller": "^2.1.2",
"@azure/core-lro": "^2.7.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.15.2",
"@azure/core-tracing": "^1.1.2",
"@azure/core-util": "^1.8.2",
"@azure/core-xml": "^1.4.2",
"@azure/logger": "^1.1.2",
"@azure-rest/core-client": "^1.4.0",
"tslib": "^2.6.2"
},
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./api": "./src/api/index.ts",
"./models": "./src/models/index.ts"
},
"dialects": [
"esm",
"commonjs"
],
"esmDialects": [
"browser",
"react-native"
],
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"react-native": {
"types": "./dist/react-native/index.d.ts",
"default": "./dist/react-native/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./api": {
"browser": {
"types": "./dist/browser/api/index.d.ts",
"default": "./dist/browser/api/index.js"
},
"react-native": {
"types": "./dist/react-native/api/index.d.ts",
"default": "./dist/react-native/api/index.js"
},
"import": {
"types": "./dist/esm/api/index.d.ts",
"default": "./dist/esm/api/index.js"
},
"require": {
"types": "./dist/commonjs/api/index.d.ts",
"default": "./dist/commonjs/api/index.js"
}
},
"./models": {
"browser": {
"types": "./dist/browser/models/index.d.ts",
"default": "./dist/browser/models/index.js"
},
"react-native": {
"types": "./dist/react-native/models/index.d.ts",
"default": "./dist/react-native/models/index.js"
},
"import": {
"types": "./dist/esm/models/index.d.ts",
"default": "./dist/esm/models/index.js"
},
"require": {
"types": "./dist/commonjs/models/index.d.ts",
"default": "./dist/commonjs/models/index.js"
}
}
}
}

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { parseNotificationHubsConnectionString } from "../../../src/auth/connectionStringUtils.js";
describe("parseNotificationHubsConnectionString", () => {

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { parseNotificationDetails } from "../../../src/serializers/notificationDetailsSerializer.js";
const NOTIFICATION_DETAILS = `<NotificationDetails xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

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

@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import {
parseNotificationHubJobEntry,
parseNotificationHubJobFeed,
serializeNotificationHubJobEntry,
} from "../../../src/serializers/notificationHubJobSerializer.js";
import { NotificationHubJob } from "../../../src/models/notificationHubJob.js";
import { assert } from "@azure/test-utils";
const HUB_JOB_OUTGOING = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { parseNotificationOutcome } from "../../../src/serializers/notificationOutcomeSerializer.js";
const FEEDBACK = `<NotificationOutcome xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { createAppleNotification } from "../../../src/models/notification.js";
import { createMultipartDirectNotification } from "../../../src/utils/notificationUtils.js";

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import {
isDirectSendNotificationOptions,
isSendNotificationOptions,

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import {
AdmRegistrationDescription,
AdmTemplateRegistrationDescription,
@ -41,7 +42,6 @@ import {
registrationDescriptionParser,
registrationDescriptionSerializer,
} from "../../../src/serializers/registrationSerializer.js";
import { assert } from "@azure/test-utils";
const ADM_REGISTRATION = `<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import {
getDate,
getDateOrUndefined,
@ -13,7 +14,6 @@ import {
getTagsOrUndefined,
isDefined,
} from "../../../src/utils/utils.js";
import { assert } from "@azure/test-utils";
describe("utils", () => {
describe("isDefined", () => {

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { parseXMLError } from "../../../src/utils/xmlUtils.js";
const NOTIFICATION_XML_ERROR = `

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

@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import {
NotificationHubsClientContext,
createOrUpdateInstallation,
deleteInstallation,
} from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
} from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createAppleInstallation } from "@azure/notification-hubs/models";
import { createAppleInstallation } from "../../src/models/index.js";
import { createRecordedClientContext } from "./utils/recordedClient.js";
describe("createOrUpdateInstallation()", () => {
@ -17,28 +17,16 @@ describe("createOrUpdateInstallation()", () => {
const installationId = "0e7c5973-714c-4ba9-a233-7c4497d5f43b";
const pushChannel = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function (this: Mocha.Context) {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
context = await createRecordedClientContext(recorder);
});
afterEach(async function () {
if (!isNode) {
return;
}
afterEach(async () => {
await recorder.stop();
});
it("should add an installation", async function () {
if (!isNode) {
this.skip();
}
it("should add an installation", async () => {
const installation = createAppleInstallation({
installationId,
pushChannel,

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

@ -1,16 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import {
NotificationHubsClientContext,
createOrUpdateRegistration,
createRegistrationId,
deleteRegistration,
getRegistration,
} from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
} from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models";
import { createAppleRegistrationDescription } from "../../src/models/index.js";
import { createRecordedClientContext } from "./utils/recordedClient.js";
describe("createRegistrationId()", () => {
@ -19,12 +19,8 @@ describe("createRegistrationId()", () => {
let context: NotificationHubsClientContext;
const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function (this: Mocha.Context) {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
await recorder.setMatcher("BodilessMatcher");
context = await createRecordedClientContext(recorder);
@ -40,19 +36,11 @@ describe("createRegistrationId()", () => {
});
afterEach(async () => {
if (!isNode) {
return;
}
await deleteRegistration(context, registrationId);
await recorder.stop();
});
it("should get a registration by the given registration ID", async function () {
if (!isNode) {
this.skip();
}
it("should get a registration by the given registration ID", async () => {
const registration = await getRegistration(context!, registrationId!);
assert.equal(registration.registrationId, registrationId);

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

@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import {
AppleRegistrationDescription,
createAppleRegistrationDescription,
} from "@azure/notification-hubs/models";
} from "../../src/models/index.js";
import {
NotificationHubsClientContext,
createRegistration,
deleteRegistration,
getRegistration,
} from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
} from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createRecordedClientContext } from "./utils/recordedClient.js";
@ -21,12 +21,8 @@ describe("getRegistration", () => {
let registrationId: string;
const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function () {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
await recorder.setMatcher("BodilessMatcher");
context = await createRecordedClientContext(recorder);
@ -43,19 +39,11 @@ describe("getRegistration", () => {
});
afterEach(async () => {
if (!isNode) {
return;
}
await deleteRegistration(context, registrationId);
await recorder.stop();
});
it("should get a registration by the given registration ID", async function () {
if (!isNode) {
this.skip();
}
it("should get a registration by the given registration ID", async () => {
const registration = await getRegistration(context!, registrationId!);
assert.equal(registration.registrationId, registrationId);

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

@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import {
AppleRegistrationDescription,
createAppleRegistrationDescription,
} from "@azure/notification-hubs/models";
} from "../../src/models/index.js";
import {
NotificationHubsClientContext,
createRegistration,
deleteRegistration,
listRegistrations,
} from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
} from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createRecordedClientContext } from "./utils/recordedClient.js";
@ -21,12 +21,8 @@ describe("listRegistrations()", () => {
const registrationIds: string[] = [];
const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function () {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
await recorder.setMatcher("BodilessMatcher");
context = await createRecordedClientContext(recorder);
@ -45,10 +41,6 @@ describe("listRegistrations()", () => {
});
afterEach(async () => {
if (!isNode) {
return;
}
for (const registrationId of registrationIds) {
await deleteRegistration(context, registrationId);
}
@ -56,11 +48,7 @@ describe("listRegistrations()", () => {
await recorder.stop();
});
it("should list all registrations", async function () {
if (!isNode) {
this.skip();
}
it("should list all registrations", async () => {
const registrations = listRegistrations(context);
let numberOfItems = 0;

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

@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import {
AppleRegistrationDescription,
createAppleRegistrationDescription,
} from "@azure/notification-hubs/models";
} from "../../src/models/index.js";
import {
NotificationHubsClientContext,
createRegistration,
deleteRegistration,
listRegistrationsByTag,
} from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
} from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createRecordedClientContext } from "./utils/recordedClient.js";
@ -21,12 +21,8 @@ describe("listRegistrationsByTag()", () => {
const registrationIds: string[] = [];
const deviceToken = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function () {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
await recorder.setMatcher("BodilessMatcher");
context = await createRecordedClientContext(recorder);
@ -45,10 +41,6 @@ describe("listRegistrationsByTag()", () => {
});
afterEach(async () => {
if (!isNode) {
return;
}
for (const registrationId of registrationIds) {
await deleteRegistration(context, registrationId);
}
@ -56,11 +48,7 @@ describe("listRegistrationsByTag()", () => {
await recorder.stop();
});
it("should list all registrations", async function () {
if (!isNode) {
this.skip();
}
it("should list all registrations", async () => {
const tag = "likes_football";
const registrations = listRegistrationsByTag(context, tag);

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

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { NotificationHubsClientContext, sendNotification } from "@azure/notification-hubs/api";
import { assert, isNode } from "@azure/test-utils";
import { describe, it, assert, beforeEach, afterEach } from "vitest";
import { NotificationHubsClientContext, sendNotification } from "../../src/api/index.js";
import { Recorder } from "@azure-tools/test-recorder";
import { createAppleNotification } from "@azure/notification-hubs/models";
import { createAppleNotification } from "../../src/models/index.js";
import { createRecordedClientContext } from "./utils/recordedClient.js";
describe("sendDirectNotification()", () => {
@ -12,28 +12,16 @@ describe("sendDirectNotification()", () => {
let context: NotificationHubsClientContext;
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
beforeEach(async function (this: Mocha.Context) {
if (!isNode) {
return;
}
recorder = new Recorder(this.currentTest);
beforeEach(async (ctx) => {
recorder = new Recorder(ctx);
context = await createRecordedClientContext(recorder);
});
afterEach(async function () {
if (!isNode) {
return;
}
afterEach(async () => {
await recorder.stop();
});
it("should send a broadcast Apple Notification", async function () {
if (!isNode) {
this.skip();
}
it("should send a broadcast Apple Notification", async () => {
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const notification = createAppleNotification({
@ -51,11 +39,7 @@ describe("sendDirectNotification()", () => {
assert.isDefined(result.correlationId);
});
it("should send a direct Apple Notification", async function () {
if (!isNode) {
this.skip();
}
it("should send a direct Apple Notification", async () => {
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const notification = createAppleNotification({
@ -72,11 +56,7 @@ describe("sendDirectNotification()", () => {
assert.isDefined(result.correlationId);
});
it("should send an Apple Notification with a tag expression", async function () {
if (!isNode) {
this.skip();
}
it("should send an Apple Notification with a tag expression", async () => {
const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import {
createAdmInstallation,
createAppleInstallation,
@ -11,7 +12,6 @@ import {
createXiaomiInstallation,
createWindowsInstallation,
} from "../../../src/models/installation.js";
import { assert } from "@azure/test-utils";
describe("createAppleInstallation", () => {
it("should set the default properties", () => {

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

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import * as Constants from "../../../src/utils/constants.js";
import {
createAdmNotification,
@ -16,7 +17,6 @@ import {
createWindowsTileNotification,
createWindowsToastNotification,
} from "../../../src/models/notification.js";
import { assert } from "@azure/test-utils";
describe("createAppleNotification", () => {
it("should create an apple message with defaults", () => {

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

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { describe, it, assert } from "vitest";
import { createWindowsBadgeNotificationBody } from "../../../src/models/notificationBodyBuilder.js";
import { assert } from "@azure/test-utils";
describe("createWindowsBadgeNotificationBody", () => {
it("should handle a notification count", () => {

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

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { assert } from "@azure/test-utils";
import { describe, it, assert } from "vitest";
import { createTagExpression } from "../../../src/models/tagExpressionBuilder.js";
describe("tagExpressionBuilder", () => {

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

@ -9,7 +9,7 @@ const replaceableVariables: { [k: string]: string } = {
// 1. The key-value pairs will be used as the environment variables in playback mode
// 2. If the env variables are present in the recordings as plain strings, they will be replaced with the provided values in record mode
NOTIFICATION_HUB_CONNECTION_STRING:
"Endpoint=sb://testns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=foobarbaz=",
"Endpoint=sb://azsdktestns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=foobarbaz=",
NOTIFICATION_HUB_NAME: "hub_name",
};
@ -20,7 +20,7 @@ const recorderOptions: RecorderStartOptions = {
{
regex: true,
target: `https://(.*).servicebus.windows.net`,
value: "https://testns.servicebus.windows.net",
value: "https://azsdktestns.servicebus.windows.net",
},
],
},
@ -33,7 +33,7 @@ export async function createRecordedClientContext(
if (!env.NOTIFICATION_HUB_CONNECTION_STRING || !env.NOTIFICATION_HUB_NAME) {
throw new Error(
"Notificaiton Hub connection string and hub name must be specified. Make sure NOTIFICATION_HUB_CONNECTION_STRING and NOTIFICATION_HUB_NAME are defined",
"Notification Hub connection string and hub name must be specified. Make sure NOTIFICATION_HUB_CONNECTION_STRING and NOTIFICATION_HUB_NAME are defined",
);
}
return createClientContext(

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

@ -0,0 +1,10 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
}

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

@ -1,8 +1,6 @@
{
"extends": "../../../tsconfig.package",
"compilerOptions": {
"outDir": "./dist-esm",
"declarationDir": "./types",
"paths": {
"@azure/notification-hubs": ["./src/index.js"]
},
@ -10,5 +8,5 @@
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"]
"include": ["src/**/*.ts", "src/**/*.cts", "src/**/*.mts", "test/**/*.ts", "samples-dev/**/*.ts"]
}

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

@ -0,0 +1,17 @@
// 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/internal/**/*.spec.js",
"dist-test/browser/test/public/**/*.spec.js",
],
},
}),
);

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

@ -0,0 +1,17 @@
// 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/internal/unit/{,!(browser)/**/}*.spec.js",
"dist-test/browser/test/public/unit/{,!(browser)/**/}*.spec.js",
],
},
}),
);

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

@ -0,0 +1,14 @@
// 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/internal/**/*.spec.ts", "test/public/**/*.spec.ts"],
},
}),
);

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

@ -0,0 +1,17 @@
// 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/internal/unit/{,!(browser)/**/}*.spec.ts",
"test/public/unit/{,!(browser)/**/}*.spec.ts",
],
},
}),
);

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

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export const env = process.env as Record<string, string | undefined>;
export const env = globalThis.process?.env as Record<string, string | undefined>;

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

@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { defineConfig } from "vitest/config";
import browserMap from "@azure-tools/vite-plugin-browser-test-map";
import { relativeRecordingsPath } from "@azure-tools/test-recorder";
process.env.RECORDINGS_RELATIVE_PATH = relativeRecordingsPath();
export default defineConfig({
define: {
"process.env": process.env,
},
optimizeDeps: {
include: ["@azure-tools/test-recorder"],
},
test: {
reporters: ["basic", "junit"],
outputFile: {
junit: "test-results.browser.xml",
},
browser: {
enabled: true,
headless: true,
name: "chromium",
provider: "playwright",
providerOptions: {
launch: {
args: ["--disable-web-security"],
},
},
},
fakeTimers: {
toFake: ["setTimeout"],
},
watch: false,
coverage: {
include: ["dist-test/browser/**/*.js"],
exclude: [
"dist-test/browser/**/*./*-browser.mjs",
"dist-test/browser/**/*./*-react-native.mjs",
],
provider: "istanbul",
reporter: ["text", "json", "html"],
reportsDirectory: "coverage-browser",
},
},
});

30
vitest.shared.config.ts Normal file
Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
reporters: ["basic", "junit"],
outputFile: {
junit: "test-results.xml",
},
fakeTimers: {
toFake: ["setTimeout", "Date"],
},
watch: false,
exclude: ["test/**/browser/*.spec.ts"],
coverage: {
include: ["src/**/*.ts"],
exclude: [
"src/**/*-browser.mts",
"src/**/*-react-native.mts",
"vitest*.config.ts",
"samples-dev/**/*.ts",
],
provider: "istanbul",
reporter: ["text", "json", "html"],
reportsDirectory: "coverage",
},
},
});