1import { getConfig } from '@expo/config';
2import { vol } from 'memfs';
3
4import { ensureConfigExistsAsync } from '../ensureConfigAsync';
5
6describe(ensureConfigExistsAsync, () => {
7  const projectRoot = '/alpha';
8  const projectRootBeta = '/beta';
9
10  beforeAll(() => {
11    const expoPackageJson = JSON.stringify({
12      name: 'expo',
13      version: '40.0.0',
14    });
15
16    vol.fromJSON(
17      {
18        // No app.json, the config should be automatically created using the Expo SDK version in the installed package.
19        'index.js': '',
20        'src/index.js': '',
21        'package.json': JSON.stringify({ name: 'my-app' }),
22        'node_modules/expo/package.json': expoPackageJson,
23      },
24      projectRoot
25    );
26    vol.fromJSON(
27      {
28        'App.js': '',
29      },
30      projectRootBeta
31    );
32  });
33
34  afterAll(() => {
35    vol.reset();
36  });
37
38  it(`automatically writes an Expo config when one is missing`, async () => {
39    await ensureConfigExistsAsync(projectRoot);
40    const config = getConfig(projectRoot);
41
42    // Writes a static config
43    expect(config.staticConfigPath).toBe('/alpha/app.json');
44    expect(config.dynamicConfigPath).toBe(null);
45
46    expect(config.exp.sdkVersion).toBe('40.0.0');
47    expect(config.exp.name).toBe('my-app');
48    // Ensure the internal object isn't written
49    expect(config.rootConfig._internal).not.toBeDefined();
50  });
51});
52