@fluidframework/test-runtime-utils 2.71.0 → 2.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export { MockHandle } from "./mockHandle.js";
11
11
  export { IMockContainerRuntimePendingMessage, MockContainerRuntime, IMockContainerRuntimeOptions, MockContainerRuntimeFactory, MockDeltaConnection, MockEmptyDeltaConnection, MockFluidDataStoreRuntime, MockObjectStorageService, MockQuorumClients, MockAudience, MockSharedObjectServices, IInternalMockRuntimeMessage, } from "./mocks.js";
12
12
  export { MockContainerRuntimeFactoryForReconnection, MockContainerRuntimeForReconnection, } from "./mocksForReconnection.js";
13
13
  export { MockStorage } from "./mockStorage.js";
14
- export { validateAssertionError } from "./validateAssertionError.js";
14
+ export { validateAssertionError, validateUsageError, validateTypeError, validateError, } from "./validateAssertionError.js";
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,mCAAmC,EACnC,oBAAoB,EACpB,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,EACxB,2BAA2B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,0CAA0C,EAC1C,mCAAmC,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACN,mCAAmC,EACnC,oBAAoB,EACpB,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,EACxB,2BAA2B,GAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,0CAA0C,EAC1C,mCAAmC,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,6BAA6B,CAAC"}
package/lib/index.js CHANGED
@@ -10,5 +10,5 @@ export { MockHandle } from "./mockHandle.js";
10
10
  export { MockContainerRuntime, MockContainerRuntimeFactory, MockDeltaConnection, MockEmptyDeltaConnection, MockFluidDataStoreRuntime, MockObjectStorageService, MockQuorumClients, MockAudience, MockSharedObjectServices, } from "./mocks.js";
11
11
  export { MockContainerRuntimeFactoryForReconnection, MockContainerRuntimeForReconnection, } from "./mocksForReconnection.js";
12
12
  export { MockStorage } from "./mockStorage.js";
13
- export { validateAssertionError } from "./validateAssertionError.js";
13
+ export { validateAssertionError, validateUsageError, validateTypeError, validateError, } from "./validateAssertionError.js";
14
14
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAEN,oBAAoB,EAEpB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,GAExB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,0CAA0C,EAC1C,mCAAmC,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { deepFreeze } from \"./deepFreeze.js\";\nexport { IInsecureUser } from \"./insecureUsers.js\";\nexport { InsecureTokenProvider } from \"./insecureTokenProvider.js\";\nexport { MockFluidDataStoreContext } from \"./mocksDataStoreContext.js\";\nexport { MockDeltaManager, MockDeltaQueue } from \"./mockDeltas.js\";\nexport { MockHandle } from \"./mockHandle.js\";\nexport {\n\tIMockContainerRuntimePendingMessage,\n\tMockContainerRuntime,\n\tIMockContainerRuntimeOptions,\n\tMockContainerRuntimeFactory,\n\tMockDeltaConnection,\n\tMockEmptyDeltaConnection,\n\tMockFluidDataStoreRuntime,\n\tMockObjectStorageService,\n\tMockQuorumClients,\n\tMockAudience,\n\tMockSharedObjectServices,\n\tIInternalMockRuntimeMessage,\n} from \"./mocks.js\";\nexport {\n\tMockContainerRuntimeFactoryForReconnection,\n\tMockContainerRuntimeForReconnection,\n} from \"./mocksForReconnection.js\";\nexport { MockStorage } from \"./mockStorage.js\";\nexport { validateAssertionError } from \"./validateAssertionError.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAEN,oBAAoB,EAEpB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,GAExB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,0CAA0C,EAC1C,mCAAmC,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACN,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACb,MAAM,6BAA6B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { deepFreeze } from \"./deepFreeze.js\";\nexport { IInsecureUser } from \"./insecureUsers.js\";\nexport { InsecureTokenProvider } from \"./insecureTokenProvider.js\";\nexport { MockFluidDataStoreContext } from \"./mocksDataStoreContext.js\";\nexport { MockDeltaManager, MockDeltaQueue } from \"./mockDeltas.js\";\nexport { MockHandle } from \"./mockHandle.js\";\nexport {\n\tIMockContainerRuntimePendingMessage,\n\tMockContainerRuntime,\n\tIMockContainerRuntimeOptions,\n\tMockContainerRuntimeFactory,\n\tMockDeltaConnection,\n\tMockEmptyDeltaConnection,\n\tMockFluidDataStoreRuntime,\n\tMockObjectStorageService,\n\tMockQuorumClients,\n\tMockAudience,\n\tMockSharedObjectServices,\n\tIInternalMockRuntimeMessage,\n} from \"./mocks.js\";\nexport {\n\tMockContainerRuntimeFactoryForReconnection,\n\tMockContainerRuntimeForReconnection,\n} from \"./mocksForReconnection.js\";\nexport { MockStorage } from \"./mockStorage.js\";\nexport {\n\tvalidateAssertionError,\n\tvalidateUsageError,\n\tvalidateTypeError,\n\tvalidateError,\n} from \"./validateAssertionError.js\";\n"]}
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  /**
6
- * Validates that an error thrown by our assert() function has the expected message, or a
6
+ * Validates that an error thrown by our `assert()` function has the expected message, or a
7
7
  * short code that corresponds to that message.
8
8
  *
9
9
  * @remarks
@@ -12,13 +12,29 @@
12
12
  * before the policy-check tool replaces those strings with short codes, or after. Note that
13
13
  * it either returns true or throws an error (the behavior expected by NodeJS' `assert.throws()`).
14
14
  *
15
- * @param error - The error object thrown by our `assert()` function. Its `message` property could
16
- * be a short code, or the original string message coded into the `assert()`.
17
15
  * @param expectedErrorMessage - The message that the error object should match (either explicitly,
18
16
  * or because it contains a short code which maps to that message).
19
- * @returns `true` if the message in the error object that was passed in matches the expected
20
- * message. Otherwise it throws an error.
17
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
21
18
  * @internal
22
19
  */
23
- export declare function validateAssertionError(error: Error, expectedErrorMsg: string | RegExp): boolean;
20
+ export declare function validateAssertionError(expectedErrorMsg: string | RegExp): (error: Error) => true;
21
+ /**
22
+ * {@link validateError} for `UsageError`.
23
+ * @internal
24
+ */
25
+ export declare function validateUsageError(expectedErrorMsg: string | RegExp): (error: Error) => true;
26
+ /**
27
+ * {@link validateError} for `TypeError`.
28
+ * @internal
29
+ */
30
+ export declare function validateTypeError(expectedErrorMsg: string | RegExp): (error: Error) => true;
31
+ /**
32
+ * Validates that a specific kind of error was thrown with the expected message.
33
+ * @remarks
34
+ * Intended for use with NodeJS's `assert.throws`.
35
+ * @see {@link validateAssertionError}, {@link validateUsageError}, {@link validateTypeError} for more specialized versions.
36
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
37
+ * @internal
38
+ */
39
+ export declare function validateError(expectedErrorMsg: string | RegExp, errorType?: new (...args: any[]) => Error): (error: Error) => true;
24
40
  //# sourceMappingURL=validateAssertionError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateAssertionError.d.ts","sourceRoot":"","sources":["../src/validateAssertionError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAC/B,OAAO,CAqBT"}
1
+ {"version":3,"file":"validateAssertionError.d.ts","sourceRoot":"","sources":["../src/validateAssertionError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACrC,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAC/B,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAmBxB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAE5F;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAE3F;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,gBAAgB,EAAE,MAAM,GAAG,MAAM,EACjC,SAAS,GAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAa,GAC9C,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAaxB"}
@@ -2,9 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
6
+ import { assert } from "@fluidframework/core-utils/internal";
5
7
  import { shortCodeMap } from "./assertionShortCodesMap.js";
6
8
  /**
7
- * Validates that an error thrown by our assert() function has the expected message, or a
9
+ * Validates that an error thrown by our `assert()` function has the expected message, or a
8
10
  * short code that corresponds to that message.
9
11
  *
10
12
  * @remarks
@@ -13,31 +15,64 @@ import { shortCodeMap } from "./assertionShortCodesMap.js";
13
15
  * before the policy-check tool replaces those strings with short codes, or after. Note that
14
16
  * it either returns true or throws an error (the behavior expected by NodeJS' `assert.throws()`).
15
17
  *
16
- * @param error - The error object thrown by our `assert()` function. Its `message` property could
17
- * be a short code, or the original string message coded into the `assert()`.
18
18
  * @param expectedErrorMessage - The message that the error object should match (either explicitly,
19
19
  * or because it contains a short code which maps to that message).
20
- * @returns `true` if the message in the error object that was passed in matches the expected
21
- * message. Otherwise it throws an error.
20
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
22
21
  * @internal
23
22
  */
24
- export function validateAssertionError(error, expectedErrorMsg) {
25
- // Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.
26
- // Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.
27
- const split = error.message.split("\n");
28
- const possibleShortCode = split[0].trim();
29
- if (possibleShortCode in shortCodeMap) {
30
- split[0] = shortCodeMap[possibleShortCode];
31
- }
32
- const mappedMsg = split.join("\n");
33
- if (typeof expectedErrorMsg === "string"
34
- ? mappedMsg !== expectedErrorMsg
35
- : !expectedErrorMsg.test(mappedMsg)) {
36
- // This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
37
- // node assert library, which we don't want to do for this library because it's used in the browser.
38
- const message = `Unexpected assertion thrown\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\nExpected: ${expectedErrorMsg}`;
39
- throw new Error(message);
40
- }
41
- return true;
23
+ export function validateAssertionError(expectedErrorMsg) {
24
+ return (error) => {
25
+ // Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.
26
+ // Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.
27
+ const split = error.message.split("\n");
28
+ const possibleShortCode = split[0].trim();
29
+ if (possibleShortCode in shortCodeMap) {
30
+ split[0] = shortCodeMap[possibleShortCode];
31
+ }
32
+ const mappedMsg = split.join("\n");
33
+ if (testErrorMessage(mappedMsg, expectedErrorMsg)) {
34
+ // This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
35
+ // node assert library, which we don't want to do for this library because it's used in the browser.
36
+ const message = `Unexpected assertion thrown\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\nExpected: ${expectedErrorMsg}`;
37
+ throw new Error(message);
38
+ }
39
+ return true;
40
+ };
41
+ }
42
+ /**
43
+ * {@link validateError} for `UsageError`.
44
+ * @internal
45
+ */
46
+ export function validateUsageError(expectedErrorMsg) {
47
+ return validateError(expectedErrorMsg, UsageError);
48
+ }
49
+ /**
50
+ * {@link validateError} for `TypeError`.
51
+ * @internal
52
+ */
53
+ export function validateTypeError(expectedErrorMsg) {
54
+ return validateError(expectedErrorMsg, TypeError);
55
+ }
56
+ /**
57
+ * Validates that a specific kind of error was thrown with the expected message.
58
+ * @remarks
59
+ * Intended for use with NodeJS's `assert.throws`.
60
+ * @see {@link validateAssertionError}, {@link validateUsageError}, {@link validateTypeError} for more specialized versions.
61
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
62
+ * @internal
63
+ */
64
+ export function validateError(expectedErrorMsg, errorType = Error) {
65
+ return (error) => {
66
+ assert(error instanceof errorType, `Expected an error of type "${errorType.name}", but got "${error}"`);
67
+ if (testErrorMessage(error.message, expectedErrorMsg)) {
68
+ throw new Error(`Unexpected ${errorType.name} thrown\nActual: ${error.message}\nExpected: ${expectedErrorMsg}`);
69
+ }
70
+ return true;
71
+ };
72
+ }
73
+ function testErrorMessage(actualMessage, expectedErrorMsg) {
74
+ return typeof expectedErrorMsg === "string"
75
+ ? actualMessage !== expectedErrorMsg
76
+ : !expectedErrorMsg.test(actualMessage);
42
77
  }
43
78
  //# sourceMappingURL=validateAssertionError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateAssertionError.js","sourceRoot":"","sources":["../src/validateAssertionError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,sBAAsB,CACrC,KAAY,EACZ,gBAAiC;IAEjC,iHAAiH;IACjH,oIAAoI;IACpI,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,IAAI,iBAAiB,IAAI,YAAY,EAAE,CAAC;QACvC,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEnC,IACC,OAAO,gBAAgB,KAAK,QAAQ;QACnC,CAAC,CAAC,SAAS,KAAK,gBAAgB;QAChC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,EACnC,CAAC;QACF,6GAA6G;QAC7G,oGAAoG;QACpG,MAAM,OAAO,GAAG,wCAAwC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,MAAM,SAAS,KAAK,eAAe,gBAAgB,EAAE,CAAC;QAC5K,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { shortCodeMap } from \"./assertionShortCodesMap.js\";\n\n/**\n * Validates that an error thrown by our assert() function has the expected message, or a\n * short code that corresponds to that message.\n *\n * @remarks\n * The main use case for this is so tests that expect specific assert() calls to fail can\n * always do comparisons based on the original string message, and work whether they run\n * before the policy-check tool replaces those strings with short codes, or after. Note that\n * it either returns true or throws an error (the behavior expected by NodeJS' `assert.throws()`).\n *\n * @param error - The error object thrown by our `assert()` function. Its `message` property could\n * be a short code, or the original string message coded into the `assert()`.\n * @param expectedErrorMessage - The message that the error object should match (either explicitly,\n * or because it contains a short code which maps to that message).\n * @returns `true` if the message in the error object that was passed in matches the expected\n * message. Otherwise it throws an error.\n * @internal\n */\nexport function validateAssertionError(\n\terror: Error,\n\texpectedErrorMsg: string | RegExp,\n): boolean {\n\t// Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.\n\t// Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.\n\tconst split = error.message.split(\"\\n\");\n\tconst possibleShortCode = split[0].trim();\n\tif (possibleShortCode in shortCodeMap) {\n\t\tsplit[0] = shortCodeMap[possibleShortCode];\n\t}\n\tconst mappedMsg = split.join(\"\\n\");\n\n\tif (\n\t\ttypeof expectedErrorMsg === \"string\"\n\t\t\t? mappedMsg !== expectedErrorMsg\n\t\t\t: !expectedErrorMsg.test(mappedMsg)\n\t) {\n\t\t// This throws an Error instead of an AssertionError because AssertionError would require a dependency on the\n\t\t// node assert library, which we don't want to do for this library because it's used in the browser.\n\t\tconst message = `Unexpected assertion thrown\\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\\nExpected: ${expectedErrorMsg}`;\n\t\tthrow new Error(message);\n\t}\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"validateAssertionError.js","sourceRoot":"","sources":["../src/validateAssertionError.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CACrC,gBAAiC;IAEjC,OAAO,CAAC,KAAY,EAAE,EAAE;QACvB,iHAAiH;QACjH,oIAAoI;QACpI,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,iBAAiB,IAAI,YAAY,EAAE,CAAC;YACvC,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEnC,IAAI,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC;YACnD,6GAA6G;YAC7G,oGAAoG;YACpG,MAAM,OAAO,GAAG,wCAAwC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,MAAM,SAAS,KAAK,eAAe,gBAAgB,EAAE,CAAC;YAC5K,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,gBAAiC;IACnE,OAAO,aAAa,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,gBAAiC;IAClE,OAAO,aAAa,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC5B,gBAAiC,EACjC,YAA2C,KAAK;IAEhD,OAAO,CAAC,KAAY,EAAE,EAAE;QACvB,MAAM,CACL,KAAK,YAAY,SAAS,EAC1B,8BAA8B,SAAS,CAAC,IAAI,eAAe,KAAK,GAAG,CACnE,CAAC;QACF,IAAI,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CACd,cAAc,SAAS,CAAC,IAAI,oBAAoB,KAAK,CAAC,OAAO,eAAe,gBAAgB,EAAE,CAC9F,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,aAAqB,EAAE,gBAAiC;IACjF,OAAO,OAAO,gBAAgB,KAAK,QAAQ;QAC1C,CAAC,CAAC,aAAa,KAAK,gBAAgB;QACpC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { shortCodeMap } from \"./assertionShortCodesMap.js\";\n\n/**\n * Validates that an error thrown by our `assert()` function has the expected message, or a\n * short code that corresponds to that message.\n *\n * @remarks\n * The main use case for this is so tests that expect specific assert() calls to fail can\n * always do comparisons based on the original string message, and work whether they run\n * before the policy-check tool replaces those strings with short codes, or after. Note that\n * it either returns true or throws an error (the behavior expected by NodeJS' `assert.throws()`).\n *\n * @param expectedErrorMessage - The message that the error object should match (either explicitly,\n * or because it contains a short code which maps to that message).\n * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.\n * @internal\n */\nexport function validateAssertionError(\n\texpectedErrorMsg: string | RegExp,\n): (error: Error) => true {\n\treturn (error: Error) => {\n\t\t// Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.\n\t\t// Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.\n\t\tconst split = error.message.split(\"\\n\");\n\t\tconst possibleShortCode = split[0].trim();\n\t\tif (possibleShortCode in shortCodeMap) {\n\t\t\tsplit[0] = shortCodeMap[possibleShortCode];\n\t\t}\n\t\tconst mappedMsg = split.join(\"\\n\");\n\n\t\tif (testErrorMessage(mappedMsg, expectedErrorMsg)) {\n\t\t\t// This throws an Error instead of an AssertionError because AssertionError would require a dependency on the\n\t\t\t// node assert library, which we don't want to do for this library because it's used in the browser.\n\t\t\tconst message = `Unexpected assertion thrown\\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\\nExpected: ${expectedErrorMsg}`;\n\t\t\tthrow new Error(message);\n\t\t}\n\t\treturn true;\n\t};\n}\n\n/**\n * {@link validateError} for `UsageError`.\n * @internal\n */\nexport function validateUsageError(expectedErrorMsg: string | RegExp): (error: Error) => true {\n\treturn validateError(expectedErrorMsg, UsageError);\n}\n\n/**\n * {@link validateError} for `TypeError`.\n * @internal\n */\nexport function validateTypeError(expectedErrorMsg: string | RegExp): (error: Error) => true {\n\treturn validateError(expectedErrorMsg, TypeError);\n}\n\n/**\n * Validates that a specific kind of error was thrown with the expected message.\n * @remarks\n * Intended for use with NodeJS's `assert.throws`.\n * @see {@link validateAssertionError}, {@link validateUsageError}, {@link validateTypeError} for more specialized versions.\n * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.\n * @internal\n */\nexport function validateError(\n\texpectedErrorMsg: string | RegExp,\n\terrorType: new (...args: any[]) => Error = Error,\n): (error: Error) => true {\n\treturn (error: Error) => {\n\t\tassert(\n\t\t\terror instanceof errorType,\n\t\t\t`Expected an error of type \"${errorType.name}\", but got \"${error}\"`,\n\t\t);\n\t\tif (testErrorMessage(error.message, expectedErrorMsg)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Unexpected ${errorType.name} thrown\\nActual: ${error.message}\\nExpected: ${expectedErrorMsg}`,\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t};\n}\n\nfunction testErrorMessage(actualMessage: string, expectedErrorMsg: string | RegExp): boolean {\n\treturn typeof expectedErrorMsg === \"string\"\n\t\t? actualMessage !== expectedErrorMsg\n\t\t: !expectedErrorMsg.test(actualMessage);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/test-runtime-utils",
3
- "version": "2.71.0",
3
+ "version": "2.73.0",
4
4
  "description": "Fluid runtime test utilities",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -69,31 +69,31 @@
69
69
  "temp-directory": "nyc/.nyc_output"
70
70
  },
71
71
  "dependencies": {
72
- "@fluid-internal/client-utils": "~2.71.0",
73
- "@fluidframework/container-definitions": "~2.71.0",
74
- "@fluidframework/container-runtime-definitions": "~2.71.0",
75
- "@fluidframework/core-interfaces": "~2.71.0",
76
- "@fluidframework/core-utils": "~2.71.0",
77
- "@fluidframework/datastore-definitions": "~2.71.0",
78
- "@fluidframework/driver-definitions": "~2.71.0",
79
- "@fluidframework/driver-utils": "~2.71.0",
80
- "@fluidframework/id-compressor": "~2.71.0",
81
- "@fluidframework/routerlicious-driver": "~2.71.0",
82
- "@fluidframework/runtime-definitions": "~2.71.0",
83
- "@fluidframework/runtime-utils": "~2.71.0",
84
- "@fluidframework/telemetry-utils": "~2.71.0",
72
+ "@fluid-internal/client-utils": "~2.73.0",
73
+ "@fluidframework/container-definitions": "~2.73.0",
74
+ "@fluidframework/container-runtime-definitions": "~2.73.0",
75
+ "@fluidframework/core-interfaces": "~2.73.0",
76
+ "@fluidframework/core-utils": "~2.73.0",
77
+ "@fluidframework/datastore-definitions": "~2.73.0",
78
+ "@fluidframework/driver-definitions": "~2.73.0",
79
+ "@fluidframework/driver-utils": "~2.73.0",
80
+ "@fluidframework/id-compressor": "~2.73.0",
81
+ "@fluidframework/routerlicious-driver": "~2.73.0",
82
+ "@fluidframework/runtime-definitions": "~2.73.0",
83
+ "@fluidframework/runtime-utils": "~2.73.0",
84
+ "@fluidframework/telemetry-utils": "~2.73.0",
85
85
  "jsrsasign": "^11.0.0",
86
86
  "uuid": "^11.1.0"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@arethetypeswrong/cli": "^0.17.1",
90
90
  "@biomejs/biome": "~1.9.3",
91
- "@fluid-internal/mocha-test-setup": "~2.71.0",
92
- "@fluid-tools/build-cli": "^0.58.3",
91
+ "@fluid-internal/mocha-test-setup": "~2.73.0",
92
+ "@fluid-tools/build-cli": "^0.60.0",
93
93
  "@fluidframework/build-common": "^2.0.3",
94
- "@fluidframework/build-tools": "^0.58.3",
95
- "@fluidframework/eslint-config-fluid": "^7.0.0",
96
- "@fluidframework/test-runtime-utils-previous": "npm:@fluidframework/test-runtime-utils@2.70.0",
94
+ "@fluidframework/build-tools": "^0.60.0",
95
+ "@fluidframework/eslint-config-fluid": "~2.73.0",
96
+ "@fluidframework/test-runtime-utils-previous": "npm:@fluidframework/test-runtime-utils@2.71.0",
97
97
  "@microsoft/api-extractor": "7.52.11",
98
98
  "@types/jsrsasign": "^10.5.12",
99
99
  "@types/mocha": "^10.0.10",
@@ -1012,7 +1012,6 @@ export const shortCodeMap = {
1012
1012
  "0x7a9": "Collision during index update",
1013
1013
  "0x7aa": "Unknown removed node ID",
1014
1014
  "0x7af": "Destination must be a new empty detached field",
1015
- "0x7b5": "kind must be FieldKindWithEditor",
1016
1015
  "0x7b6": "Attach source field must be different from current field",
1017
1016
  "0x7b7": "Attach source field must exist",
1018
1017
  "0x7b8": "Attach must consume all nodes in source field",
@@ -1157,16 +1156,6 @@ export const shortCodeMap = {
1157
1156
  "0x8cd": "detached node should exist",
1158
1157
  "0x8ce": "Both replace replaces should not be undefined",
1159
1158
  "0x8cf": "Both replace replaces should not be undefined",
1160
- "0x8d0": "Multiple detached nodes",
1161
- "0x8d1": "Multiple attached nodes",
1162
- "0x8d2": "Invalid change: pin must have a reserved detach ID",
1163
- "0x8d3": "Invalid reserved detach ID",
1164
- "0x8d4": "Invalid change: unexpected reserved detach ID on a change that detaches a node from the field",
1165
- "0x8d5": "Invalid change: attach must have a reserved detach ID",
1166
- "0x8d6": "Invalid reserved detach ID",
1167
- "0x8d7": "Invalid change: unexpected reserved detach ID on a change that detaches a node from the field",
1168
- "0x8d8": "Invalid detach ID",
1169
- "0x8d9": "Invalid detach ID",
1170
1159
  "0x8da": "Unexpected node changeset collision",
1171
1160
  "0x8db": "Cannot peek length unless both mark queues are non-empty",
1172
1161
  "0x8dc": "Unexpected collision of new node changes",
@@ -1201,7 +1190,6 @@ export const shortCodeMap = {
1201
1190
  "0x907": "unknown op type",
1202
1191
  "0x908": "unknon type of op",
1203
1192
  "0x909": "should not be called",
1204
- "0x90e": "Unknown format version",
1205
1193
  "0x911": "Invalid operation on a disposed TreeCheckout",
1206
1194
  "0x916": "invalid value",
1207
1195
  "0x921": "Expected a leaf schema.",
@@ -1247,7 +1235,6 @@ export const shortCodeMap = {
1247
1235
  "0x962": "overwriting wrong cache",
1248
1236
  "0x963": "Invalid InternalTreeNode",
1249
1237
  "0x964": "A tagged change should only contain the tagged revision",
1250
- "0x965": "Implicit revision should be provided",
1251
1238
  "0x966": "Client id should be present and should be of type string",
1252
1239
  "0x967": "Received message from user not in the quorumClients",
1253
1240
  "0x969": "not connected yet",
@@ -1351,7 +1338,6 @@ export const shortCodeMap = {
1351
1338
  "0x9f4": "Impactful cell rename must target empty cell",
1352
1339
  "0x9f5": "Rename mark must have cell ID",
1353
1340
  "0x9f6": "Expected empty cell",
1354
- "0x9f7": "Rename must have idOverride",
1355
1341
  "0x9f8": "Rename must have idOverride",
1356
1342
  "0x9f9": "Renames should only target empty cells",
1357
1343
  "0x9fe": "node id should be an absolute route with child id part",
@@ -1598,7 +1584,6 @@ export const shortCodeMap = {
1598
1584
  "0xb28": "missing schema",
1599
1585
  "0xb29": "Expected defined output ID",
1600
1586
  "0xb2a": "Revision must be defined",
1601
- "0xb2b": "Mark type: NoopMarkType should not be encoded.",
1602
1587
  "0xb2c": "Mark type: NoopMarkType should not be encoded.",
1603
1588
  "0xb2d": "Unable to split mark due to lengths",
1604
1589
  "0xb2e": "missing schema for type in cursor",
@@ -1791,7 +1776,6 @@ export const shortCodeMap = {
1791
1776
  "0xc15": "Expected ObjectNodeStoredSchema",
1792
1777
  "0xc16": "missing schema for array node",
1793
1778
  "0xc17": "Expected MapNodeStoredSchema",
1794
- "0xc19": "Expected FieldSchemaAlpha",
1795
1779
  "0xc1a": "Expected MapNodeStoredSchema",
1796
1780
  "0xc1b": "Expected at least two types",
1797
1781
  "0xc1e": "Expected a constructed node to be an object",
@@ -1911,5 +1895,12 @@ export const shortCodeMap = {
1911
1895
  "0xc99": "Registered version is not less than the current version.",
1912
1896
  "0xc9a": "Presence capabilities should be empty.",
1913
1897
  "0xc9b": "Presence extension called without own compatibility details",
1914
- "0xc9c": "Data store context does not implement ContainerExtensionProvider"
1898
+ "0xc9c": "Data store context does not implement ContainerExtensionProvider",
1899
+ "0xc9d": "missing schema",
1900
+ "0xc9e": "Invalid configuration class constructed.",
1901
+ "0xc9f": "Unsupported FieldBatchFormatVersion for incremental chunks; must be v2 or higher",
1902
+ "0xca0": "Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher",
1903
+ "0xca1": "Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher",
1904
+ "0xca2": "localOpActivity must be undefined when entering rollback",
1905
+ "0xca3": "localOpActivity must be undefined when entering applyStashedOp"
1915
1906
  };
package/src/index.ts CHANGED
@@ -28,4 +28,9 @@ export {
28
28
  MockContainerRuntimeForReconnection,
29
29
  } from "./mocksForReconnection.js";
30
30
  export { MockStorage } from "./mockStorage.js";
31
- export { validateAssertionError } from "./validateAssertionError.js";
31
+ export {
32
+ validateAssertionError,
33
+ validateUsageError,
34
+ validateTypeError,
35
+ validateError,
36
+ } from "./validateAssertionError.js";
@@ -3,10 +3,12 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
+ import { assert } from "@fluidframework/core-utils/internal";
6
8
  import { shortCodeMap } from "./assertionShortCodesMap.js";
7
9
 
8
10
  /**
9
- * Validates that an error thrown by our assert() function has the expected message, or a
11
+ * Validates that an error thrown by our `assert()` function has the expected message, or a
10
12
  * short code that corresponds to that message.
11
13
  *
12
14
  * @remarks
@@ -15,36 +17,78 @@ import { shortCodeMap } from "./assertionShortCodesMap.js";
15
17
  * before the policy-check tool replaces those strings with short codes, or after. Note that
16
18
  * it either returns true or throws an error (the behavior expected by NodeJS' `assert.throws()`).
17
19
  *
18
- * @param error - The error object thrown by our `assert()` function. Its `message` property could
19
- * be a short code, or the original string message coded into the `assert()`.
20
20
  * @param expectedErrorMessage - The message that the error object should match (either explicitly,
21
21
  * or because it contains a short code which maps to that message).
22
- * @returns `true` if the message in the error object that was passed in matches the expected
23
- * message. Otherwise it throws an error.
22
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
24
23
  * @internal
25
24
  */
26
25
  export function validateAssertionError(
27
- error: Error,
28
26
  expectedErrorMsg: string | RegExp,
29
- ): boolean {
30
- // Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.
31
- // Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.
32
- const split = error.message.split("\n");
33
- const possibleShortCode = split[0].trim();
34
- if (possibleShortCode in shortCodeMap) {
35
- split[0] = shortCodeMap[possibleShortCode];
36
- }
37
- const mappedMsg = split.join("\n");
27
+ ): (error: Error) => true {
28
+ return (error: Error) => {
29
+ // Asserts with custom debugMessageBuilder put extra content on the second line of the message, even when tagged.
30
+ // Thus extract the first line, which will be the assert tag if there is one, and replace it with the message from the shortCodeMap.
31
+ const split = error.message.split("\n");
32
+ const possibleShortCode = split[0].trim();
33
+ if (possibleShortCode in shortCodeMap) {
34
+ split[0] = shortCodeMap[possibleShortCode];
35
+ }
36
+ const mappedMsg = split.join("\n");
38
37
 
39
- if (
40
- typeof expectedErrorMsg === "string"
41
- ? mappedMsg !== expectedErrorMsg
42
- : !expectedErrorMsg.test(mappedMsg)
43
- ) {
44
- // This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
45
- // node assert library, which we don't want to do for this library because it's used in the browser.
46
- const message = `Unexpected assertion thrown\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\nExpected: ${expectedErrorMsg}`;
47
- throw new Error(message);
48
- }
49
- return true;
38
+ if (testErrorMessage(mappedMsg, expectedErrorMsg)) {
39
+ // This throws an Error instead of an AssertionError because AssertionError would require a dependency on the
40
+ // node assert library, which we don't want to do for this library because it's used in the browser.
41
+ const message = `Unexpected assertion thrown\nActual: ${error.message === mappedMsg ? error.message : `${error.message} ('${mappedMsg}')}`}\nExpected: ${expectedErrorMsg}`;
42
+ throw new Error(message);
43
+ }
44
+ return true;
45
+ };
46
+ }
47
+
48
+ /**
49
+ * {@link validateError} for `UsageError`.
50
+ * @internal
51
+ */
52
+ export function validateUsageError(expectedErrorMsg: string | RegExp): (error: Error) => true {
53
+ return validateError(expectedErrorMsg, UsageError);
54
+ }
55
+
56
+ /**
57
+ * {@link validateError} for `TypeError`.
58
+ * @internal
59
+ */
60
+ export function validateTypeError(expectedErrorMsg: string | RegExp): (error: Error) => true {
61
+ return validateError(expectedErrorMsg, TypeError);
62
+ }
63
+
64
+ /**
65
+ * Validates that a specific kind of error was thrown with the expected message.
66
+ * @remarks
67
+ * Intended for use with NodeJS's `assert.throws`.
68
+ * @see {@link validateAssertionError}, {@link validateUsageError}, {@link validateTypeError} for more specialized versions.
69
+ * @returns an error validation function suitable for use with NodeJS's `assert.throws()`.
70
+ * @internal
71
+ */
72
+ export function validateError(
73
+ expectedErrorMsg: string | RegExp,
74
+ errorType: new (...args: any[]) => Error = Error,
75
+ ): (error: Error) => true {
76
+ return (error: Error) => {
77
+ assert(
78
+ error instanceof errorType,
79
+ `Expected an error of type "${errorType.name}", but got "${error}"`,
80
+ );
81
+ if (testErrorMessage(error.message, expectedErrorMsg)) {
82
+ throw new Error(
83
+ `Unexpected ${errorType.name} thrown\nActual: ${error.message}\nExpected: ${expectedErrorMsg}`,
84
+ );
85
+ }
86
+ return true;
87
+ };
88
+ }
89
+
90
+ function testErrorMessage(actualMessage: string, expectedErrorMsg: string | RegExp): boolean {
91
+ return typeof expectedErrorMsg === "string"
92
+ ? actualMessage !== expectedErrorMsg
93
+ : !expectedErrorMsg.test(actualMessage);
50
94
  }