Skip to content

Commit 96a4fc5

Browse files
Merge branch 'main' into ConfigMap
2 parents af4e4a4 + bc5a930 commit 96a4fc5

36 files changed

+190
-303
lines changed

packages/common/client-utils/src/test/mocha/events.spec.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,7 @@ describe("CustomEventEmitter", () => {
258258
let count = 0;
259259
const listener = (): number => (count += 1);
260260
emitter.on("open", listener);
261-
assert.throws(
262-
() => emitter.on("open", listener),
263-
(e: Error) => validateAssertionError(e, /register.*twice.*open/),
264-
);
261+
assert.throws(() => emitter.on("open", listener), validateError(/register.*twice.*open/));
265262
// If error is caught, the listener should still fire once for the first registration
266263
emitter.emit("open");
267264
assert.strictEqual(count, 1);
@@ -276,7 +273,7 @@ describe("CustomEventEmitter", () => {
276273
emitter.emit(eventSymbol);
277274
assert.throws(
278275
() => emitter.on(eventSymbol, listener),
279-
(e: Error) => validateAssertionError(e, /register.*twice.*TestEvent/),
276+
validateError(/register.*twice.*TestEvent/),
280277
);
281278
});
282279
});
@@ -358,29 +355,28 @@ export class MyExposingClass {
358355
}
359356

360357
/**
361-
* Validates that an error thrown by assert() function has the expected message.
358+
* Validates that an error has the expected message.
362359
*
363-
* @param error - The error object thrown by `assert()` function.
364360
* @param expectedErrorMessage - The message that the error object should match.
365-
* @returns `true` if the message in the error object that was passed in matches the expected
366-
* message. Otherwise it throws an error.
361+
* @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
367362
*
368363
* @remarks
369-
* Similar to {@link @fluidframework/test-runtime-utils#validateAssertionError}.
370-
*
371-
* @internal
364+
* This does not work for asserts that get "tagging" see {@link @fluidframework/test-runtime-utils#validateAssertionError} for that.
365+
* This function exists here to avoid a dependency on `@fluidframework/test-runtime-utils` since this package cannot use it.
372366
*/
373-
function validateAssertionError(error: Error, expectedErrorMsg: string | RegExp): boolean {
374-
const actualMsg = error.message;
375-
if (
376-
typeof expectedErrorMsg === "string"
377-
? actualMsg !== expectedErrorMsg
378-
: !expectedErrorMsg.test(actualMsg)
379-
) {
380-
// This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
381-
// node assert library, which we don't want to do for this library because it's used in the browser.
382-
const message = `Unexpected assertion thrown\nActual: ${error.message}\nExpected: ${expectedErrorMsg}`;
383-
throw new Error(message);
384-
}
385-
return true;
367+
function validateError(expectedErrorMsg: string | RegExp): (error: Error) => true {
368+
return (error: Error) => {
369+
const actualMsg = error.message;
370+
if (
371+
typeof expectedErrorMsg === "string"
372+
? actualMsg !== expectedErrorMsg
373+
: !expectedErrorMsg.test(actualMsg)
374+
) {
375+
// This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
376+
// node assert library, which we don't want to do for this library because it's used in the browser.
377+
const message = `Unexpected assertion thrown\nActual: ${error.message}\nExpected: ${expectedErrorMsg}`;
378+
throw new Error(message);
379+
}
380+
return true;
381+
};
386382
}

packages/dds/sequence/src/test/sharedString.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
MockEmptyDeltaConnection,
2828
MockFluidDataStoreRuntime,
2929
MockStorage,
30-
validateAssertionError,
30+
validateAssertionError2 as validateAssertionError,
3131
} from "@fluidframework/test-runtime-utils/internal";
3232

3333
import { SharedStringFactory, type SharedString } from "../sequenceFactory.js";
@@ -253,8 +253,7 @@ describe("SharedString", () => {
253253
() => {
254254
sharedString.annotateMarker(simpleMarker, newIdProps);
255255
},
256-
(e: Error) =>
257-
validateAssertionError(e, "Cannot change the markerId of an existing marker"),
256+
validateAssertionError("Cannot change the markerId of an existing marker"),
258257
"Error from attempting to update marker was not thrown or was not the expected error",
259258
);
260259
});
@@ -273,8 +272,7 @@ describe("SharedString", () => {
273272
() => {
274273
sharedString.annotateMarker(simpleMarker, newIdProps);
275274
},
276-
(e: Error) =>
277-
validateAssertionError(e, "Cannot change the markerId of an existing marker"),
275+
validateAssertionError("Cannot change the markerId of an existing marker"),
278276
"Error from attempting to update marker was not thrown or was not the expected error",
279277
);
280278
});
@@ -293,8 +291,7 @@ describe("SharedString", () => {
293291
() => {
294292
sharedString.annotateMarker(simpleMarker, newIdProps);
295293
},
296-
(e: Error) =>
297-
validateAssertionError(e, "Cannot change the markerId of an existing marker"),
294+
validateAssertionError("Cannot change the markerId of an existing marker"),
298295
"Error from attempting to update marker was not thrown or was not the expected error",
299296
);
300297
});

packages/dds/shared-object-base/src/test/sharedObject.spec.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { isSerializedHandle } from "@fluidframework/runtime-utils/internal";
2222
import {
2323
MockFluidDataStoreRuntime,
2424
MockHandle,
25-
validateAssertionError,
25+
validateAssertionError2 as validateAssertionError,
2626
} from "@fluidframework/test-runtime-utils/internal";
2727
import sinon from "sinon";
2828

@@ -128,19 +128,15 @@ describe("SharedObject", () => {
128128
it("rejects slashes in id", () => {
129129
const invalidId = "beforeSlash/afterSlash";
130130
const codeBlock = (): SharedObject => new MySharedObject(invalidId);
131-
assert.throws(codeBlock, (e: Error) =>
132-
validateAssertionError(e, "Id cannot contain slashes"),
133-
);
131+
assert.throws(codeBlock, validateAssertionError("Id cannot contain slashes"));
134132
});
135133
});
136134

137135
describe("SharedObjectCore", () => {
138136
it("rejects slashes in id", () => {
139137
const invalidId = "beforeSlash/afterSlash";
140138
const codeBlock = (): SharedObjectCore => new MySharedObjectCore({ id: invalidId });
141-
assert.throws(codeBlock, (e: Error) =>
142-
validateAssertionError(e, "Id cannot contain slashes"),
143-
);
139+
assert.throws(codeBlock, validateAssertionError("Id cannot contain slashes"));
144140
});
145141

146142
describe("handle encoding in submitLocalMessage", () => {

packages/dds/tree/src/test/codec/codec.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Type } from "@sinclair/typebox";
99

1010
import { type IJsonCodec, withSchemaValidation } from "../../codec/index.js";
1111
import { FormatValidatorBasic } from "../../external-utilities/index.js";
12-
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
12+
import { validateAssertionError2 as validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
1313

1414
describe("Codec APIs", () => {
1515
describe("withSchemaValidation", () => {
@@ -22,14 +22,14 @@ describe("Codec APIs", () => {
2222
it("on encode", () => {
2323
assert.throws(
2424
() => codec.encode("bad data" as unknown as number),
25-
(error: Error) => validateAssertionError(error, /Encoded schema should validate/),
25+
validateAssertionError(/Encoded schema should validate/),
2626
);
2727
});
2828

2929
it("on decode", () => {
3030
assert.throws(
3131
() => codec.decode("bad data" as unknown as number),
32-
(error: Error) => validateAssertionError(error, /Encoded schema should validate/),
32+
validateAssertionError(/Encoded schema should validate/),
3333
);
3434
});
3535
});

packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/chunkDecoding.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { strict as assert } from "node:assert";
77

88
import { compareArrays } from "@fluidframework/core-utils/internal";
9-
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
9+
import { validateAssertionError2 as validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
1010

1111
// eslint-disable-next-line import-x/no-internal-modules
1212
import { BasicChunk } from "../../../../feature-libraries/chunked-forest/basicChunk.js";
@@ -564,11 +564,9 @@ describe("chunkDecoding", () => {
564564

565565
assert.throws(
566566
() => decoder.decode([], stream),
567-
(error: Error) =>
568-
validateAssertionError(
569-
error,
570-
"incremental decoder not available for incremental field decoding",
571-
),
567+
validateAssertionError(
568+
"incremental decoder not available for incremental field decoding",
569+
),
572570
);
573571
});
574572

@@ -590,7 +588,7 @@ describe("chunkDecoding", () => {
590588

591589
assert.throws(
592590
() => decoder.decode([], stream),
593-
(error: Error) => validateAssertionError(error, /Unsupported FieldBatchFormatVersion/),
591+
validateAssertionError(/Unsupported FieldBatchFormatVersion/),
594592
);
595593
});
596594
});

packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/codecs.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { strict as assert } from "node:assert";
7-
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
7+
import { validateAssertionError2 as validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
88
import {
99
makeFieldBatchCodec,
1010
// eslint-disable-next-line import-x/no-internal-modules
@@ -96,7 +96,7 @@ describe("makeFieldBatchCodec", () => {
9696

9797
assert.throws(
9898
() => codec.encode([input], context),
99-
(error: Error) => validateAssertionError(error, /Unsupported FieldBatchFormatVersion/),
99+
validateAssertionError(/Unsupported FieldBatchFormatVersion/),
100100
);
101101
});
102102
});

packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/compressedEncode.spec.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { strict as assert, fail } from "node:assert";
88
import { compareArrays } from "@fluidframework/core-utils/internal";
99
import {
1010
MockHandle,
11-
validateAssertionError,
11+
validateAssertionError2 as validateAssertionError,
1212
} from "@fluidframework/test-runtime-utils/internal";
1313

1414
import {
@@ -498,16 +498,11 @@ describe("compressedEncode", () => {
498498
fieldBatchVersion,
499499
);
500500

501-
assert.throws(
502-
() => {
503-
checkFieldEncode(incrementalFieldEncoder, context, [{ type: brand("foo") }]);
504-
},
505-
(error: Error) =>
506-
validateAssertionError(
507-
error,
508-
"incremental encoder must be defined to use incrementalFieldEncoder",
509-
),
510-
);
501+
assert.throws(() => {
502+
checkFieldEncode(incrementalFieldEncoder, context, [{ type: brand("foo") }]);
503+
}, validateAssertionError(
504+
"incremental encoder must be defined to use incrementalFieldEncoder",
505+
));
511506
});
512507

513508
it("has correct shape", () => {
@@ -527,7 +522,7 @@ describe("compressedEncode", () => {
527522

528523
assert.throws(
529524
() => checkFieldEncode(incrementalFieldEncoder, context, []),
530-
(error: Error) => validateAssertionError(error, /Unsupported FieldBatchFormatVersion/),
525+
validateAssertionError(/Unsupported FieldBatchFormatVersion/),
531526
);
532527
});
533528
});

packages/dds/tree/src/test/feature-libraries/flex-tree/lazyField.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { strict as assert } from "node:assert";
99

10-
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
10+
import { validateAssertionError2 as validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
1111

1212
import {
1313
type FieldAnchor,
@@ -93,13 +93,11 @@ describe("LazyField", () => {
9393
cursor.free();
9494
assert.throws(
9595
() => optionalField.editor.set(undefined, optionalField.length === undefined),
96-
(e: Error) =>
97-
validateAssertionError(e, /only allowed on fields with TreeStatus.InDocument status/),
96+
validateAssertionError(/only allowed on fields with TreeStatus.InDocument status/),
9897
);
9998
assert.throws(
10099
() => valueField.editor.set(mapTreeFromCursor(singleJsonCursor({}))),
101-
(e: Error) =>
102-
validateAssertionError(e, /only allowed on fields with TreeStatus.InDocument status/),
100+
validateAssertionError(/only allowed on fields with TreeStatus.InDocument status/),
103101
);
104102
});
105103

packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizerCodec.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { strict as assert } from "node:assert";
77

88
import {
9-
validateAssertionError,
9+
validateAssertionError2 as validateAssertionError,
1010
validateUsageError,
1111
} from "@fluidframework/test-runtime-utils/internal";
1212

@@ -159,7 +159,7 @@ describe("ForestSummarizerCodec", () => {
159159
} as unknown as Format,
160160
context,
161161
),
162-
(e: Error) => validateAssertionError(e, "Encoded schema should validate"),
162+
validateAssertionError("Encoded schema should validate"),
163163
);
164164
});
165165

@@ -175,7 +175,7 @@ describe("ForestSummarizerCodec", () => {
175175
} as unknown as Format,
176176
context,
177177
),
178-
(e: Error) => validateAssertionError(e, "Encoded schema should validate"),
178+
validateAssertionError("Encoded schema should validate"),
179179
);
180180
});
181181
});

packages/dds/tree/src/test/feature-libraries/forest-summary/incrementalSummaryBuilder.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { stringToBuffer } from "@fluid-internal/client-utils";
99
import type { IExperimentalIncrementalSummaryContext } from "@fluidframework/runtime-definitions/internal";
1010
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
1111
import { SummaryType, type ISnapshotTree } from "@fluidframework/driver-definitions/internal";
12-
import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
12+
import { validateAssertionError2 as validateAssertionError } from "@fluidframework/test-runtime-utils/internal";
1313

1414
import {
1515
ForestIncrementalSummaryBehavior,
@@ -159,7 +159,7 @@ describe("ForestIncrementalSummaryBuilder", () => {
159159
incrementalSummaryContext,
160160
stringify,
161161
}),
162-
(error: Error) => validateAssertionError(error, /Already tracking/),
162+
validateAssertionError(/Already tracking/),
163163
);
164164
assert.equal(builder.forestSummaryState, ForestSummaryTrackingState.Tracking);
165165
});
@@ -225,7 +225,7 @@ describe("ForestIncrementalSummaryBuilder", () => {
225225
incrementalSummaryContext: localIncrementalSummaryContext,
226226
forestSummaryContent: mockForestSummaryContent,
227227
}),
228-
(error: Error) => validateAssertionError(error, /Not tracking/),
228+
validateAssertionError(/Not tracking/),
229229
);
230230
assert.equal(builder.forestSummaryState, ForestSummaryTrackingState.ReadyToTrack);
231231
});
@@ -350,7 +350,7 @@ describe("ForestIncrementalSummaryBuilder", () => {
350350
const builder = createIncrementalSummaryBuilder();
351351
assert.throws(
352352
() => builder.encodeIncrementalField(testCursor, () => mockEncodedChunk),
353-
(error: Error) => validateAssertionError(error, /Not tracking/),
353+
validateAssertionError(/Not tracking/),
354354
);
355355
});
356356

@@ -570,7 +570,7 @@ describe("ForestIncrementalSummaryBuilder", () => {
570570
builder.decodeIncrementalChunk(999 as ChunkReferenceId, (encoded) => {
571571
return getMockChunk();
572572
}),
573-
(error: Error) => validateAssertionError(error, "Encoded incremental chunk not found"),
573+
validateAssertionError("Encoded incremental chunk not found"),
574574
);
575575
});
576576
});

0 commit comments

Comments
 (0)