|
| 1 | +import { Platform, Workflow } from '@expo/eas-build-job'; |
| 2 | +import getenv from 'getenv'; |
| 3 | +import resolveFrom from 'resolve-from'; |
| 4 | + |
| 5 | +import type { ProfileData } from '../../utils/profiles'; |
| 6 | +import { resolveVcsClient } from '../../vcs'; |
| 7 | +import { detectExpoGoProdBuildAsync } from '../discourageExpoGoForProd'; |
| 8 | + |
| 9 | +jest.mock('getenv'); |
| 10 | +jest.mock('resolve-from'); |
| 11 | +jest.mock('../workflow', () => ({ |
| 12 | + resolveWorkflowPerPlatformAsync: jest.fn(), |
| 13 | +})); |
| 14 | + |
| 15 | +const mockResolveWorkflowPerPlatformAsync = jest.mocked( |
| 16 | + require('../workflow').resolveWorkflowPerPlatformAsync |
| 17 | +); |
| 18 | + |
| 19 | +const projectDir = '/app'; |
| 20 | +const vcsClient = resolveVcsClient(); |
| 21 | + |
| 22 | +const createMockBuildProfile = (profileName: string): ProfileData<'build'> => ({ |
| 23 | + profileName, |
| 24 | + platform: Platform.ANDROID, |
| 25 | + profile: {} as any, |
| 26 | +}); |
| 27 | + |
| 28 | +describe(detectExpoGoProdBuildAsync, () => { |
| 29 | + beforeEach(() => { |
| 30 | + jest.clearAllMocks(); |
| 31 | + jest.mocked(getenv.boolish).mockReturnValue(false); |
| 32 | + jest.mocked(resolveFrom.silent).mockReturnValue(undefined); // expo-dev-client is not installed |
| 33 | + }); |
| 34 | + |
| 35 | + describe('should return false', () => { |
| 36 | + it.each([ |
| 37 | + ['non-production profiles', [createMockBuildProfile('development')]], |
| 38 | + ['undefined buildProfiles', undefined], |
| 39 | + ['empty buildProfiles', []], |
| 40 | + ])('should return false for %s', async (_, buildProfiles) => { |
| 41 | + const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); |
| 42 | + |
| 43 | + expect(result).toBe(false); |
| 44 | + expect(mockResolveWorkflowPerPlatformAsync).not.toHaveBeenCalled(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('when expo-dev-client is installed - that signals development build', async () => { |
| 48 | + jest.mocked(resolveFrom.silent).mockReturnValue('/path/to/expo-dev-client/package.json'); |
| 49 | + const buildProfiles = [createMockBuildProfile('production')]; |
| 50 | + |
| 51 | + const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); |
| 52 | + |
| 53 | + expect(result).toBe(false); |
| 54 | + expect(mockResolveWorkflowPerPlatformAsync).not.toHaveBeenCalled(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('when either platform is "generic" - likely a bare RN project', async () => { |
| 58 | + mockResolveWorkflowPerPlatformAsync.mockResolvedValue({ |
| 59 | + android: Workflow.GENERIC, |
| 60 | + ios: Workflow.GENERIC, |
| 61 | + }); |
| 62 | + const buildProfiles = [createMockBuildProfile('production')]; |
| 63 | + |
| 64 | + const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); |
| 65 | + |
| 66 | + expect(result).toBe(false); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + describe('should return true', () => { |
| 71 | + it('when production profile is used, there are no native directories (or are gitignored) AND expo-dev-client is not installed', async () => { |
| 72 | + mockResolveWorkflowPerPlatformAsync.mockResolvedValue({ |
| 73 | + android: Workflow.MANAGED, |
| 74 | + ios: Workflow.MANAGED, |
| 75 | + }); |
| 76 | + const buildProfiles = [createMockBuildProfile('production')]; |
| 77 | + |
| 78 | + const result = await detectExpoGoProdBuildAsync(buildProfiles, projectDir, vcsClient); |
| 79 | + |
| 80 | + expect(result).toBe(true); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
0 commit comments