1import { vol } from 'memfs';
2
3import { getPublicExpoManifestAsync } from '../getPublicExpoManifest';
4
5jest.mock('fs');
6
7describe(getPublicExpoManifestAsync, () => {
8  afterAll(() => {
9    vol.reset();
10  });
11
12  const runtimeVersion = 'one';
13  const sdkVersion = '40.0.0';
14  it('Passes if sdkVersion is not specified', async () => {
15    vol.fromJSON(
16      {
17        'package.json': JSON.stringify({}),
18        'app.json': JSON.stringify({
19          name: 'hello',
20          slug: 'hello',
21          version: '1.0.0',
22          runtimeVersion,
23          platforms: [],
24        }),
25      },
26      'runtimeVersion'
27    );
28    const config = await getPublicExpoManifestAsync('runtimeVersion');
29    expect(config).toMatchObject({ sdkVersion: undefined, runtimeVersion });
30  });
31  it('reads sdkVersion from node module', async () => {
32    vol.fromJSON(
33      {
34        'package.json': JSON.stringify({}),
35        'app.json': JSON.stringify({
36          name: 'hello',
37          slug: 'hello',
38          version: '1.0.0',
39          platforms: [],
40        }),
41        'node_modules/expo/package.json': JSON.stringify({
42          version: sdkVersion,
43        }),
44      },
45      'sdkVersion'
46    );
47    const config = await getPublicExpoManifestAsync('sdkVersion');
48    expect(config).toMatchObject({ sdkVersion });
49  });
50  it('reads sdkVersion from app.json', async () => {
51    vol.fromJSON(
52      {
53        'package.json': JSON.stringify({}),
54        'app.json': JSON.stringify({
55          name: 'hello',
56          slug: 'hello',
57          version: '1.0.0',
58          sdkVersion,
59          platforms: [],
60        }),
61      },
62      'sdkVersionInAppDotJson'
63    );
64    const config = await getPublicExpoManifestAsync('sdkVersionInAppDotJson');
65    expect(config).toMatchObject({ sdkVersion });
66  });
67});
68