1import { ExpoConfig } from '@expo/config';
2
3import { ConfigPlugin, ExportedConfigWithProps, Mod } from '../../Plugin.types';
4
5// Usage: add the following mock to the mods you are using:
6// jest.mock('../../plugins/android-plugins');
7
8export function mockModWithResults(withMod, modResults) {
9  withMod.mockImplementationOnce((config, action) => {
10    return action({ ...config, modResults });
11  });
12}
13
14/**
15 * Mock a single mod and evaluate the plugin that uses that mod
16 * @param config
17 * @param param1
18 * @returns
19 */
20export async function compileMockModWithResultsAsync<T>(
21  config: Partial<ExpoConfig>,
22  {
23    mod,
24    plugin,
25    modResults,
26  }: {
27    mod: ConfigPlugin<Mod<T>>;
28    plugin: ConfigPlugin;
29    modResults: T;
30  }
31): Promise<ExportedConfigWithProps<T>> {
32  mockModWithResults(mod, modResults);
33  return (await plugin(config as any)) as ExportedConfigWithProps<T>;
34}
35