@metamask/snaps-jest 9.3.0 → 9.4.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/CHANGELOG.md +10 -1
- package/dist/global.cjs.map +1 -1
- package/dist/global.d.cts +45 -0
- package/dist/global.d.cts.map +1 -1
- package/dist/global.d.mts +45 -0
- package/dist/global.d.mts.map +1 -1
- package/dist/global.mjs.map +1 -1
- package/dist/matchers.cjs +70 -1
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts +6 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts +6 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs +66 -0
- package/dist/matchers.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [9.4.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add support for `snap_startTrace` and `snap_endTrace` ([#3547](https://github.com/MetaMask/snaps/pull/3547))
|
|
15
|
+
- Add support for `snap_trackError` ([#3546](https://github.com/MetaMask/snaps/pull/3546))
|
|
16
|
+
- Add support for `snap_trackEvent` ([#3546](https://github.com/MetaMask/snaps/pull/3546))
|
|
17
|
+
|
|
10
18
|
## [9.3.0]
|
|
11
19
|
|
|
12
20
|
### Added
|
|
@@ -403,7 +411,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
403
411
|
- The version of the package no longer needs to match the version of all other
|
|
404
412
|
MetaMask Snaps packages.
|
|
405
413
|
|
|
406
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.
|
|
414
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.4.0...HEAD
|
|
415
|
+
[9.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.3.0...@metamask/snaps-jest@9.4.0
|
|
407
416
|
[9.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.2.0...@metamask/snaps-jest@9.3.0
|
|
408
417
|
[9.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.1.0...@metamask/snaps-jest@9.2.0
|
|
409
418
|
[9.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@9.0.0...@metamask/snaps-jest@9.1.0
|
package/dist/global.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.cjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":";AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"global.cjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":";AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n\n /**\n * Assert that the Snap tracked an error with the expected parameters. This\n * is equivalent to calling\n * `expect(response.tracked.errors).toContainEqual(error)`.\n *\n * @param error - The expected error parameters.\n * @throws If the snap did not track an error with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrackError({\n * name: 'Error',\n * message: 'This is an error.',\n * });\n */\n toTrackError(error?: unknown): void;\n\n /**\n * Assert that the Snap tracked an event with the expected parameters. This\n * is equivalent to calling\n * `expect(response.tracked.events).toContainEqual(event)`.\n *\n * @param event - The expected event parameters.\n * @throws If the snap did not track an event with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrackEvent({\n * event: 'bar',\n * properties: { baz: 'qux' },\n * sensitiveProperties: { quux: 'corge' },\n * });\n */\n toTrackEvent(event?: unknown): void;\n\n /**\n * Assert that the Snap started and ended a trace with the expected\n * parameters. This is equivalent to calling\n * `expect(response.tracked.traces).toContainEqual(span)`.\n *\n * @param trace - The expected trace parameters.\n * @throws If the snap did not end a trace with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrace({\n * name: 'My Trace',\n * });\n */\n toTrace(trace?: unknown): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
|
package/dist/global.d.cts
CHANGED
|
@@ -61,6 +61,51 @@ interface SnapsMatchers {
|
|
|
61
61
|
* expect(ui).toRender(panel([heading('Hello, world!')]));
|
|
62
62
|
*/
|
|
63
63
|
toRender(component: ComponentOrElement): void;
|
|
64
|
+
/**
|
|
65
|
+
* Assert that the Snap tracked an error with the expected parameters. This
|
|
66
|
+
* is equivalent to calling
|
|
67
|
+
* `expect(response.tracked.errors).toContainEqual(error)`.
|
|
68
|
+
*
|
|
69
|
+
* @param error - The expected error parameters.
|
|
70
|
+
* @throws If the snap did not track an error with the expected parameters.
|
|
71
|
+
* @example
|
|
72
|
+
* const response = await request({ method: 'foo' });
|
|
73
|
+
* expect(response).toTrackError({
|
|
74
|
+
* name: 'Error',
|
|
75
|
+
* message: 'This is an error.',
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
toTrackError(error?: unknown): void;
|
|
79
|
+
/**
|
|
80
|
+
* Assert that the Snap tracked an event with the expected parameters. This
|
|
81
|
+
* is equivalent to calling
|
|
82
|
+
* `expect(response.tracked.events).toContainEqual(event)`.
|
|
83
|
+
*
|
|
84
|
+
* @param event - The expected event parameters.
|
|
85
|
+
* @throws If the snap did not track an event with the expected parameters.
|
|
86
|
+
* @example
|
|
87
|
+
* const response = await request({ method: 'foo' });
|
|
88
|
+
* expect(response).toTrackEvent({
|
|
89
|
+
* event: 'bar',
|
|
90
|
+
* properties: { baz: 'qux' },
|
|
91
|
+
* sensitiveProperties: { quux: 'corge' },
|
|
92
|
+
* });
|
|
93
|
+
*/
|
|
94
|
+
toTrackEvent(event?: unknown): void;
|
|
95
|
+
/**
|
|
96
|
+
* Assert that the Snap started and ended a trace with the expected
|
|
97
|
+
* parameters. This is equivalent to calling
|
|
98
|
+
* `expect(response.tracked.traces).toContainEqual(span)`.
|
|
99
|
+
*
|
|
100
|
+
* @param trace - The expected trace parameters.
|
|
101
|
+
* @throws If the snap did not end a trace with the expected parameters.
|
|
102
|
+
* @example
|
|
103
|
+
* const response = await request({ method: 'foo' });
|
|
104
|
+
* expect(response).toTrace({
|
|
105
|
+
* name: 'My Trace',
|
|
106
|
+
* });
|
|
107
|
+
*/
|
|
108
|
+
toTrace(trace?: unknown): void;
|
|
64
109
|
}
|
|
65
110
|
declare module 'expect' {
|
|
66
111
|
interface AsymmetricMatchers extends SnapsMatchers {
|
package/dist/global.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.d.cts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACnC,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,EACpB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC1C,IAAI,CAAC;IAER;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"global.d.cts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACnC,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,EACpB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC1C,IAAI,CAAC;IAER;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE9C;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpC;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAID,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,kBAAmB,SAAQ,aAAa;KAAG;IAKrD,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;KAAG;CAC/C;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QAIb,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;SAAG;KAC/C;CACF"}
|
package/dist/global.d.mts
CHANGED
|
@@ -61,6 +61,51 @@ interface SnapsMatchers {
|
|
|
61
61
|
* expect(ui).toRender(panel([heading('Hello, world!')]));
|
|
62
62
|
*/
|
|
63
63
|
toRender(component: ComponentOrElement): void;
|
|
64
|
+
/**
|
|
65
|
+
* Assert that the Snap tracked an error with the expected parameters. This
|
|
66
|
+
* is equivalent to calling
|
|
67
|
+
* `expect(response.tracked.errors).toContainEqual(error)`.
|
|
68
|
+
*
|
|
69
|
+
* @param error - The expected error parameters.
|
|
70
|
+
* @throws If the snap did not track an error with the expected parameters.
|
|
71
|
+
* @example
|
|
72
|
+
* const response = await request({ method: 'foo' });
|
|
73
|
+
* expect(response).toTrackError({
|
|
74
|
+
* name: 'Error',
|
|
75
|
+
* message: 'This is an error.',
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
toTrackError(error?: unknown): void;
|
|
79
|
+
/**
|
|
80
|
+
* Assert that the Snap tracked an event with the expected parameters. This
|
|
81
|
+
* is equivalent to calling
|
|
82
|
+
* `expect(response.tracked.events).toContainEqual(event)`.
|
|
83
|
+
*
|
|
84
|
+
* @param event - The expected event parameters.
|
|
85
|
+
* @throws If the snap did not track an event with the expected parameters.
|
|
86
|
+
* @example
|
|
87
|
+
* const response = await request({ method: 'foo' });
|
|
88
|
+
* expect(response).toTrackEvent({
|
|
89
|
+
* event: 'bar',
|
|
90
|
+
* properties: { baz: 'qux' },
|
|
91
|
+
* sensitiveProperties: { quux: 'corge' },
|
|
92
|
+
* });
|
|
93
|
+
*/
|
|
94
|
+
toTrackEvent(event?: unknown): void;
|
|
95
|
+
/**
|
|
96
|
+
* Assert that the Snap started and ended a trace with the expected
|
|
97
|
+
* parameters. This is equivalent to calling
|
|
98
|
+
* `expect(response.tracked.traces).toContainEqual(span)`.
|
|
99
|
+
*
|
|
100
|
+
* @param trace - The expected trace parameters.
|
|
101
|
+
* @throws If the snap did not end a trace with the expected parameters.
|
|
102
|
+
* @example
|
|
103
|
+
* const response = await request({ method: 'foo' });
|
|
104
|
+
* expect(response).toTrace({
|
|
105
|
+
* name: 'My Trace',
|
|
106
|
+
* });
|
|
107
|
+
*/
|
|
108
|
+
toTrace(trace?: unknown): void;
|
|
64
109
|
}
|
|
65
110
|
declare module 'expect' {
|
|
66
111
|
interface AsymmetricMatchers extends SnapsMatchers {
|
package/dist/global.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.d.mts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACnC,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,EACpB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC1C,IAAI,CAAC;IAER;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"global.d.mts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;;;OAgBG;IACH,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACnC,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,EACpB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC1C,IAAI,CAAC;IAER;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE9C;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpC;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAID,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,kBAAmB,SAAQ,aAAa;KAAG;IAKrD,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;KAAG;CAC/C;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QAIb,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;SAAG;KAC/C;CACF"}
|
package/dist/global.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.mjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"global.mjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n\n /**\n * Assert that the Snap tracked an error with the expected parameters. This\n * is equivalent to calling\n * `expect(response.tracked.errors).toContainEqual(error)`.\n *\n * @param error - The expected error parameters.\n * @throws If the snap did not track an error with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrackError({\n * name: 'Error',\n * message: 'This is an error.',\n * });\n */\n toTrackError(error?: unknown): void;\n\n /**\n * Assert that the Snap tracked an event with the expected parameters. This\n * is equivalent to calling\n * `expect(response.tracked.events).toContainEqual(event)`.\n *\n * @param event - The expected event parameters.\n * @throws If the snap did not track an event with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrackEvent({\n * event: 'bar',\n * properties: { baz: 'qux' },\n * sensitiveProperties: { quux: 'corge' },\n * });\n */\n toTrackEvent(event?: unknown): void;\n\n /**\n * Assert that the Snap started and ended a trace with the expected\n * parameters. This is equivalent to calling\n * `expect(response.tracked.traces).toContainEqual(span)`.\n *\n * @param trace - The expected trace parameters.\n * @throws If the snap did not end a trace with the expected parameters.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toTrace({\n * name: 'My Trace',\n * });\n */\n toTrace(trace?: unknown): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
|
package/dist/matchers.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Note: Because this file imports from `@jest/globals`, it can only be used in
|
|
3
3
|
// a Jest environment. This is why it's not exported from the index file.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.toRender = exports.toSendNotification = exports.toRespondWithError = exports.toRespondWith = void 0;
|
|
5
|
+
exports.toTrace = exports.toTrackEvent = exports.toTrackError = exports.toRender = exports.toSendNotification = exports.toRespondWithError = exports.toRespondWith = void 0;
|
|
6
6
|
const globals_1 = require("@jest/globals");
|
|
7
7
|
const jsx_1 = require("@metamask/snaps-sdk/jsx");
|
|
8
8
|
const snaps_simulation_1 = require("@metamask/snaps-simulation");
|
|
@@ -213,10 +213,79 @@ function (actual, expected) {
|
|
|
213
213
|
return { message, pass };
|
|
214
214
|
};
|
|
215
215
|
exports.toRender = toRender;
|
|
216
|
+
const toTrackError = function (actual, errorData) {
|
|
217
|
+
assertActualIsSnapResponse(actual, 'toTrackError');
|
|
218
|
+
const errorValidator = (error) => {
|
|
219
|
+
if (!errorData) {
|
|
220
|
+
// If no error data is provided, we just check for the existence of an
|
|
221
|
+
// error.
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
return this.equals(error, errorData);
|
|
225
|
+
};
|
|
226
|
+
const { errors } = actual.tracked;
|
|
227
|
+
const pass = errors.some(errorValidator);
|
|
228
|
+
const message = pass
|
|
229
|
+
? () => `${this.utils.matcherHint('.not.toTrackError')}\n\n` +
|
|
230
|
+
`Expected not to track error with data: ${this.utils.printExpected(errorData)}\n` +
|
|
231
|
+
`Received errors: ${this.utils.printReceived(errors)}`
|
|
232
|
+
: () => `${this.utils.matcherHint('.toTrackError')}\n\n` +
|
|
233
|
+
`Expected to track error with data: ${this.utils.printExpected(errorData)}\n` +
|
|
234
|
+
`Received errors: ${this.utils.printReceived(errors)}`;
|
|
235
|
+
return { message, pass };
|
|
236
|
+
};
|
|
237
|
+
exports.toTrackError = toTrackError;
|
|
238
|
+
const toTrackEvent = function (actual, eventData) {
|
|
239
|
+
assertActualIsSnapResponse(actual, 'toTrackEvent');
|
|
240
|
+
const eventValidator = (event) => {
|
|
241
|
+
if (!eventData) {
|
|
242
|
+
// If no event data is provided, we just check for the existence of an
|
|
243
|
+
// event.
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
return this.equals(event, eventData);
|
|
247
|
+
};
|
|
248
|
+
const { events } = actual.tracked;
|
|
249
|
+
const pass = events.some(eventValidator);
|
|
250
|
+
const message = pass
|
|
251
|
+
? () => `${this.utils.matcherHint('.not.toTrackEvent')}\n\n` +
|
|
252
|
+
`Expected not to track event with data: ${this.utils.printExpected(eventData)}\n` +
|
|
253
|
+
`Received events: ${this.utils.printReceived(events)}`
|
|
254
|
+
: () => `${this.utils.matcherHint('.toTrackEvent')}\n\n` +
|
|
255
|
+
`Expected to track event with data: ${this.utils.printExpected(eventData)}\n` +
|
|
256
|
+
`Received events: ${this.utils.printReceived(events)}`;
|
|
257
|
+
return { message, pass };
|
|
258
|
+
};
|
|
259
|
+
exports.toTrackEvent = toTrackEvent;
|
|
260
|
+
const toTrace = function (actual, traceData) {
|
|
261
|
+
assertActualIsSnapResponse(actual, 'toTrace');
|
|
262
|
+
const traceValidator = (trace) => {
|
|
263
|
+
if (!traceData) {
|
|
264
|
+
// If no trace data is provided, we just check for the existence of a
|
|
265
|
+
// trace.
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
return this.equals(trace, traceData);
|
|
269
|
+
};
|
|
270
|
+
const { traces } = actual.tracked;
|
|
271
|
+
const pass = traces.some(traceValidator);
|
|
272
|
+
const message = pass
|
|
273
|
+
? () => `${this.utils.matcherHint('.not.toTrace')}\n\n` +
|
|
274
|
+
`Expected not to trace with data: ${this.utils.printExpected(traceData)}\n` +
|
|
275
|
+
`Received traces: ${this.utils.printReceived(traces)}`
|
|
276
|
+
: () => `${this.utils.matcherHint('.toTrace')}\n\n` +
|
|
277
|
+
`Expected to trace with data: ${this.utils.printExpected(traceData)}\n` +
|
|
278
|
+
`Received traces: ${this.utils.printReceived(traces)}`;
|
|
279
|
+
return { message, pass };
|
|
280
|
+
};
|
|
281
|
+
exports.toTrace = toTrace;
|
|
216
282
|
globals_1.expect.extend({
|
|
217
283
|
toRespondWith: exports.toRespondWith,
|
|
218
284
|
toRespondWithError: exports.toRespondWithError,
|
|
219
285
|
toSendNotification: exports.toSendNotification,
|
|
220
286
|
toRender: exports.toRender,
|
|
287
|
+
toTrackError: exports.toTrackError,
|
|
288
|
+
toTrackEvent: exports.toTrackEvent,
|
|
289
|
+
toTrace: exports.toTrace,
|
|
221
290
|
});
|
|
222
291
|
//# sourceMappingURL=matchers.cjs.map
|
package/dist/matchers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yEAAyE;;;AAGzE,2CAAuC;AAQvC,iDAA+E;AAE/E,iEAGoC;AACpC,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAA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CAAC,MAAM;YAC5C,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAlCS,QAAA,QAAQ,YAkCjB;AAEJ,gBAAM,CAAC,MAAM,CAAC;IACZ,aAAa,EAAb,qBAAa;IACb,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,QAAQ,EAAR,gBAAQ;CACT,CAAC,CAAC","sourcesContent":["// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
|
|
1
|
+
{"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yEAAyE;;;AAGzE,2CAAuC;AAUvC,iDAA+E;AAE/E,iEAGoC;AACpC,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,qCAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EACf,UAAU,CACX,yDAAyD,EAC1D,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,EAAE,kCAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,kCAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EAAC,UAAU,CAAC,yCAAyC,EACtE,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,EAAE,kCAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACI,MAAM,aAAa,GAAsC,UAC9D,MA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CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;IAE7D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAlCW,QAAA,OAAO,WAkClB;AAEF,gBAAM,CAAC,MAAM,CAAC;IACZ,aAAa,EAAb,qBAAa;IACb,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,QAAQ,EAAR,gBAAQ;IACR,YAAY,EAAZ,oBAAY;IACZ,YAAY,EAAZ,oBAAY;IACZ,OAAO,EAAP,eAAO;CACR,CAAC,CAAC","sourcesContent":["// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n TrackableError,\n TraceRequest,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexport const toTrackError: MatcherFunction<\n [errorData?: Partial<TrackableError>]\n> = function (actual, errorData) {\n assertActualIsSnapResponse(actual, 'toTrackError');\n\n const errorValidator = (error: SnapResponse['tracked']['errors'][number]) => {\n if (!errorData) {\n // If no error data is provided, we just check for the existence of an\n // error.\n return true;\n }\n\n return this.equals(error, errorData);\n };\n\n const { errors } = actual.tracked;\n const pass = errors.some(errorValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrackError')}\\n\\n` +\n `Expected not to track error with data: ${this.utils.printExpected(\n errorData,\n )}\\n` +\n `Received errors: ${this.utils.printReceived(errors)}`\n : () =>\n `${this.utils.matcherHint('.toTrackError')}\\n\\n` +\n `Expected to track error with data: ${this.utils.printExpected(\n errorData,\n )}\\n` +\n `Received errors: ${this.utils.printReceived(errors)}`;\n\n return { message, pass };\n};\n\nexport const toTrackEvent: MatcherFunction<[eventData?: Json | undefined]> =\n function (actual, eventData) {\n assertActualIsSnapResponse(actual, 'toTrackEvent');\n\n const eventValidator = (\n event: SnapResponse['tracked']['events'][number],\n ) => {\n if (!eventData) {\n // If no event data is provided, we just check for the existence of an\n // event.\n return true;\n }\n\n return this.equals(event, eventData);\n };\n\n const { events } = actual.tracked;\n const pass = events.some(eventValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrackEvent')}\\n\\n` +\n `Expected not to track event with data: ${this.utils.printExpected(\n eventData,\n )}\\n` +\n `Received events: ${this.utils.printReceived(events)}`\n : () =>\n `${this.utils.matcherHint('.toTrackEvent')}\\n\\n` +\n `Expected to track event with data: ${this.utils.printExpected(\n eventData,\n )}\\n` +\n `Received events: ${this.utils.printReceived(events)}`;\n\n return { message, pass };\n };\n\nexport const toTrace: MatcherFunction<[traceData?: TraceRequest]> = function (\n actual,\n traceData,\n) {\n assertActualIsSnapResponse(actual, 'toTrace');\n\n const traceValidator = (trace: SnapResponse['tracked']['traces'][number]) => {\n if (!traceData) {\n // If no trace data is provided, we just check for the existence of a\n // trace.\n return true;\n }\n\n return this.equals(trace, traceData);\n };\n\n const { traces } = actual.tracked;\n const pass = traces.some(traceValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrace')}\\n\\n` +\n `Expected not to trace with data: ${this.utils.printExpected(\n traceData,\n )}\\n` +\n `Received traces: ${this.utils.printReceived(traces)}`\n : () =>\n `${this.utils.matcherHint('.toTrace')}\\n\\n` +\n `Expected to trace with data: ${this.utils.printExpected(\n traceData,\n )}\\n` +\n `Received traces: ${this.utils.printReceived(traces)}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n toTrackError,\n toTrackEvent,\n toTrace,\n});\n"]}
|
package/dist/matchers.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MatcherFunction } from "@jest/expect";
|
|
2
|
-
import type { EnumToUnion, ComponentOrElement, NotificationType } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { EnumToUnion, ComponentOrElement, NotificationType, TrackableError, TraceRequest } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { JSXElement } from "@metamask/snaps-sdk/jsx";
|
|
4
4
|
import type { Json } from "@metamask/utils";
|
|
5
5
|
/**
|
|
@@ -35,4 +35,9 @@ export declare const toSendNotification: MatcherFunction<[
|
|
|
35
35
|
} | undefined
|
|
36
36
|
]>;
|
|
37
37
|
export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
|
|
38
|
+
export declare const toTrackError: MatcherFunction<[
|
|
39
|
+
errorData?: Partial<TrackableError>
|
|
40
|
+
]>;
|
|
41
|
+
export declare const toTrackEvent: MatcherFunction<[eventData?: Json | undefined]>;
|
|
42
|
+
export declare const toTrace: MatcherFunction<[traceData?: TraceRequest]>;
|
|
38
43
|
//# sourceMappingURL=matchers.d.cts.map
|
package/dist/matchers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"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C,SAAS,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAkCtE,CAAC;AAEJ,eAAO,MAAM,OAAO,EAAE,eAAe,CAAC,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,CAkC/D,CAAC"}
|
package/dist/matchers.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MatcherFunction } from "@jest/expect";
|
|
2
|
-
import type { EnumToUnion, ComponentOrElement, NotificationType } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { EnumToUnion, ComponentOrElement, NotificationType, TrackableError, TraceRequest } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { JSXElement } from "@metamask/snaps-sdk/jsx";
|
|
4
4
|
import type { Json } from "@metamask/utils";
|
|
5
5
|
/**
|
|
@@ -35,4 +35,9 @@ export declare const toSendNotification: MatcherFunction<[
|
|
|
35
35
|
} | undefined
|
|
36
36
|
]>;
|
|
37
37
|
export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
|
|
38
|
+
export declare const toTrackError: MatcherFunction<[
|
|
39
|
+
errorData?: Partial<TrackableError>
|
|
40
|
+
]>;
|
|
41
|
+
export declare const toTrackEvent: MatcherFunction<[eventData?: Json | undefined]>;
|
|
42
|
+
export declare const toTrace: MatcherFunction<[traceData?: TraceRequest]>;
|
|
38
43
|
//# sourceMappingURL=matchers.d.mts.map
|
package/dist/matchers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAElB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,WAAW,EACX,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};
|
|
209
209
|
};
|
|
210
|
+
export const toTrackError = function (actual, errorData) {
|
|
211
|
+
assertActualIsSnapResponse(actual, 'toTrackError');
|
|
212
|
+
const errorValidator = (error) => {
|
|
213
|
+
if (!errorData) {
|
|
214
|
+
// If no error data is provided, we just check for the existence of an
|
|
215
|
+
// error.
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return this.equals(error, errorData);
|
|
219
|
+
};
|
|
220
|
+
const { errors } = actual.tracked;
|
|
221
|
+
const pass = errors.some(errorValidator);
|
|
222
|
+
const message = pass
|
|
223
|
+
? () => `${this.utils.matcherHint('.not.toTrackError')}\n\n` +
|
|
224
|
+
`Expected not to track error with data: ${this.utils.printExpected(errorData)}\n` +
|
|
225
|
+
`Received errors: ${this.utils.printReceived(errors)}`
|
|
226
|
+
: () => `${this.utils.matcherHint('.toTrackError')}\n\n` +
|
|
227
|
+
`Expected to track error with data: ${this.utils.printExpected(errorData)}\n` +
|
|
228
|
+
`Received errors: ${this.utils.printReceived(errors)}`;
|
|
229
|
+
return { message, pass };
|
|
230
|
+
};
|
|
231
|
+
export const toTrackEvent = function (actual, eventData) {
|
|
232
|
+
assertActualIsSnapResponse(actual, 'toTrackEvent');
|
|
233
|
+
const eventValidator = (event) => {
|
|
234
|
+
if (!eventData) {
|
|
235
|
+
// If no event data is provided, we just check for the existence of an
|
|
236
|
+
// event.
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return this.equals(event, eventData);
|
|
240
|
+
};
|
|
241
|
+
const { events } = actual.tracked;
|
|
242
|
+
const pass = events.some(eventValidator);
|
|
243
|
+
const message = pass
|
|
244
|
+
? () => `${this.utils.matcherHint('.not.toTrackEvent')}\n\n` +
|
|
245
|
+
`Expected not to track event with data: ${this.utils.printExpected(eventData)}\n` +
|
|
246
|
+
`Received events: ${this.utils.printReceived(events)}`
|
|
247
|
+
: () => `${this.utils.matcherHint('.toTrackEvent')}\n\n` +
|
|
248
|
+
`Expected to track event with data: ${this.utils.printExpected(eventData)}\n` +
|
|
249
|
+
`Received events: ${this.utils.printReceived(events)}`;
|
|
250
|
+
return { message, pass };
|
|
251
|
+
};
|
|
252
|
+
export const toTrace = function (actual, traceData) {
|
|
253
|
+
assertActualIsSnapResponse(actual, 'toTrace');
|
|
254
|
+
const traceValidator = (trace) => {
|
|
255
|
+
if (!traceData) {
|
|
256
|
+
// If no trace data is provided, we just check for the existence of a
|
|
257
|
+
// trace.
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
return this.equals(trace, traceData);
|
|
261
|
+
};
|
|
262
|
+
const { traces } = actual.tracked;
|
|
263
|
+
const pass = traces.some(traceValidator);
|
|
264
|
+
const message = pass
|
|
265
|
+
? () => `${this.utils.matcherHint('.not.toTrace')}\n\n` +
|
|
266
|
+
`Expected not to trace with data: ${this.utils.printExpected(traceData)}\n` +
|
|
267
|
+
`Received traces: ${this.utils.printReceived(traces)}`
|
|
268
|
+
: () => `${this.utils.matcherHint('.toTrace')}\n\n` +
|
|
269
|
+
`Expected to trace with data: ${this.utils.printExpected(traceData)}\n` +
|
|
270
|
+
`Received traces: ${this.utils.printReceived(traces)}`;
|
|
271
|
+
return { message, pass };
|
|
272
|
+
};
|
|
210
273
|
expect.extend({
|
|
211
274
|
toRespondWith,
|
|
212
275
|
toRespondWithError,
|
|
213
276
|
toSendNotification,
|
|
214
277
|
toRender,
|
|
278
|
+
toTrackError,
|
|
279
|
+
toTrackEvent,
|
|
280
|
+
toTrace,
|
|
215
281
|
});
|
|
216
282
|
//# sourceMappingURL=matchers.mjs.map
|
package/dist/matchers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,yEAAyE;;;AAWzE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gCAAgC;AAE/E,OAAO,EACL,eAAe,EACf,kBAAkB,EACnB,mCAAmC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,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,CAAC;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,QAAQ;CACT,CAAC,CAAC","sourcesContent":["// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
|
|
1
|
+
{"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,yEAAyE;;;AAazE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gCAAgC;AAE/E,OAAO,EACL,eAAe,EACf,kBAAkB,EACnB,mCAAmC;AACpC,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EACL,cAAc,EACd,IAAI,EACJ,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,aAAa,EACb,cAAc,EACf,2BAA2B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,cAAc,CACf,UAAU,CACX,yDAAyD,EAC1D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,cAAc,CAAC,UAAU,CAAC,yCAAyC,EACtE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AAE,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,CAAC;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,OAAO;CACR,CAAC,CAAC","sourcesContent":["// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n TrackableError,\n TraceRequest,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexport const toTrackError: MatcherFunction<\n [errorData?: Partial<TrackableError>]\n> = function (actual, errorData) {\n assertActualIsSnapResponse(actual, 'toTrackError');\n\n const errorValidator = (error: SnapResponse['tracked']['errors'][number]) => {\n if (!errorData) {\n // If no error data is provided, we just check for the existence of an\n // error.\n return true;\n }\n\n return this.equals(error, errorData);\n };\n\n const { errors } = actual.tracked;\n const pass = errors.some(errorValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrackError')}\\n\\n` +\n `Expected not to track error with data: ${this.utils.printExpected(\n errorData,\n )}\\n` +\n `Received errors: ${this.utils.printReceived(errors)}`\n : () =>\n `${this.utils.matcherHint('.toTrackError')}\\n\\n` +\n `Expected to track error with data: ${this.utils.printExpected(\n errorData,\n )}\\n` +\n `Received errors: ${this.utils.printReceived(errors)}`;\n\n return { message, pass };\n};\n\nexport const toTrackEvent: MatcherFunction<[eventData?: Json | undefined]> =\n function (actual, eventData) {\n assertActualIsSnapResponse(actual, 'toTrackEvent');\n\n const eventValidator = (\n event: SnapResponse['tracked']['events'][number],\n ) => {\n if (!eventData) {\n // If no event data is provided, we just check for the existence of an\n // event.\n return true;\n }\n\n return this.equals(event, eventData);\n };\n\n const { events } = actual.tracked;\n const pass = events.some(eventValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrackEvent')}\\n\\n` +\n `Expected not to track event with data: ${this.utils.printExpected(\n eventData,\n )}\\n` +\n `Received events: ${this.utils.printReceived(events)}`\n : () =>\n `${this.utils.matcherHint('.toTrackEvent')}\\n\\n` +\n `Expected to track event with data: ${this.utils.printExpected(\n eventData,\n )}\\n` +\n `Received events: ${this.utils.printReceived(events)}`;\n\n return { message, pass };\n };\n\nexport const toTrace: MatcherFunction<[traceData?: TraceRequest]> = function (\n actual,\n traceData,\n) {\n assertActualIsSnapResponse(actual, 'toTrace');\n\n const traceValidator = (trace: SnapResponse['tracked']['traces'][number]) => {\n if (!traceData) {\n // If no trace data is provided, we just check for the existence of a\n // trace.\n return true;\n }\n\n return this.equals(trace, traceData);\n };\n\n const { traces } = actual.tracked;\n const pass = traces.some(traceValidator);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toTrace')}\\n\\n` +\n `Expected not to trace with data: ${this.utils.printExpected(\n traceData,\n )}\\n` +\n `Received traces: ${this.utils.printReceived(traces)}`\n : () =>\n `${this.utils.matcherHint('.toTrace')}\\n\\n` +\n `Expected to trace with data: ${this.utils.printExpected(\n traceData,\n )}\\n` +\n `Received traces: ${this.utils.printReceived(traces)}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n toTrackError,\n toTrackEvent,\n toTrace,\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
"@jest/environment": "^29.5.0",
|
|
61
61
|
"@jest/expect": "^29.5.0",
|
|
62
62
|
"@jest/globals": "^29.5.0",
|
|
63
|
-
"@metamask/snaps-controllers": "^14.
|
|
64
|
-
"@metamask/snaps-sdk": "^9.
|
|
65
|
-
"@metamask/snaps-simulation": "^3.
|
|
63
|
+
"@metamask/snaps-controllers": "^14.2.0",
|
|
64
|
+
"@metamask/snaps-sdk": "^9.3.0",
|
|
65
|
+
"@metamask/snaps-simulation": "^3.4.0",
|
|
66
66
|
"@metamask/superstruct": "^3.2.1",
|
|
67
67
|
"@metamask/utils": "^11.4.2",
|
|
68
68
|
"express": "^5.1.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@jest/types": "^29.6.3",
|
|
75
75
|
"@lavamoat/allow-scripts": "^3.3.4",
|
|
76
76
|
"@metamask/auto-changelog": "^5.0.2",
|
|
77
|
-
"@metamask/snaps-utils": "^11.
|
|
77
|
+
"@metamask/snaps-utils": "^11.3.0",
|
|
78
78
|
"@swc/core": "1.11.31",
|
|
79
79
|
"@swc/jest": "^0.2.38",
|
|
80
80
|
"@ts-bridge/cli": "^0.6.1",
|