@fluidframework/test-runtime-utils 2.72.0 → 2.74.0-365691
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/CHANGELOG.md +4 -0
- package/dist/assertionShortCodesMap.d.ts +7 -15
- package/dist/assertionShortCodesMap.d.ts.map +1 -1
- package/dist/assertionShortCodesMap.js +8 -16
- package/dist/assertionShortCodesMap.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/validateAssertionError.d.ts +22 -6
- package/dist/validateAssertionError.d.ts.map +1 -1
- package/dist/validateAssertionError.js +62 -24
- package/dist/validateAssertionError.js.map +1 -1
- package/lib/assertionShortCodesMap.d.ts +7 -15
- package/lib/assertionShortCodesMap.d.ts.map +1 -1
- package/lib/assertionShortCodesMap.js +8 -16
- package/lib/assertionShortCodesMap.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/validateAssertionError.d.ts +22 -6
- package/lib/validateAssertionError.d.ts.map +1 -1
- package/lib/validateAssertionError.js +58 -23
- package/lib/validateAssertionError.js.map +1 -1
- package/package.json +17 -17
- package/src/assertionShortCodesMap.ts +8 -16
- package/src/index.ts +6 -1
- package/src/validateAssertionError.ts +70 -26
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
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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,E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6B,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
|
|
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(
|
|
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;
|
|
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
|
|
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(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"validateAssertionError.js","sourceRoot":"","sources":["../src/validateAssertionError.ts"],"names":[],"mappings":"AAAA;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C,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.
|
|
3
|
+
"version": "2.74.0-365691",
|
|
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": "
|
|
73
|
-
"@fluidframework/container-definitions": "
|
|
74
|
-
"@fluidframework/container-runtime-definitions": "
|
|
75
|
-
"@fluidframework/core-interfaces": "
|
|
76
|
-
"@fluidframework/core-utils": "
|
|
77
|
-
"@fluidframework/datastore-definitions": "
|
|
78
|
-
"@fluidframework/driver-definitions": "
|
|
79
|
-
"@fluidframework/driver-utils": "
|
|
80
|
-
"@fluidframework/id-compressor": "
|
|
81
|
-
"@fluidframework/routerlicious-driver": "
|
|
82
|
-
"@fluidframework/runtime-definitions": "
|
|
83
|
-
"@fluidframework/runtime-utils": "
|
|
84
|
-
"@fluidframework/telemetry-utils": "
|
|
72
|
+
"@fluid-internal/client-utils": "2.74.0-365691",
|
|
73
|
+
"@fluidframework/container-definitions": "2.74.0-365691",
|
|
74
|
+
"@fluidframework/container-runtime-definitions": "2.74.0-365691",
|
|
75
|
+
"@fluidframework/core-interfaces": "2.74.0-365691",
|
|
76
|
+
"@fluidframework/core-utils": "2.74.0-365691",
|
|
77
|
+
"@fluidframework/datastore-definitions": "2.74.0-365691",
|
|
78
|
+
"@fluidframework/driver-definitions": "2.74.0-365691",
|
|
79
|
+
"@fluidframework/driver-utils": "2.74.0-365691",
|
|
80
|
+
"@fluidframework/id-compressor": "2.74.0-365691",
|
|
81
|
+
"@fluidframework/routerlicious-driver": "2.74.0-365691",
|
|
82
|
+
"@fluidframework/runtime-definitions": "2.74.0-365691",
|
|
83
|
+
"@fluidframework/runtime-utils": "2.74.0-365691",
|
|
84
|
+
"@fluidframework/telemetry-utils": "2.74.0-365691",
|
|
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": "
|
|
91
|
+
"@fluid-internal/mocha-test-setup": "2.74.0-365691",
|
|
92
92
|
"@fluid-tools/build-cli": "^0.60.0",
|
|
93
93
|
"@fluidframework/build-common": "^2.0.3",
|
|
94
94
|
"@fluidframework/build-tools": "^0.60.0",
|
|
95
|
-
"@fluidframework/eslint-config-fluid": "
|
|
96
|
-
"@fluidframework/test-runtime-utils-previous": "npm:@fluidframework/test-runtime-utils@2.
|
|
95
|
+
"@fluidframework/eslint-config-fluid": "2.74.0-365691",
|
|
96
|
+
"@fluidframework/test-runtime-utils-previous": "npm:@fluidframework/test-runtime-utils@2.73.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",
|
|
@@ -1246,7 +1235,6 @@ export const shortCodeMap = {
|
|
|
1246
1235
|
"0x962": "overwriting wrong cache",
|
|
1247
1236
|
"0x963": "Invalid InternalTreeNode",
|
|
1248
1237
|
"0x964": "A tagged change should only contain the tagged revision",
|
|
1249
|
-
"0x965": "Implicit revision should be provided",
|
|
1250
1238
|
"0x966": "Client id should be present and should be of type string",
|
|
1251
1239
|
"0x967": "Received message from user not in the quorumClients",
|
|
1252
1240
|
"0x969": "not connected yet",
|
|
@@ -1350,7 +1338,6 @@ export const shortCodeMap = {
|
|
|
1350
1338
|
"0x9f4": "Impactful cell rename must target empty cell",
|
|
1351
1339
|
"0x9f5": "Rename mark must have cell ID",
|
|
1352
1340
|
"0x9f6": "Expected empty cell",
|
|
1353
|
-
"0x9f7": "Rename must have idOverride",
|
|
1354
1341
|
"0x9f8": "Rename must have idOverride",
|
|
1355
1342
|
"0x9f9": "Renames should only target empty cells",
|
|
1356
1343
|
"0x9fe": "node id should be an absolute route with child id part",
|
|
@@ -1597,7 +1584,6 @@ export const shortCodeMap = {
|
|
|
1597
1584
|
"0xb28": "missing schema",
|
|
1598
1585
|
"0xb29": "Expected defined output ID",
|
|
1599
1586
|
"0xb2a": "Revision must be defined",
|
|
1600
|
-
"0xb2b": "Mark type: NoopMarkType should not be encoded.",
|
|
1601
1587
|
"0xb2c": "Mark type: NoopMarkType should not be encoded.",
|
|
1602
1588
|
"0xb2d": "Unable to split mark due to lengths",
|
|
1603
1589
|
"0xb2e": "missing schema for type in cursor",
|
|
@@ -1790,7 +1776,6 @@ export const shortCodeMap = {
|
|
|
1790
1776
|
"0xc15": "Expected ObjectNodeStoredSchema",
|
|
1791
1777
|
"0xc16": "missing schema for array node",
|
|
1792
1778
|
"0xc17": "Expected MapNodeStoredSchema",
|
|
1793
|
-
"0xc19": "Expected FieldSchemaAlpha",
|
|
1794
1779
|
"0xc1a": "Expected MapNodeStoredSchema",
|
|
1795
1780
|
"0xc1b": "Expected at least two types",
|
|
1796
1781
|
"0xc1e": "Expected a constructed node to be an object",
|
|
@@ -1910,5 +1895,12 @@ export const shortCodeMap = {
|
|
|
1910
1895
|
"0xc99": "Registered version is not less than the current version.",
|
|
1911
1896
|
"0xc9a": "Presence capabilities should be empty.",
|
|
1912
1897
|
"0xc9b": "Presence extension called without own compatibility details",
|
|
1913
|
-
"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"
|
|
1914
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 {
|
|
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
|
|
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
|
-
):
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
}
|