1import { ExpoConfig } from '@expo/config';
2import fs from 'fs';
3import { vol } from 'memfs';
4import path from 'path';
5
6import { withGradleProperties } from '../android-plugins';
7import { evalModsAsync } from '../mod-compiler';
8import { getAndroidModFileProviders, withAndroidBaseMods } from '../withAndroidBaseMods';
9import rnFixture from './fixtures/react-native-project';
10
11jest.mock('fs');
12
13describe(withGradleProperties, () => {
14  const projectRoot = '/app';
15
16  beforeEach(async () => {
17    vol.fromJSON(rnFixture, projectRoot);
18  });
19
20  afterEach(() => {
21    vol.reset();
22  });
23
24  it(`is passed gradle.properties`, async () => {
25    let config: ExpoConfig = {
26      name: 'foobar',
27      slug: 'foobar',
28    };
29
30    config = withGradleProperties(config, (config) => {
31      config.modResults.push({ type: 'comment', value: 'expo-test' });
32      config.modResults.push({ type: 'empty' });
33      config.modResults.push({ type: 'property', key: 'foo', value: 'bar' });
34      config.modResults.push({ type: 'empty' });
35      config.modResults.push({ type: 'comment', value: 'end-expo-test' });
36      return config;
37    });
38    config = withAndroidBaseMods(config, {
39      providers: {
40        gradleProperties: getAndroidModFileProviders().gradleProperties,
41      },
42    });
43
44    await evalModsAsync(config, {
45      projectRoot,
46      platforms: ['android'],
47      assertMissingModProviders: true,
48    });
49
50    const contents = fs.readFileSync(path.join(projectRoot, 'android/gradle.properties'), 'utf8');
51    expect(contents.endsWith('# expo-test\n\nfoo=bar\n\n# end-expo-test')).toBe(true);
52  });
53});
54