Skip to content

Commit a4deecb

Browse files
committed
Add tests for upload error paths and builder env gate
1 parent dec3375 commit a4deecb

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

packages/build-tools/src/builders/__tests__/android.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createTestAndroidJob } from '../../__tests__/utils/job';
55
import { createMockLogger } from '../../__tests__/utils/logger';
66
import { BuildContext } from '../../context';
77
import { restoreCredentials } from '../../android/credentials';
8+
import { uploadEmbeddedBundleAsync } from '../../utils/expoUpdatesEmbedded';
89
import androidBuilder from '../android';
910
import { runBuilderWithHooksAsync } from '../common';
1011
import {
@@ -56,6 +57,9 @@ jest.mock('../../utils/expoUpdates', () => ({
5657
configureExpoUpdatesIfInstalledAsync: jest.fn(),
5758
resolveRuntimeVersionForExpoUpdatesIfConfiguredAsync: jest.fn(async () => null),
5859
}));
60+
jest.mock('../../utils/expoUpdatesEmbedded', () => ({
61+
uploadEmbeddedBundleAsync: jest.fn(),
62+
}));
5963
jest.mock('../../utils/hooks', () => ({
6064
Hook: {
6165
POST_INSTALL: 'POST_INSTALL',
@@ -263,4 +267,37 @@ describe(androidBuilder, () => {
263267

264268
expect(runBuilderWithHooksAsync).toHaveBeenCalledWith(ctx, expect.any(Function));
265269
});
270+
271+
it('runs the embedded bundle upload phase when EAS_UPDATE_EXPERIMENTAL_UPLOAD_EMBEDDED_BUNDLE is set', async () => {
272+
const ctx = new BuildContext(createTestAndroidJob(), {
273+
workingdir: '/workingdir',
274+
logBuffer: { getLogs: () => [], getPhaseLogs: () => [] },
275+
logger: createMockLogger(),
276+
env: {
277+
__API_SERVER_URL: 'http://api.expo.test',
278+
EAS_UPDATE_EXPERIMENTAL_UPLOAD_EMBEDDED_BUNDLE: '1',
279+
},
280+
uploadArtifact: jest.fn(),
281+
});
282+
283+
await androidBuilder(ctx);
284+
285+
expect(uploadEmbeddedBundleAsync).toHaveBeenCalledWith(ctx);
286+
});
287+
288+
it('skips the embedded bundle upload phase when EAS_UPDATE_EXPERIMENTAL_UPLOAD_EMBEDDED_BUNDLE is not set', async () => {
289+
const ctx = new BuildContext(createTestAndroidJob(), {
290+
workingdir: '/workingdir',
291+
logBuffer: { getLogs: () => [], getPhaseLogs: () => [] },
292+
logger: createMockLogger(),
293+
env: {
294+
__API_SERVER_URL: 'http://api.expo.test',
295+
},
296+
uploadArtifact: jest.fn(),
297+
});
298+
299+
await androidBuilder(ctx);
300+
301+
expect(uploadEmbeddedBundleAsync).not.toHaveBeenCalled();
302+
});
266303
});

packages/build-tools/src/utils/__tests__/expoUpdatesEmbedded.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,50 @@ describe('uploadEmbeddedBundleAsync', () => {
197197
);
198198
expect(easCli.runEasCliCommand).not.toHaveBeenCalled();
199199
});
200+
201+
it('warns when build archive is not found', async () => {
202+
jest.mocked(artifacts.findArtifacts).mockResolvedValue([]);
203+
const ctx = makeCtx({ platform: Platform.ANDROID, channel: 'production' });
204+
205+
await uploadEmbeddedBundleAsync(ctx);
206+
207+
expect(ctx.logger.warn).toHaveBeenCalledWith(
208+
'Skipping embedded bundle upload: build archive not found.'
209+
);
210+
expect(ctx.markBuildPhaseHasWarnings).toHaveBeenCalled();
211+
expect(easCli.runEasCliCommand).not.toHaveBeenCalled();
212+
});
213+
214+
it('treats findArtifacts errors as no archive found', async () => {
215+
jest.mocked(artifacts.findArtifacts).mockRejectedValue(new Error('glob failed'));
216+
const ctx = makeCtx({ platform: Platform.ANDROID, channel: 'production' });
217+
218+
await uploadEmbeddedBundleAsync(ctx);
219+
220+
expect(ctx.logger.warn).toHaveBeenCalledWith(
221+
'Skipping embedded bundle upload: build archive not found.'
222+
);
223+
expect(ctx.markBuildPhaseHasWarnings).toHaveBeenCalled();
224+
expect(easCli.runEasCliCommand).not.toHaveBeenCalled();
225+
});
226+
227+
it('warns and continues when CLI upload throws', async () => {
228+
jest.mocked(artifacts.findArtifacts).mockResolvedValue(['/tmp/app-release.apk']);
229+
mockZipEntries.mockResolvedValue(
230+
zipEntryMap({
231+
'assets/index.android.bundle': true,
232+
'assets/app.manifest': true,
233+
})
234+
);
235+
jest.mocked(easCli.runEasCliCommand).mockRejectedValue(new Error('upload failed'));
236+
const ctx = makeCtx({ platform: Platform.ANDROID, channel: 'production' });
237+
238+
await uploadEmbeddedBundleAsync(ctx);
239+
240+
expect(ctx.logger.warn).toHaveBeenCalledWith(
241+
expect.objectContaining({ err: expect.any(Error) }),
242+
'Failed to upload embedded bundle.'
243+
);
244+
expect(ctx.markBuildPhaseHasWarnings).toHaveBeenCalled();
245+
});
200246
});

0 commit comments

Comments
 (0)