Skip to content

Commit acf7b1f

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

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
@@ -6,6 +6,7 @@ import { createMockLogger } from '../../__tests__/utils/logger';
66
import { BuildContext } from '../../context';
77
import { Datadog } from '../../datadog';
88
import { restoreCredentials } from '../../android/credentials';
9+
import { uploadEmbeddedBundleAsync } from '../../utils/expoUpdatesEmbedded';
910
import androidBuilder from '../android';
1011
import { runBuilderWithHooksAsync } from '../common';
1112
import {
@@ -57,6 +58,9 @@ jest.mock('../../utils/expoUpdates', () => ({
5758
configureExpoUpdatesIfInstalledAsync: jest.fn(),
5859
resolveRuntimeVersionForExpoUpdatesIfConfiguredAsync: jest.fn(async () => null),
5960
}));
61+
jest.mock('../../utils/expoUpdatesEmbedded', () => ({
62+
uploadEmbeddedBundleAsync: jest.fn(),
63+
}));
6064
jest.mock('../../utils/hooks', () => ({
6165
Hook: {
6266
POST_INSTALL: 'POST_INSTALL',
@@ -269,4 +273,37 @@ describe(androidBuilder, () => {
269273

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

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)