Skip to content

Commit

Permalink
Reexport some helper functions and reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Sep 17, 2024
1 parent 5b10901 commit 22c82ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 50 deletions.
10 changes: 5 additions & 5 deletions packages/snaps-jest/src/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { NodeProcessExecutionService } from '@metamask/snaps-controllers/node';
import { DialogType } from '@metamask/snaps-sdk';
import { Text } from '@metamask/snaps-sdk/jsx';
import type { InstallSnapOptions } from '@metamask/snaps-simulation';
import { installSnap as simulateSnap } from '@metamask/snaps-simulation';
import { getSnapManifest } from '@metamask/snaps-utils/test-utils';

import {
assertIsAlertDialog,
assertIsConfirmationDialog,
assertIsPromptDialog,
installSnap,
} from './helpers';
installSnap as simulateSnap,
} from '@metamask/snaps-simulation';
import { getSnapManifest } from '@metamask/snaps-utils/test-utils';

import { installSnap } from './helpers';
import { getMockServer } from './test-utils';

describe('installSnap', () => {
Expand Down
46 changes: 1 addition & 45 deletions packages/snaps-jest/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { AbstractExecutionService } from '@metamask/snaps-controllers';
import type { SnapId } from '@metamask/snaps-sdk';
import { DialogType } from '@metamask/snaps-sdk';
import type { InstallSnapOptions } from '@metamask/snaps-simulation';
import {
JsonRpcMockOptionsStruct,
Expand All @@ -13,12 +12,7 @@ import {
} from '@metamask/snaps-simulation';
import { HandlerType, logInfo } from '@metamask/snaps-utils';
import { create } from '@metamask/superstruct';
import {
assert,
assertStruct,
createModuleLogger,
hasProperty,
} from '@metamask/utils';
import { assertStruct, createModuleLogger } from '@metamask/utils';

import { rootLogger, getEnvironment } from './internals';
import type {
Expand All @@ -28,11 +22,6 @@ import type {
Snap,
SnapResponse,
TransactionOptions,
SnapInterface,
SnapAlertInterface,
SnapInterfaceActions,
SnapConfirmationInterface,
SnapPromptInterface,
} from './types';

const log = createModuleLogger(rootLogger, 'helpers');
Expand Down Expand Up @@ -70,39 +59,6 @@ function assertIsResponseWithInterface(
assertStruct(response, SnapResponseWithInterfaceStruct);
}

/**
* Ensure that the actual interface is an alert dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsAlertDialog(
ui: SnapInterface,
): asserts ui is SnapAlertInterface & SnapInterfaceActions {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);
}

/**
* Ensure that the actual interface is a confirmation dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsConfirmationDialog(
ui: SnapInterface,
): asserts ui is SnapConfirmationInterface & SnapInterfaceActions {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);
}

/**
* Ensure that the actual interface is a Prompt dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsPromptDialog(
ui: SnapInterface,
): asserts ui is SnapPromptInterface & SnapInterfaceActions {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);
}

/**
* Load a snap into the environment. This is the main entry point for testing
* snaps: It returns a {@link Snap} object that can be used to interact with the
Expand Down
9 changes: 9 additions & 0 deletions packages/snaps-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ export { default, default as TestEnvironment } from './environment';
export * from './helpers';
export * from './options';
export * from './types';

export {
assertCustomDialogHasNoFooter,
assertCustomDialogHasPartialFooter,
assertIsAlertDialog,
assertIsConfirmationDialog,
assertIsCustomDialog,
assertIsPromptDialog,
} from '@metamask/snaps-simulation';

0 comments on commit 22c82ca

Please sign in to comment.