|
| 1 | +import { getConfigFilePaths } from '@expo/config'; |
| 2 | + |
| 3 | +import { getWorkflowRunUrl } from '../../build/utils/url'; |
| 4 | +import Go from '../../commands/go'; |
| 5 | +import { WorkflowRunStatus } from '../../graphql/generated'; |
| 6 | +import { WorkflowRunMutation } from '../../graphql/mutations/WorkflowRunMutation'; |
| 7 | +import { WorkflowRunQuery } from '../../graphql/queries/WorkflowRunQuery'; |
| 8 | +import Log from '../../log'; |
| 9 | +import { getPrivateExpoConfigAsync } from '../../project/expoConfig'; |
| 10 | +import { uploadAccountScopedFileAsync } from '../../project/uploadAccountScopedFileAsync'; |
| 11 | +import { uploadAccountScopedProjectSourceAsync } from '../../project/uploadAccountScopedProjectSourceAsync'; |
| 12 | +import { ensureActorHasPrimaryAccount } from '../../user/actions'; |
| 13 | +import { detectProjectSdkVersionAsync } from '../../commands/go'; |
| 14 | +import { mockTestCommand } from './utils'; |
| 15 | + |
| 16 | +jest.mock('@expo/config', () => ({ |
| 17 | + ...jest.requireActual('@expo/config'), |
| 18 | + getConfigFilePaths: jest.fn(), |
| 19 | +})); |
| 20 | +jest.mock('../../project/expoConfig'); |
| 21 | +jest.mock('../../log', () => ({ |
| 22 | + __esModule: true, |
| 23 | + default: { |
| 24 | + log: jest.fn(), |
| 25 | + withTick: jest.fn(), |
| 26 | + newLine: jest.fn(), |
| 27 | + succeed: jest.fn(), |
| 28 | + debug: jest.fn(), |
| 29 | + markFreshLine: jest.fn(), |
| 30 | + error: jest.fn(), |
| 31 | + }, |
| 32 | + learnMore: jest.fn().mockReturnValue(''), |
| 33 | +})); |
| 34 | +jest.mock('../../ora', () => ({ |
| 35 | + ora: jest.fn().mockReturnValue({ |
| 36 | + start: jest.fn().mockReturnThis(), |
| 37 | + stop: jest.fn().mockReturnThis(), |
| 38 | + fail: jest.fn().mockReturnThis(), |
| 39 | + succeed: jest.fn().mockReturnThis(), |
| 40 | + }), |
| 41 | +})); |
| 42 | +jest.mock('fs-extra', () => ({ |
| 43 | + ensureDir: jest.fn().mockResolvedValue(undefined), |
| 44 | + writeFile: jest.fn().mockResolvedValue(undefined), |
| 45 | + remove: jest.fn().mockResolvedValue(undefined), |
| 46 | +})); |
| 47 | +jest.mock('../../user/actions'); |
| 48 | +jest.mock('../../graphql/queries/WorkflowRunQuery'); |
| 49 | +jest.mock('../../graphql/mutations/WorkflowRunMutation'); |
| 50 | +jest.mock('../../project/uploadAccountScopedFileAsync'); |
| 51 | +jest.mock('../../project/uploadAccountScopedProjectSourceAsync'); |
| 52 | +jest.mock('../../build/utils/url'); |
| 53 | + |
| 54 | +const mockGetConfigFilePaths = jest.mocked(getConfigFilePaths); |
| 55 | +const mockGetPrivateExpoConfigAsync = jest.mocked(getPrivateExpoConfigAsync); |
| 56 | + |
| 57 | +describe('detectProjectSdkVersionAsync', () => { |
| 58 | + it('returns undefined when no config file exists', async () => { |
| 59 | + mockGetConfigFilePaths.mockReturnValue({ staticConfigPath: null, dynamicConfigPath: null }); |
| 60 | + await expect(detectProjectSdkVersionAsync('/project')).resolves.toBeUndefined(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('returns the sdkVersion from the project config', async () => { |
| 64 | + mockGetConfigFilePaths.mockReturnValue({ |
| 65 | + staticConfigPath: '/project/app.json', |
| 66 | + dynamicConfigPath: null, |
| 67 | + }); |
| 68 | + mockGetPrivateExpoConfigAsync.mockResolvedValue({ sdkVersion: '55.0.0' } as any); |
| 69 | + await expect(detectProjectSdkVersionAsync('/project')).resolves.toBe('55.0.0'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('returns undefined when reading the config throws', async () => { |
| 73 | + mockGetConfigFilePaths.mockReturnValue({ |
| 74 | + staticConfigPath: '/project/app.json', |
| 75 | + dynamicConfigPath: null, |
| 76 | + }); |
| 77 | + mockGetPrivateExpoConfigAsync.mockRejectedValue(new Error('config error')); |
| 78 | + await expect(detectProjectSdkVersionAsync('/project')).resolves.toBeUndefined(); |
| 79 | + }); |
| 80 | +}); |
| 81 | + |
| 82 | +const mockAccount = { id: 'account-id', name: 'testuser' }; |
| 83 | +const mockActor = { |
| 84 | + __typename: 'User' as const, |
| 85 | + id: 'user-id', |
| 86 | + username: 'testuser', |
| 87 | + primaryAccount: mockAccount, |
| 88 | +}; |
| 89 | + |
| 90 | +describe('Go command', () => { |
| 91 | + beforeEach(() => { |
| 92 | + jest.mocked(ensureActorHasPrimaryAccount).mockReturnValue(mockAccount as any); |
| 93 | + jest.mocked(WorkflowRunQuery.expoGoRepackConfigurationAsync).mockResolvedValue({ |
| 94 | + files: [], |
| 95 | + sdkVersion: '55.0.0', |
| 96 | + } as any); |
| 97 | + jest.mocked(WorkflowRunMutation.createExpoGoRepackWorkflowRunAsync).mockResolvedValue({ |
| 98 | + id: 'run-id', |
| 99 | + } as any); |
| 100 | + jest.mocked(uploadAccountScopedProjectSourceAsync).mockResolvedValue({ |
| 101 | + projectArchiveBucketKey: 'archive-key', |
| 102 | + }); |
| 103 | + jest |
| 104 | + .mocked(uploadAccountScopedFileAsync) |
| 105 | + .mockResolvedValue({ fileBucketKey: 'file-key' } as any); |
| 106 | + jest.mocked(getWorkflowRunUrl).mockReturnValue('https://expo.dev/run/123'); |
| 107 | + }); |
| 108 | + |
| 109 | + afterEach(() => { |
| 110 | + jest.clearAllMocks(); |
| 111 | + }); |
| 112 | + |
| 113 | + function makeCmd(argv: string[] = []) { |
| 114 | + const ctx = { |
| 115 | + loggedIn: { actor: mockActor as any, graphqlClient: {} as any }, |
| 116 | + analytics: {} as any, |
| 117 | + }; |
| 118 | + const cmd = mockTestCommand(Go, ['--bundle-id', 'com.test.go', ...argv], ctx); |
| 119 | + jest.spyOn(cmd as any, 'ensureEasProjectAsync').mockResolvedValue('project-id'); |
| 120 | + jest.spyOn(cmd as any, 'setupCredentialsAsync').mockResolvedValue({ id: 'asc-app-id' }); |
| 121 | + jest.spyOn(cmd as any, 'monitorWorkflowJobsAsync').mockResolvedValue(WorkflowRunStatus.Success); |
| 122 | + return cmd; |
| 123 | + } |
| 124 | + |
| 125 | + it('logs auto-selected SDK message and reports resolved version after dispatch', async () => { |
| 126 | + mockGetConfigFilePaths.mockReturnValue({ |
| 127 | + staticConfigPath: '/app.json', |
| 128 | + dynamicConfigPath: null, |
| 129 | + }); |
| 130 | + mockGetPrivateExpoConfigAsync.mockResolvedValue({ sdkVersion: '55.0.0' } as any); |
| 131 | + |
| 132 | + await makeCmd().run(); |
| 133 | + |
| 134 | + expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('SDK 55')); |
| 135 | + expect(Log.withTick).toHaveBeenCalledWith(expect.stringContaining('Using Expo Go SDK')); |
| 136 | + }); |
| 137 | + |
| 138 | + it('skips auto-select log when --sdk-version flag is provided', async () => { |
| 139 | + mockGetConfigFilePaths.mockReturnValue({ |
| 140 | + staticConfigPath: '/app.json', |
| 141 | + dynamicConfigPath: null, |
| 142 | + }); |
| 143 | + mockGetPrivateExpoConfigAsync.mockResolvedValue({ sdkVersion: '55.0.0' } as any); |
| 144 | + |
| 145 | + await makeCmd(['--sdk-version', '55.0.0']).run(); |
| 146 | + |
| 147 | + expect(Log.log).not.toHaveBeenCalledWith(expect.stringContaining('Auto-selected')); |
| 148 | + }); |
| 149 | +}); |
0 commit comments