Skip to content

Commit c6824e0

Browse files
authored
Replace assert imports with chai in AppConfiguration (Azure#19245)
* Replace assert imports with chai * Fixing types errors * Fixing tests * Catch not recognized error * Rushx format * Casting for OperationOptions & {keyFilter ?: string} * Feature flag as ConfigurationSettingParam<string> instead of as any
1 parent 5deb6ce commit c6824e0

File tree

10 files changed

+29
-15
lines changed

10 files changed

+29
-15
lines changed

sdk/appconfiguration/app-configuration/rollup.base.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export function browserConfig(test = false) {
119119
cjs({
120120
namedExports: {
121121
chai: ["assert", "expect", "use"],
122-
assert: ["ok", "equal", "strictEqual", "deepEqual", "fail", "throws", "notEqual"],
123122
events: ["EventEmitter"],
124123
...openTelemetryCommonJs()
125124
}

sdk/appconfiguration/app-configuration/test/internal/helpers.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
formatFieldsForSelect,
1414
serializeAsConfigurationSettingParam
1515
} from "../../src/internal/helpers";
16-
import * as assert from "assert";
16+
import { assert } from "chai";
1717
import {
1818
ConfigurationSetting,
19+
ConfigurationSettingParam,
1920
featureFlagContentType,
2021
HttpResponseField,
2122
HttpResponseFields,
@@ -155,7 +156,7 @@ describe("helper methods", () => {
155156
featureFlag.value = value as any;
156157
assert.deepEqual(
157158
serializeAsConfigurationSettingParam(featureFlag),
158-
featureFlag,
159+
(featureFlag as unknown) as ConfigurationSettingParam<string>,
159160
"setting was modified"
160161
);
161162
});
@@ -170,7 +171,7 @@ describe("helper methods", () => {
170171
setting.value = value as any;
171172
assert.deepEqual(
172173
serializeAsConfigurationSettingParam(setting),
173-
setting,
174+
setting as any,
174175
"setting was modified"
175176
);
176177
});

sdk/appconfiguration/app-configuration/test/internal/http.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Licensed under the MIT License.
66

77
import { parseSyncToken, SyncTokens } from "../../src/internal/synctokenpolicy";
8-
import * as assert from "assert";
8+
import { assert } from "chai";
99
import { AppConfigurationClient } from "../../src";
1010
import nock from "nock";
1111
import {

sdk/appconfiguration/app-configuration/test/internal/package.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import * as assert from "assert";
4+
import { assert } from "chai";
55
import { isNode } from "@azure/core-http";
66

77
import { packageVersion } from "../../src/appConfigurationClient";

sdk/appconfiguration/app-configuration/test/internal/tracingHelpers.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { createSpan, trace } from "../../src/internal/tracingHelpers";
55
import { Span, SpanStatus, SpanStatusCode } from "@azure/core-tracing";
66

7-
import * as assert from "assert";
7+
import { assert } from "chai";
88
import sinon from "sinon";
99
import { AppConfigurationClient } from "../../src/appConfigurationClient";
1010
import { AbortSignalLike, OperationOptions } from "@azure/core-http";
@@ -92,6 +92,9 @@ describe("tracingHelpers", () => {
9292

9393
assert.fail("Exception should have been thrown from `trace` since the inner action threw");
9494
} catch (err) {
95+
if (!(err instanceof Error)) {
96+
throw new Error("Error is not recognized");
97+
}
9598
assert.equal(err.message, "Purposefully thrown error");
9699
}
97100

@@ -172,15 +175,19 @@ describe("tracingHelpers", () => {
172175

173176
assert.deepEqual(traceData, {
174177
operationName: "listConfigurationSettings",
175-
options: { ...operationOptions, keyFilter: "ignored" }
178+
options: { ...operationOptions, keyFilter: "ignored" } as OperationOptions & {
179+
keyFilter?: string;
180+
}
176181
});
177182

178183
const it2 = appConfigurationClient.listRevisions({ keyFilter: "ignored", ...operationOptions });
179184
await it2.next();
180185

181186
assert.deepEqual(traceData, {
182187
operationName: "listRevisions",
183-
options: { ...operationOptions, keyFilter: "ignored" }
188+
options: { ...operationOptions, keyFilter: "ignored" } as OperationOptions & {
189+
keyFilter?: string;
190+
}
184191
});
185192
});
186193
});

sdk/appconfiguration/app-configuration/test/public/auth.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getTokenAuthenticationCredential,
88
CredsAndEndpoint
99
} from "./utils/testHelpers";
10-
import * as assert from "assert";
10+
import { assert } from "chai";
1111
import { Recorder } from "@azure-tools/test-recorder";
1212
import { Context } from "mocha";
1313

sdk/appconfiguration/app-configuration/test/public/etags.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
deleteKeyCompletely,
99
assertThrowsRestError
1010
} from "./utils/testHelpers";
11-
import * as assert from "assert";
11+
import { assert } from "chai";
1212
import { Recorder } from "@azure-tools/test-recorder";
1313
import { Context } from "mocha";
1414

sdk/appconfiguration/app-configuration/test/public/index.readonlytests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
startRecorder
1010
} from "./utils/testHelpers";
1111
import { AppConfigurationClient } from "../../src";
12-
import * as assert from "assert";
12+
import { assert } from "chai";
1313
import { Recorder } from "@azure-tools/test-recorder";
1414
import { Context } from "mocha";
1515

sdk/appconfiguration/app-configuration/test/public/throwOrNotThrow.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
assertThrowsRestError,
99
startRecorder
1010
} from "./utils/testHelpers";
11-
import * as assert from "assert";
11+
import { assert } from "chai";
1212
import { Recorder } from "@azure-tools/test-recorder";
1313
import { Context } from "mocha";
1414

sdk/appconfiguration/app-configuration/test/public/utils/testHelpers.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import {
1515
record,
1616
Recorder
1717
} from "@azure-tools/test-recorder";
18-
import * as assert from "assert";
18+
import { assert } from "chai";
1919

2020
import { DefaultAzureCredential, TokenCredential } from "@azure/identity";
21+
import { RestError } from "@azure/core-http";
2122

2223
let connectionStringNotPresentWarning = false;
2324
let tokenCredentialsNotPresentWarning = false;
@@ -144,7 +145,7 @@ export function assertEqualSettings(
144145
actual = actual.map((setting) => {
145146
return {
146147
key: setting.key,
147-
label: setting.label,
148+
label: setting.label || undefined,
148149
value: setting.value,
149150
isReadOnly: setting.isReadOnly
150151
};
@@ -162,6 +163,9 @@ export async function assertThrowsRestError(
162163
await testFunction();
163164
assert.fail(`${message}: No error thrown`);
164165
} catch (err) {
166+
if (!(err instanceof RestError)) {
167+
throw new Error("Error is not recognized");
168+
}
165169
if (err.name === "RestError") {
166170
assert.equal(expectedStatusCode, err.statusCode, message);
167171
return err;
@@ -181,6 +185,9 @@ export async function assertThrowsAbortError(
181185
await testFunction();
182186
assert.fail(`${message}: No error thrown`);
183187
} catch (e) {
188+
if (!(e instanceof Error)) {
189+
throw new Error("Error is not recognized");
190+
}
184191
if (isPlaybackMode() && (e.name === "FetchError" || e.name === "AbortError")) {
185192
return e;
186193
} else {

0 commit comments

Comments
 (0)