Skip to content

Commit

Permalink
[test-utils] Migrate @azure-tools/test-utils to ESM (#32248)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- `@azure-tools/test-utils`

### Issues associated with this PR

- #31338

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

Migrates `@azure-tools/test-utils` to ESM. Removes web testing as Karma
is no longer supported and not worth the migration to a new tool since
this package is to be deprecated.

### 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)
  • Loading branch information
mpodwysocki authored Dec 17, 2024
1 parent eb67b30 commit f6904d7
Show file tree
Hide file tree
Showing 20 changed files with 1,338 additions and 264 deletions.
1,196 changes: 1,188 additions & 8 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

120 changes: 0 additions & 120 deletions sdk/test-utils/test-utils/karma.conf.js

This file was deleted.

70 changes: 49 additions & 21 deletions sdk/test-utils/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"version": "1.0.3",
"sdk-type": "utility",
"description": "Test utilities library for the Azure SDK for JavaScript and TypeScript",
"main": "dist/index.js",
"module": "dist-esm/src/index.js",
"browser": {
"./dist-esm/src/global.js": "./dist-esm/src/global.browser.js"
},
"types": "./types/src/index.d.ts",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/browser/index.js",
"types": "./dist/commonjs/index.d.ts",
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"build": "npm run clean && tsc -p . && dev-tool run bundle",
"build": "npm run clean && dev-tool run build-package",
"build:samples": "echo Skipped.",
"build:test": "echo skipped. actual commands inlined in browser test scripts",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand All @@ -29,14 +27,12 @@
"test:browser": "npm run clean && npm run build:test npm run unit-test:browser",
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
"unit-test:browser": "tsc -p . && dev-tool run bundle && dev-tool run vendored cross-env karma start --single-run",
"unit-test:browser": "echo skipped",
"unit-test:node": "dev-tool run test:node-ts-input --no-test-proxy",
"update-snippets": "echo skipped"
},
"files": [
"dist/",
"dist-esm/src/",
"types/src/",
"README.md",
"LICENSE"
],
Expand All @@ -56,9 +52,9 @@
"sideEffects": false,
"dependencies": {
"@azure-tools/test-recorder": "^3.0.0",
"@azure/abort-controller": "^2.0.0",
"@azure/core-rest-pipeline": "^1.1.0",
"@azure/core-tracing": "^1.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-rest-pipeline": "^1.18.1",
"@azure/core-tracing": "^1.2.0",
"@opentelemetry/api": "^1.9.0",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.4",
Expand All @@ -71,16 +67,48 @@
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/sinon": "^17.0.0",
"@types/sinon": "^17.0.3",
"eslint": "^9.9.0",
"karma": "^6.2.0",
"karma-chrome-launcher": "^3.0.0",
"karma-coverage": "^2.0.0",
"karma-env-preprocessor": "^0.1.1",
"sinon": "^17.0.0",
"ts-node": "^10.0.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"typescript": "~5.6.2"
},
"type": "module",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"dialects": [
"esm",
"commonjs"
],
"esmDialects": [
"browser",
"react-native"
],
"selfLink": false
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"types": "./dist/browser/index.d.ts",
"default": "./dist/browser/index.js"
},
"react-native": {
"types": "./dist/react-native/index.d.ts",
"default": "./dist/react-native/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
}
}
2 changes: 1 addition & 1 deletion sdk/test-utils/test-utils/src/chai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import chai from "chai";
import { chaiAzure } from "./chaiAzure";
import { chaiAzure } from "./chaiAzure.js";
import chaiAsPromised from "chai-as-promised";
import chaiExclude from "chai-exclude";

Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/test-utils/src/chaiAzure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { assert } from "chai";
import { OperationTracingOptions } from "@azure/core-tracing";
import { supportsTracing } from "./tracing/chaiAzureTrace";
import { supportsTracing } from "./tracing/chaiAzureTrace.js";

/**
* Augments Chai with support for Azure specific assertions.
Expand Down
7 changes: 0 additions & 7 deletions sdk/test-utils/test-utils/src/global.browser.ts

This file was deleted.

7 changes: 0 additions & 7 deletions sdk/test-utils/test-utils/src/global.ts

This file was deleted.

32 changes: 14 additions & 18 deletions sdk/test-utils/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ export {
SupportedVersions,
MultiVersionTestOptions,
TestFunctionWrapper,
} from "./multiVersion";
} from "./multiVersion.js";
export { chai, assert, expect, should } from "./chai.js";
export { matrix } from "./matrix.js";
export { isNode, isNode8 } from "./utils.js";
export { getYieldedValue } from "./getYieldedValue.js";

export { chai, assert, expect, should } from "./chai";
export { matrix } from "./matrix";
export { isNode, isNode8 } from "./utils";
export { getYieldedValue } from "./getYieldedValue";

export { TestSpan } from "./tracing/testSpan";
export * from "./tracing/mockInstrumenter";
export * from "./tracing/mockTracingSpan";
export * from "./tracing/testTracer";
export * from "./tracing/testTracerProvider";
export * from "./tracing/spanGraphModel";

export * from "./fakeTestSecrets";

export { createXhrHttpClient } from "./xhrHttpClient";

export { createMockTracingContext } from "./tracing/mockContext";
export { TestSpan } from "./tracing/testSpan.js";
export * from "./tracing/mockInstrumenter.js";
export * from "./tracing/mockTracingSpan.js";
export * from "./tracing/testTracer.js";
export * from "./tracing/testTracerProvider.js";
export * from "./tracing/spanGraphModel.js";
export * from "./fakeTestSecrets.js";
export { createXhrHttpClient } from "./xhrHttpClient.js";
export { createMockTracingContext } from "./tracing/mockContext.js";
7 changes: 3 additions & 4 deletions sdk/test-utils/test-utils/src/multiVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

import { env, isLiveMode } from "@azure-tools/test-recorder";
import { getGlobalObject } from "./global";

export interface TestFunctionWrapper {
it:
Expand Down Expand Up @@ -169,12 +168,12 @@ export function supports(
// Record and playback depends on titles for recording file names so keeping them
// in order to be compatible with existing recordings.
const wrappedDescribe = isLiveMode()
? function (title: string, fn: Mocha.Func | Mocha.AsyncFunc) {
? function (title: string, fn: (this: Mocha.Suite) => void) {
return supports.global.describe(`${title} (service version ${currentVersion})`, fn);
}
: supports.global.describe;
const wrappedDescribeOnly = isLiveMode()
? function (title: string, fn: Mocha.Func | Mocha.AsyncFunc) {
? function (title: string, fn: (this: Mocha.Suite) => void) {
return supports.global.describe.only(`${title} (service version ${currentVersion})`, fn);
}
: supports.global.describe.only;
Expand All @@ -197,7 +196,7 @@ export function supports(
return chain;
}

supports.global = getGlobalObject();
supports.global = globalThis;

/**
* Options to multi-service-version tests
Expand Down
7 changes: 3 additions & 4 deletions sdk/test-utils/test-utils/src/tracing/chaiAzureTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Licensed under the MIT License.

import { OperationTracingOptions, useInstrumenter } from "@azure/core-tracing";
import { SpanGraph, SpanGraphNode } from "./spanGraphModel";

import { MockInstrumenter } from "./mockInstrumenter";
import { MockTracingSpan } from "./mockTracingSpan";
import { SpanGraph, SpanGraphNode } from "./spanGraphModel.js";
import { MockInstrumenter } from "./mockInstrumenter.js";
import { MockTracingSpan } from "./mockTracingSpan.js";
import { assert } from "chai";

const instrumenter = new MockInstrumenter();
Expand Down
5 changes: 2 additions & 3 deletions sdk/test-utils/test-utils/src/tracing/mockInstrumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
TracingContext,
TracingSpan,
} from "@azure/core-tracing";
import { MockContext, spanKey } from "./mockContext";

import { MockTracingSpan } from "./mockTracingSpan";
import { MockContext, spanKey } from "./mockContext.js";
import { MockTracingSpan } from "./mockTracingSpan.js";

/**
* Represents an implementation of {@link Instrumenter} interface that keeps track of the tracing contexts and spans
Expand Down
2 changes: 1 addition & 1 deletion sdk/test-utils/test-utils/src/tracing/mockTracingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TracingSpanKind,
TracingContext,
} from "@azure/core-tracing";
import { spanKey } from "./mockContext";
import { spanKey } from "./mockContext.js";

/**
* Represents an implementation of a mock tracing span {@link TracingSpan} used for tests
Expand Down
4 changes: 2 additions & 2 deletions sdk/test-utils/test-utils/src/tracing/testTracer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { TestSpan } from "./testSpan";
import { TestSpan } from "./testSpan.js";
import {
SpanContext,
SpanKind,
Expand All @@ -12,7 +12,7 @@ import {
Tracer,
trace as otTrace,
} from "@opentelemetry/api";
import { SpanGraph, SpanGraphNode } from "./spanGraphModel";
import { SpanGraph, SpanGraphNode } from "./spanGraphModel.js";

/**
* A mock tracer useful for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { TracerOptions, TracerProvider, trace } from "@opentelemetry/api";
import { TestTracer } from "./testTracer";
import { TestTracer } from "./testTracer.js";

// This must be the same as the default tracer name supplied from @azure/core-tracing.
const TRACER_NAME = "azure/core-tracing";
Expand Down
Loading

0 comments on commit f6904d7

Please sign in to comment.