Skip to content

Commit c41e8ab

Browse files
committed
Fix SwiftPM download retry tests under Jest
1 parent 5b54e17 commit c41e8ab

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/react-native/scripts/spm/__tests__/download-spm-artifacts-test.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,17 @@ describe('exists', () => {
553553
describe('download', () => {
554554
let originalFetch;
555555
let tempDir;
556+
let warnSpy;
556557

557558
beforeEach(() => {
558559
originalFetch = globalThis.fetch;
559560
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'spm-download-'));
561+
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
560562
});
561563

562564
afterEach(() => {
563565
globalThis.fetch = originalFetch;
566+
warnSpy.mockRestore();
564567
fs.rmSync(tempDir, {recursive: true, force: true});
565568
});
566569

@@ -596,9 +599,19 @@ describe('download', () => {
596599
.mockResolvedValueOnce(downloadResponse('complete'));
597600
const destination = path.join(tempDir, 'artifact.tar.gz');
598601

599-
await download('https://example/artifact.tar.gz', destination, () => {});
602+
const pending = download(
603+
'https://example/artifact.tar.gz',
604+
destination,
605+
() => {},
606+
);
607+
await jest.advanceTimersByTimeAsync(1_500);
608+
await pending;
600609

601610
expect(globalThis.fetch).toHaveBeenCalledTimes(2);
611+
expect(warnSpy).toHaveBeenCalledTimes(1);
612+
expect(warnSpy).toHaveBeenCalledWith(
613+
expect.stringContaining('retrying in 1000ms'),
614+
);
602615
expect(fs.readFileSync(destination, 'utf8')).toBe('complete');
603616
expect(fs.existsSync(`${destination}.download`)).toBe(false);
604617
});
@@ -621,6 +634,10 @@ describe('download', () => {
621634
await pending;
622635

623636
expect(globalThis.fetch).toHaveBeenCalledTimes(2);
637+
expect(warnSpy).toHaveBeenCalledTimes(1);
638+
expect(warnSpy).toHaveBeenCalledWith(
639+
expect.stringContaining('retrying in 1000ms'),
640+
);
624641
expect(fs.readFileSync(destination, 'utf8')).toBe('complete');
625642
expect(fs.existsSync(`${destination}.download`)).toBe(false);
626643
} finally {
@@ -643,6 +660,7 @@ describe('download', () => {
643660
).rejects.toThrow(/HTTP 404/);
644661

645662
expect(globalThis.fetch).toHaveBeenCalledTimes(1);
663+
expect(warnSpy).not.toHaveBeenCalled();
646664
expect(fs.existsSync(destination)).toBe(false);
647665
});
648666
});

0 commit comments

Comments
 (0)