File tree Expand file tree Collapse file tree
apps/desktop/src/renderer/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+ import { toSnapshotArtifactType } from './store' ;
3+
4+ describe ( 'toSnapshotArtifactType' , ( ) => {
5+ it ( 'folds html/slides/bundle/undefined into html' , ( ) => {
6+ expect ( toSnapshotArtifactType ( undefined ) ) . toBe ( 'html' ) ;
7+ expect ( toSnapshotArtifactType ( 'html' ) ) . toBe ( 'html' ) ;
8+ expect ( toSnapshotArtifactType ( 'slides' ) ) . toBe ( 'html' ) ;
9+ expect ( toSnapshotArtifactType ( 'bundle' ) ) . toBe ( 'html' ) ;
10+ } ) ;
11+
12+ it ( 'passes svg and react through' , ( ) => {
13+ expect ( toSnapshotArtifactType ( 'svg' ) ) . toBe ( 'svg' ) ;
14+ expect ( toSnapshotArtifactType ( 'react' ) ) . toBe ( 'react' ) ;
15+ } ) ;
16+
17+ it ( 'throws on unknown coreType instead of silently returning html' , ( ) => {
18+ expect ( ( ) => toSnapshotArtifactType ( 'mystery' ) ) . toThrow (
19+ / U n s u p p o r t e d a r t i f a c t t y p e f o r s n a p s h o t p e r s i s t e n c e : m y s t e r y / ,
20+ ) ;
21+ } ) ;
22+ } ) ;
Original file line number Diff line number Diff line change @@ -283,13 +283,25 @@ function isDefaultDesignName(name: string): boolean {
283283}
284284
285285// Core emits 'html' | 'svg' | 'slides' | 'bundle' but the snapshots schema only
286- // stores 'html' | 'react' | 'svg' (see DesignSnapshotV1). 'slides'/'bundle' fall
287- // through to 'html' because their on-disk source is HTML — keeping the column
286+ // stores 'html' | 'react' | 'svg' (see DesignSnapshotV1). 'slides'/'bundle' fold
287+ // into 'html' because their on-disk source is HTML — keeping the column
288288// constraint stable means we don't need a schema migration to persist them.
289- function toSnapshotArtifactType ( coreType : string | undefined ) : 'html' | 'react' | 'svg' {
290- if ( coreType === 'svg' ) return 'svg' ;
291- if ( coreType === 'react' ) return 'react' ;
292- return 'html' ;
289+ // Unknown types throw so a new core ArtifactType doesn't silently round-trip
290+ // as the wrong renderer.
291+ export function toSnapshotArtifactType ( coreType : string | undefined ) : 'html' | 'react' | 'svg' {
292+ switch ( coreType ) {
293+ case undefined :
294+ case 'html' :
295+ case 'slides' :
296+ case 'bundle' :
297+ return 'html' ;
298+ case 'svg' :
299+ return 'svg' ;
300+ case 'react' :
301+ return 'react' ;
302+ default :
303+ throw new Error ( `Unsupported artifact type for snapshot persistence: ${ coreType } ` ) ;
304+ }
293305}
294306
295307interface PersistArtifact {
You can’t perform that action at this time.
0 commit comments