@metamask/snaps-jest 4.0.0 → 5.0.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 +21 -1
- package/README.md +66 -179
- package/dist/cjs/environment.js +21 -82
- package/dist/cjs/environment.js.map +1 -1
- package/dist/cjs/helpers.js +118 -43
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/internals/environment.js +1 -1
- package/dist/cjs/internals/environment.js.map +1 -1
- package/dist/cjs/internals/index.js +1 -4
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/internals/request.js +42 -94
- package/dist/cjs/internals/request.js.map +1 -1
- package/dist/cjs/internals/server.js +0 -4
- package/dist/cjs/internals/server.js.map +1 -1
- package/dist/cjs/internals/simulation/constants.js +29 -0
- package/dist/cjs/internals/simulation/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/controllers.js +95 -0
- package/dist/cjs/internals/simulation/controllers.js.map +1 -0
- package/dist/cjs/internals/simulation/files.js +22 -0
- package/dist/cjs/internals/simulation/files.js.map +1 -0
- package/dist/cjs/internals/simulation/index.js +24 -0
- package/dist/cjs/internals/simulation/index.js.map +1 -0
- package/dist/cjs/internals/simulation/interface.js +98 -0
- package/dist/cjs/internals/simulation/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/constants.js +84 -0
- package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
- package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
- package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
- package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
- package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
- package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
- package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
- package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/index.js +20 -0
- package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
- package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
- package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
- package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/cjs/internals/simulation/options.js +24 -0
- package/dist/cjs/internals/simulation/options.js.map +1 -0
- package/dist/cjs/internals/simulation/simulation.js +124 -0
- package/dist/cjs/internals/simulation/simulation.js.map +1 -0
- package/dist/cjs/internals/simulation/store/index.js +23 -0
- package/dist/cjs/internals/simulation/store/index.js.map +1 -0
- package/dist/cjs/internals/simulation/store/mocks.js +52 -0
- package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
- package/dist/cjs/internals/simulation/store/notifications.js +52 -0
- package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
- package/dist/cjs/internals/simulation/store/state.js +64 -0
- package/dist/cjs/internals/simulation/store/state.js.map +1 -0
- package/dist/cjs/internals/simulation/store/store.js +57 -0
- package/dist/cjs/internals/simulation/store/store.js.map +1 -0
- package/dist/cjs/internals/simulation/store/ui.js +48 -0
- package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
- package/dist/cjs/internals/structs.js +47 -5
- package/dist/cjs/internals/structs.js.map +1 -1
- package/dist/cjs/matchers.js +5 -2
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/options.js +0 -6
- package/dist/cjs/options.js.map +1 -1
- package/dist/esm/environment.js +22 -83
- package/dist/esm/environment.js.map +1 -1
- package/dist/esm/helpers.js +127 -46
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/internals/environment.js +1 -1
- package/dist/esm/internals/environment.js.map +1 -1
- package/dist/esm/internals/index.js +1 -5
- package/dist/esm/internals/index.js.map +1 -1
- package/dist/esm/internals/request.js +61 -104
- package/dist/esm/internals/request.js.map +1 -1
- package/dist/esm/internals/server.js +1 -5
- package/dist/esm/internals/server.js.map +1 -1
- package/dist/esm/internals/simulation/constants.js +12 -0
- package/dist/esm/internals/simulation/constants.js.map +1 -0
- package/dist/esm/internals/simulation/controllers.js +90 -0
- package/dist/esm/internals/simulation/controllers.js.map +1 -0
- package/dist/esm/internals/simulation/files.js +19 -0
- package/dist/esm/internals/simulation/files.js.map +1 -0
- package/dist/esm/internals/simulation/index.js +7 -0
- package/dist/esm/internals/simulation/index.js.map +1 -0
- package/dist/esm/internals/simulation/interface.js +95 -0
- package/dist/esm/internals/simulation/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/constants.js +69 -0
- package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
- package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
- package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
- package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
- package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
- package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
- package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
- package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/esm/internals/simulation/methods/index.js +3 -0
- package/dist/esm/internals/simulation/methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/methods/specifications.js +84 -0
- package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/engine.js +33 -0
- package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
- package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/esm/internals/simulation/middleware/mock.js +18 -0
- package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/esm/internals/simulation/options.js +20 -0
- package/dist/esm/internals/simulation/options.js.map +1 -0
- package/dist/esm/internals/simulation/simulation.js +128 -0
- package/dist/esm/internals/simulation/simulation.js.map +1 -0
- package/dist/esm/internals/simulation/store/index.js +6 -0
- package/dist/esm/internals/simulation/store/index.js.map +1 -0
- package/dist/esm/internals/simulation/store/mocks.js +32 -0
- package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
- package/dist/esm/internals/simulation/store/notifications.js +30 -0
- package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
- package/dist/esm/internals/simulation/store/state.js +47 -0
- package/dist/esm/internals/simulation/store/state.js.map +1 -0
- package/dist/esm/internals/simulation/store/store.js +50 -0
- package/dist/esm/internals/simulation/store/store.js.map +1 -0
- package/dist/esm/internals/simulation/store/ui.js +21 -0
- package/dist/esm/internals/simulation/store/ui.js.map +1 -0
- package/dist/esm/internals/structs.js +41 -5
- package/dist/esm/internals/structs.js.map +1 -1
- package/dist/esm/matchers.js +5 -2
- package/dist/esm/matchers.js.map +1 -1
- package/dist/esm/options.js +1 -7
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/environment.d.ts +14 -15
- package/dist/types/helpers.d.ts +64 -3
- package/dist/types/internals/index.d.ts +1 -4
- package/dist/types/internals/request.d.ts +38 -56
- package/dist/types/internals/simulation/constants.d.ts +13 -0
- package/dist/types/internals/simulation/controllers.d.ts +40 -0
- package/dist/types/internals/simulation/files.d.ts +11 -0
- package/dist/types/internals/simulation/index.d.ts +5 -0
- package/dist/types/internals/simulation/interface.d.ts +25 -0
- package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
- package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
- package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
- package/dist/types/internals/simulation/methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
- package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
- package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
- package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
- package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
- package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
- package/dist/types/internals/simulation/options.d.ts +37 -0
- package/dist/types/internals/simulation/simulation.d.ts +98 -0
- package/dist/types/internals/simulation/store/index.d.ts +4 -0
- package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
- package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
- package/dist/types/internals/simulation/store/state.d.ts +55 -0
- package/dist/types/internals/simulation/store/store.d.ts +22 -0
- package/dist/types/internals/simulation/store/ui.d.ts +25 -0
- package/dist/types/internals/structs.d.ts +229 -16
- package/dist/types/options.d.ts +3 -35
- package/dist/types/types.d.ts +88 -41
- package/package.json +21 -12
- package/dist/cjs/internals/interface.js +0 -103
- package/dist/cjs/internals/interface.js.map +0 -1
- package/dist/cjs/internals/network.js +0 -148
- package/dist/cjs/internals/network.js.map +0 -1
- package/dist/cjs/internals/types.js +0 -6
- package/dist/cjs/internals/types.js.map +0 -1
- package/dist/cjs/internals/wait-for.js +0 -63
- package/dist/cjs/internals/wait-for.js.map +0 -1
- package/dist/esm/internals/interface.js +0 -100
- package/dist/esm/internals/interface.js.map +0 -1
- package/dist/esm/internals/network.js +0 -143
- package/dist/esm/internals/network.js.map +0 -1
- package/dist/esm/internals/types.js +0 -3
- package/dist/esm/internals/types.js.map +0 -1
- package/dist/esm/internals/wait-for.js +0 -63
- package/dist/esm/internals/wait-for.js.map +0 -1
- package/dist/types/internals/interface.d.ts +0 -25
- package/dist/types/internals/network.d.ts +0 -87
- package/dist/types/internals/types.d.ts +0 -18
- package/dist/types/internals/wait-for.d.ts +0 -38
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/types.ts"],"sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n // This API is injected into the page by the simulator. It allows us to\n // dispatch actions to the simulator, and read the state directly from the\n // Redux store.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n __SIMULATOR_API__: {\n dispatch: Dispatch;\n subscribe: (listener: () => void) => () => void;\n getState: () => ApplicationState;\n getRequestId: () => string;\n getNotifications: (requestId: string) => {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n };\n }\n}\n\nexport {};\n"],"names":[],"mappings":"AAAA,WAwBU"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { assert, createModuleLogger } from '@metamask/utils';
|
|
2
|
-
import { waitFor as waitForPuppeteer } from 'pptr-testing-library';
|
|
3
|
-
import { rootLogger } from './logger';
|
|
4
|
-
const log = createModuleLogger(rootLogger, 'wait-for');
|
|
5
|
-
/**
|
|
6
|
-
* Wait for a condition to be true. This is a wrapper around
|
|
7
|
-
* `pptr-testing-library`'s `waitFor` function, with the addition of a custom
|
|
8
|
-
* error message.
|
|
9
|
-
*
|
|
10
|
-
* @param fn - The condition to wait for.
|
|
11
|
-
* @param options - The options.
|
|
12
|
-
* @param options.timeout - The timeout in milliseconds.
|
|
13
|
-
* @param options.message - The error message to throw if the condition is not
|
|
14
|
-
* met.
|
|
15
|
-
* @returns A promise that resolves when the condition is met. The promise
|
|
16
|
-
* resolves to the return value of the condition function.
|
|
17
|
-
*/ export async function waitFor(fn, { timeout = 3000, message } = {}) {
|
|
18
|
-
try {
|
|
19
|
-
let result;
|
|
20
|
-
await waitForPuppeteer(// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
21
|
-
async ()=>{
|
|
22
|
-
// Puppeteer's `waitFor` function does not support returning a value
|
|
23
|
-
// from the condition function, so we need to use a variable outside
|
|
24
|
-
// the scope of the function.
|
|
25
|
-
result = await fn();
|
|
26
|
-
}, {
|
|
27
|
-
timeout
|
|
28
|
-
});
|
|
29
|
-
assert(result !== undefined);
|
|
30
|
-
return result;
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (message) {
|
|
33
|
-
throw new Error(message);
|
|
34
|
-
}
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Wait for a JSON-RPC response.
|
|
40
|
-
*
|
|
41
|
-
* @param page - The page to wait for the response on.
|
|
42
|
-
* @param type - The type of response to wait for.
|
|
43
|
-
* @returns The JSON-RPC response.
|
|
44
|
-
*/ export async function waitForResponse(page, type) {
|
|
45
|
-
log('Waiting for response of type %s.', type);
|
|
46
|
-
return await page.evaluate(async (_type)=>{
|
|
47
|
-
return new Promise((resolve)=>{
|
|
48
|
-
window.__SIMULATOR_API__.dispatch({
|
|
49
|
-
type: `${_type}/clearResponse`
|
|
50
|
-
});
|
|
51
|
-
const unsubscribe = window.__SIMULATOR_API__.subscribe(()=>{
|
|
52
|
-
const state = window.__SIMULATOR_API__.getState();
|
|
53
|
-
const { pending, response } = state[_type];
|
|
54
|
-
if (!pending && response) {
|
|
55
|
-
unsubscribe();
|
|
56
|
-
resolve(response);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}, type);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=wait-for.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/wait-for.ts"],"sourcesContent":["import type { HandlerType } from '@metamask/snaps-utils';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport { waitFor as waitForPuppeteer } from 'pptr-testing-library';\nimport type { Page } from 'puppeteer';\n\nimport type { SnapResponse } from '../types';\nimport { rootLogger } from './logger';\n\nexport type WaitForOptions = {\n /**\n * The timeout in milliseconds.\n */\n timeout?: number;\n\n /**\n * The error message to throw if the condition is not met.\n */\n message?: string;\n};\n\nconst log = createModuleLogger(rootLogger, 'wait-for');\n\n/**\n * Wait for a condition to be true. This is a wrapper around\n * `pptr-testing-library`'s `waitFor` function, with the addition of a custom\n * error message.\n *\n * @param fn - The condition to wait for.\n * @param options - The options.\n * @param options.timeout - The timeout in milliseconds.\n * @param options.message - The error message to throw if the condition is not\n * met.\n * @returns A promise that resolves when the condition is met. The promise\n * resolves to the return value of the condition function.\n */\nexport async function waitFor<Result>(\n fn: () => Promise<Result>,\n { timeout = 3000, message }: WaitForOptions = {},\n) {\n try {\n let result: Result | undefined;\n\n await waitForPuppeteer(\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async () => {\n // Puppeteer's `waitFor` function does not support returning a value\n // from the condition function, so we need to use a variable outside\n // the scope of the function.\n result = await fn();\n },\n {\n timeout,\n },\n );\n\n assert(result !== undefined);\n return result;\n } catch (error) {\n if (message) {\n throw new Error(message);\n }\n\n throw error;\n }\n}\n\n/**\n * Wait for a JSON-RPC response.\n *\n * @param page - The page to wait for the response on.\n * @param type - The type of response to wait for.\n * @returns The JSON-RPC response.\n */\nexport async function waitForResponse(\n page: Page,\n type:\n | HandlerType.OnTransaction\n | HandlerType.OnRpcRequest\n | HandlerType.OnCronjob,\n) {\n log('Waiting for response of type %s.', type);\n\n return await page.evaluate(async (_type) => {\n return new Promise<SnapResponse['response']>((resolve) => {\n window.__SIMULATOR_API__.dispatch({\n type: `${_type}/clearResponse`,\n });\n\n const unsubscribe = window.__SIMULATOR_API__.subscribe(() => {\n const state = window.__SIMULATOR_API__.getState();\n const { pending, response } = state[_type];\n\n if (!pending && response) {\n unsubscribe();\n\n resolve(response);\n }\n });\n });\n }, type);\n}\n"],"names":["assert","createModuleLogger","waitFor","waitForPuppeteer","rootLogger","log","fn","timeout","message","result","undefined","error","Error","waitForResponse","page","type","evaluate","_type","Promise","resolve","window","__SIMULATOR_API__","dispatch","unsubscribe","subscribe","state","getState","pending","response"],"mappings":"AACA,SAASA,MAAM,EAAEC,kBAAkB,QAAQ,kBAAkB;AAC7D,SAASC,WAAWC,gBAAgB,QAAQ,uBAAuB;AAInE,SAASC,UAAU,QAAQ,WAAW;AActC,MAAMC,MAAMJ,mBAAmBG,YAAY;AAE3C;;;;;;;;;;;;CAYC,GACD,OAAO,eAAeF,QACpBI,EAAyB,EACzB,EAAEC,UAAU,IAAI,EAAEC,OAAO,EAAkB,GAAG,CAAC,CAAC;IAEhD,IAAI;QACF,IAAIC;QAEJ,MAAMN,iBACJ,kEAAkE;QAClE;YACE,oEAAoE;YACpE,oEAAoE;YACpE,6BAA6B;YAC7BM,SAAS,MAAMH;QACjB,GACA;YACEC;QACF;QAGFP,OAAOS,WAAWC;QAClB,OAAOD;IACT,EAAE,OAAOE,OAAO;QACd,IAAIH,SAAS;YACX,MAAM,IAAII,MAAMJ;QAClB;QAEA,MAAMG;IACR;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeE,gBACpBC,IAAU,EACVC,IAGyB;IAEzBV,IAAI,oCAAoCU;IAExC,OAAO,MAAMD,KAAKE,QAAQ,CAAC,OAAOC;QAChC,OAAO,IAAIC,QAAkC,CAACC;YAC5CC,OAAOC,iBAAiB,CAACC,QAAQ,CAAC;gBAChCP,MAAM,CAAC,EAAEE,MAAM,cAAc,CAAC;YAChC;YAEA,MAAMM,cAAcH,OAAOC,iBAAiB,CAACG,SAAS,CAAC;gBACrD,MAAMC,QAAQL,OAAOC,iBAAiB,CAACK,QAAQ;gBAC/C,MAAM,EAAEC,OAAO,EAAEC,QAAQ,EAAE,GAAGH,KAAK,CAACR,MAAM;gBAE1C,IAAI,CAACU,WAAWC,UAAU;oBACxBL;oBAEAJ,QAAQS;gBACV;YACF;QACF;IACF,GAAGb;AACL"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Page } from 'puppeteer';
|
|
2
|
-
import type { SnapInterface, SnapOptions } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Get the current snap user interface (i.e., dialog). This will throw an error
|
|
5
|
-
* if the snap does not show a user interface within the timeout.
|
|
6
|
-
*
|
|
7
|
-
* @param page - The page to get the interface from.
|
|
8
|
-
* @param options - The options to use.
|
|
9
|
-
* @param options.timeout - The timeout in milliseconds to use. Defaults to
|
|
10
|
-
* `1000`.
|
|
11
|
-
* @returns The user interface object.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getInterface(page: Page, options?: SnapOptions): Promise<SnapInterface>;
|
|
14
|
-
/**
|
|
15
|
-
* Get the text of the notifications.
|
|
16
|
-
*
|
|
17
|
-
* @param page - The page to get the notifications from.
|
|
18
|
-
* @param requestId - The ID of the request to get the notifications for.
|
|
19
|
-
* @returns The text of the notifications, in order of appearance.
|
|
20
|
-
*/
|
|
21
|
-
export declare function getNotifications(page: Page, requestId: string): Promise<{
|
|
22
|
-
id: string;
|
|
23
|
-
message: string;
|
|
24
|
-
type: "native" | "inApp";
|
|
25
|
-
}[]>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { Page, HTTPRequest } from 'puppeteer';
|
|
2
|
-
import type { Infer, Struct } from 'superstruct';
|
|
3
|
-
import type { DeepPartial } from '../types';
|
|
4
|
-
export declare type Unmock = () => Promise<void>;
|
|
5
|
-
export declare type Mock = {
|
|
6
|
-
/**
|
|
7
|
-
* A function that can be used to unmock the URL.
|
|
8
|
-
*/
|
|
9
|
-
unmock: Unmock;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* A function that can return `true` if the given request should be mocked, or
|
|
13
|
-
* false if not.
|
|
14
|
-
*
|
|
15
|
-
* @param request - The request to check.
|
|
16
|
-
* @returns Whether to mock the request.
|
|
17
|
-
*/
|
|
18
|
-
export declare type ConditionFunction = (request: HTTPRequest) => boolean;
|
|
19
|
-
export declare const MockOptionsStruct: Struct<{
|
|
20
|
-
response: {
|
|
21
|
-
headers: Record<string, unknown>;
|
|
22
|
-
status: number;
|
|
23
|
-
body: string;
|
|
24
|
-
contentType: string;
|
|
25
|
-
};
|
|
26
|
-
url: string | RegExp;
|
|
27
|
-
partial?: boolean | undefined;
|
|
28
|
-
} | {
|
|
29
|
-
response: {
|
|
30
|
-
headers: Record<string, unknown>;
|
|
31
|
-
status: number;
|
|
32
|
-
body: string;
|
|
33
|
-
contentType: string;
|
|
34
|
-
};
|
|
35
|
-
condition: ConditionFunction;
|
|
36
|
-
}, null>;
|
|
37
|
-
/**
|
|
38
|
-
* The options for the network mocking.
|
|
39
|
-
*
|
|
40
|
-
* @property url - The URL to mock. If a string is provided, the URL will be
|
|
41
|
-
* matched exactly. If a RegExp is provided, the URL will be matched against it.
|
|
42
|
-
* This option is incompatible with the `condition` option.
|
|
43
|
-
* @property partial - If enabled, the request will be mocked if the URL starts
|
|
44
|
-
* with the given URL. This option is ignored if a RegExp is provided to the
|
|
45
|
-
* `url` option. This option is incompatible with the `condition` option.
|
|
46
|
-
* @property condition - A function which gets the {@link HTTPRequest} as
|
|
47
|
-
* parameter and returns a boolean to indicate whether the response should be
|
|
48
|
-
* mocked or not. This option is incompatible with the `url` and `partial`
|
|
49
|
-
* options.
|
|
50
|
-
* @property response - The response to send for the request.
|
|
51
|
-
* @property response.status - The status code to send for the response.
|
|
52
|
-
* Defaults to `200`.
|
|
53
|
-
* @property response.headers - The headers to send for the response. Defaults
|
|
54
|
-
* to headers that enable CORS.
|
|
55
|
-
* @property response.contentType - The content type to send for the response.
|
|
56
|
-
* Defaults to `text/plain`.
|
|
57
|
-
*/
|
|
58
|
-
export declare type MockOptions = Infer<typeof MockOptionsStruct>;
|
|
59
|
-
/**
|
|
60
|
-
* Enable network mocking for the given page, and all its sub-frames.
|
|
61
|
-
*
|
|
62
|
-
* @param page - The page to enable network mocking on.
|
|
63
|
-
* @param options - The options for the network mocking.
|
|
64
|
-
* @returns A {@link Mock} object, with an `unmock` function.
|
|
65
|
-
*/
|
|
66
|
-
export declare function mock(page: Page, options: DeepPartial<MockOptions>): Promise<Mock>;
|
|
67
|
-
declare const MockJsonRpcOptionsStruct: Struct<{
|
|
68
|
-
method: string;
|
|
69
|
-
result: import("@metamask/utils").Json;
|
|
70
|
-
}, {
|
|
71
|
-
method: Struct<string, null>;
|
|
72
|
-
result: Struct<import("@metamask/utils").Json, unknown>;
|
|
73
|
-
}>;
|
|
74
|
-
export declare type MockJsonRpcOptions = Infer<typeof MockJsonRpcOptionsStruct>;
|
|
75
|
-
/**
|
|
76
|
-
* Mock an Ethereum JSON-RPC request. This intercepts all requests to the
|
|
77
|
-
* Ethereum provider, and returns the `result` instead.
|
|
78
|
-
*
|
|
79
|
-
* @param page - The page to enable network JSON-RPC mocking on.
|
|
80
|
-
* @param options - The options for the JSON-RPC mock.
|
|
81
|
-
* @param options.method - The JSON-RPC method to mock. Any other methods will be
|
|
82
|
-
* forwarded to the provider.
|
|
83
|
-
* @param options.result - The JSON response to return.
|
|
84
|
-
* @returns A {@link Mock} object, with an `unmock` function.
|
|
85
|
-
*/
|
|
86
|
-
export declare function mockJsonRpc(page: Page, { method, result }: MockJsonRpcOptions): Promise<Mock>;
|
|
87
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
|
|
2
|
-
import type { ApplicationState, Dispatch } from '@metamask/snaps-simulator';
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
__SIMULATOR_API__: {
|
|
6
|
-
dispatch: Dispatch;
|
|
7
|
-
subscribe: (listener: () => void) => () => void;
|
|
8
|
-
getState: () => ApplicationState;
|
|
9
|
-
getRequestId: () => string;
|
|
10
|
-
getNotifications: (requestId: string) => {
|
|
11
|
-
id: string;
|
|
12
|
-
message: string;
|
|
13
|
-
type: EnumToUnion<NotificationType>;
|
|
14
|
-
}[];
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { HandlerType } from '@metamask/snaps-utils';
|
|
2
|
-
import type { Page } from 'puppeteer';
|
|
3
|
-
export declare type WaitForOptions = {
|
|
4
|
-
/**
|
|
5
|
-
* The timeout in milliseconds.
|
|
6
|
-
*/
|
|
7
|
-
timeout?: number;
|
|
8
|
-
/**
|
|
9
|
-
* The error message to throw if the condition is not met.
|
|
10
|
-
*/
|
|
11
|
-
message?: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Wait for a condition to be true. This is a wrapper around
|
|
15
|
-
* `pptr-testing-library`'s `waitFor` function, with the addition of a custom
|
|
16
|
-
* error message.
|
|
17
|
-
*
|
|
18
|
-
* @param fn - The condition to wait for.
|
|
19
|
-
* @param options - The options.
|
|
20
|
-
* @param options.timeout - The timeout in milliseconds.
|
|
21
|
-
* @param options.message - The error message to throw if the condition is not
|
|
22
|
-
* met.
|
|
23
|
-
* @returns A promise that resolves when the condition is met. The promise
|
|
24
|
-
* resolves to the return value of the condition function.
|
|
25
|
-
*/
|
|
26
|
-
export declare function waitFor<Result>(fn: () => Promise<Result>, { timeout, message }?: WaitForOptions): Promise<Result & ({} | null)>;
|
|
27
|
-
/**
|
|
28
|
-
* Wait for a JSON-RPC response.
|
|
29
|
-
*
|
|
30
|
-
* @param page - The page to wait for the response on.
|
|
31
|
-
* @param type - The type of response to wait for.
|
|
32
|
-
* @returns The JSON-RPC response.
|
|
33
|
-
*/
|
|
34
|
-
export declare function waitForResponse(page: Page, type: HandlerType.OnTransaction | HandlerType.OnRpcRequest | HandlerType.OnCronjob): Promise<{
|
|
35
|
-
result: import("@metamask/utils").Json;
|
|
36
|
-
} | {
|
|
37
|
-
error: import("@metamask/utils").Json;
|
|
38
|
-
}>;
|