From 1d649bd52d2bab8f877a20212ec09a2e26adf2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Wed, 27 May 2026 08:37:36 +0200 Subject: [PATCH 1/3] test: add font config and asset loading harness tests Covers RiveFonts API (loadFont by name/URL, systemFallback, setFallbackFonts, clearFallbackFonts, error path) and referencedAssets loading (font/image assets with explicit types, multiple assets, undefined assets). --- example/__tests__/asset-loading.harness.ts | 48 ++++++++++++++++++++ example/__tests__/font-config.harness.ts | 51 ++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 example/__tests__/asset-loading.harness.ts create mode 100644 example/__tests__/font-config.harness.ts diff --git a/example/__tests__/asset-loading.harness.ts b/example/__tests__/asset-loading.harness.ts new file mode 100644 index 00000000..6a91defc --- /dev/null +++ b/example/__tests__/asset-loading.harness.ts @@ -0,0 +1,48 @@ +import { describe, it, expect } from 'react-native-harness'; +import { RiveFileFactory } from '@rive-app/react-native'; + +const OUT_OF_BAND = require('../assets/rive/out_of_band.riv'); + +describe('Asset loading with referencedAssets', () => { + it('loads file with font asset (type: font)', async () => { + const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { + 'Inter-594377': { + sourceAssetId: 'Inter-594377.ttf', + type: 'font', + }, + }); + expect(file).toBeDefined(); + expect(file.artboardNames.length).toBeGreaterThan(0); + }); + + it('loads file with image asset via URL (type: image)', async () => { + const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { + 'referenced-image-2929282': { + sourceUrl: 'https://picsum.photos/id/237/200/200', + type: 'image', + }, + }); + expect(file).toBeDefined(); + expect(file.artboardNames.length).toBeGreaterThan(0); + }); + + it('loads file with multiple asset types', async () => { + const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { + 'Inter-594377': { + sourceAssetId: 'Inter-594377.ttf', + type: 'font', + }, + 'referenced-image-2929282': { + sourceUrl: 'https://picsum.photos/id/237/200/200', + type: 'image', + }, + }); + expect(file).toBeDefined(); + }); + + it('loads file without referencedAssets (undefined)', async () => { + const file = await RiveFileFactory.fromSource(OUT_OF_BAND, undefined); + expect(file).toBeDefined(); + expect(file.artboardNames.length).toBeGreaterThan(0); + }); +}); diff --git a/example/__tests__/font-config.harness.ts b/example/__tests__/font-config.harness.ts new file mode 100644 index 00000000..33b8f7b9 --- /dev/null +++ b/example/__tests__/font-config.harness.ts @@ -0,0 +1,51 @@ +import { describe, it, expect } from 'react-native-harness'; +import { RiveFonts } from '@rive-app/react-native'; + +describe('RiveFonts', () => { + it('systemFallback() returns a font object', () => { + const font = RiveFonts.systemFallback(); + expect(font).toBeDefined(); + }); + + it('loadFont with system font name', async () => { + const font = await RiveFonts.loadFont({ name: 'Helvetica' }); + expect(font).toBeDefined(); + }); + + it('loadFont with URL', async () => { + const font = await RiveFonts.loadFont({ + uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf', + }); + expect(font).toBeDefined(); + }); + + it('setFallbackFonts + clearFallbackFonts round-trip', async () => { + const systemFont = RiveFonts.systemFallback(); + const namedFont = await RiveFonts.loadFont({ name: 'Helvetica' }); + + await RiveFonts.setFallbackFonts({ + default: [namedFont, systemFont], + }); + + await RiveFonts.clearFallbackFonts(); + }); + + it('setFallbackFonts with weight-specific fonts', async () => { + const regular = await RiveFonts.loadFont({ name: 'Helvetica' }); + const bold = await RiveFonts.loadFont({ name: 'Helvetica-Bold' }); + const systemFont = RiveFonts.systemFallback(); + + await RiveFonts.setFallbackFonts({ + default: [regular, systemFont], + 700: [bold, systemFont], + }); + + await RiveFonts.clearFallbackFonts(); + }); + + it('loadFont with invalid name throws', async () => { + await expect( + RiveFonts.loadFont({ name: 'NonExistentFont_XYZ_12345' }) + ).rejects.toBeDefined(); + }); +}); From 3c172d4055a0c6dd32e6961a2d7d99b0c795035e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Wed, 27 May 2026 09:41:37 +0200 Subject: [PATCH 2/3] fix: skip referencedAssets tests on legacy backend --- example/__tests__/asset-loading.harness.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/example/__tests__/asset-loading.harness.ts b/example/__tests__/asset-loading.harness.ts index 6a91defc..2626a7e8 100644 --- a/example/__tests__/asset-loading.harness.ts +++ b/example/__tests__/asset-loading.harness.ts @@ -3,8 +3,15 @@ import { RiveFileFactory } from '@rive-app/react-native'; const OUT_OF_BAND = require('../assets/rive/out_of_band.riv'); +function isExperimental() { + return RiveFileFactory.getBackend() === 'experimental'; +} + describe('Asset loading with referencedAssets', () => { + // referencedAssets with raw ResolvedReferencedAsset objects only works + // on the experimental backend; legacy uses a different resolution path. it('loads file with font asset (type: font)', async () => { + if (!isExperimental()) return; const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { 'Inter-594377': { sourceAssetId: 'Inter-594377.ttf', @@ -16,6 +23,7 @@ describe('Asset loading with referencedAssets', () => { }); it('loads file with image asset via URL (type: image)', async () => { + if (!isExperimental()) return; const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { 'referenced-image-2929282': { sourceUrl: 'https://picsum.photos/id/237/200/200', @@ -27,6 +35,7 @@ describe('Asset loading with referencedAssets', () => { }); it('loads file with multiple asset types', async () => { + if (!isExperimental()) return; const file = await RiveFileFactory.fromSource(OUT_OF_BAND, { 'Inter-594377': { sourceAssetId: 'Inter-594377.ttf', From 85fd6fc4f39cfc895568abda0edf9a754f6a898f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Fri, 29 May 2026 07:37:19 +0200 Subject: [PATCH 3/3] fix: use cross-platform fonts in font-config tests --- example/__tests__/font-config.harness.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/example/__tests__/font-config.harness.ts b/example/__tests__/font-config.harness.ts index 33b8f7b9..2fbc5959 100644 --- a/example/__tests__/font-config.harness.ts +++ b/example/__tests__/font-config.harness.ts @@ -1,6 +1,9 @@ import { describe, it, expect } from 'react-native-harness'; +import { Platform } from 'react-native'; import { RiveFonts } from '@rive-app/react-native'; +const SYSTEM_FONT = Platform.OS === 'ios' ? 'Helvetica' : 'sans-serif'; + describe('RiveFonts', () => { it('systemFallback() returns a font object', () => { const font = RiveFonts.systemFallback(); @@ -8,7 +11,7 @@ describe('RiveFonts', () => { }); it('loadFont with system font name', async () => { - const font = await RiveFonts.loadFont({ name: 'Helvetica' }); + const font = await RiveFonts.loadFont({ name: SYSTEM_FONT }); expect(font).toBeDefined(); }); @@ -21,18 +24,24 @@ describe('RiveFonts', () => { it('setFallbackFonts + clearFallbackFonts round-trip', async () => { const systemFont = RiveFonts.systemFallback(); - const namedFont = await RiveFonts.loadFont({ name: 'Helvetica' }); + const urlFont = await RiveFonts.loadFont({ + uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf', + }); await RiveFonts.setFallbackFonts({ - default: [namedFont, systemFont], + default: [urlFont, systemFont], }); await RiveFonts.clearFallbackFonts(); }); it('setFallbackFonts with weight-specific fonts', async () => { - const regular = await RiveFonts.loadFont({ name: 'Helvetica' }); - const bold = await RiveFonts.loadFont({ name: 'Helvetica-Bold' }); + const regular = await RiveFonts.loadFont({ + uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Regular.ttf', + }); + const bold = await RiveFonts.loadFont({ + uri: 'https://raw.githubusercontent.com/google/fonts/main/ofl/kanit/Kanit-Bold.ttf', + }); const systemFont = RiveFonts.systemFallback(); await RiveFonts.setFallbackFonts({