@@ -234,6 +234,39 @@ function testNoOpWhenBackgroundMissing() {
234234 assert . equal ( order . length , 0 ) ;
235235}
236236
237+ function testSampleGameBackgroundAndBezelNoOpWhenMissing ( ) {
238+ const documentRef = createDocumentStub ( "/games/SpaceInvaders/index.html" ) ;
239+ const paths = resolveGameImageConventionPaths ( { documentRef } ) ;
240+ assert . equal ( paths . backgroundPath , "games/SpaceInvaders/assets/images/background.png" ) ;
241+ assert . equal ( paths . bezelPath , "games/SpaceInvaders/assets/images/bezel.png" ) ;
242+
243+ const backgroundLayer = new backgroundImage ( {
244+ documentRef,
245+ imageFactory : createImageFactory ( new Set ( ) )
246+ } ) ;
247+ const backgroundOrder = [ ] ;
248+ const backgroundResult = backgroundLayer . render ( createRendererSpy ( backgroundOrder ) , {
249+ scene : { session : { mode : "playing" } }
250+ } ) ;
251+ assert . equal ( backgroundResult . drawn , false ) ;
252+ assert . equal ( backgroundResult . path , "games/SpaceInvaders/assets/images/background.png" ) ;
253+ assert . equal ( backgroundOrder . length , 0 ) ;
254+
255+ const host = createElement ( "div" , documentRef ) ;
256+ const canvas = createElement ( "canvas" , documentRef ) ;
257+ host . appendChild ( canvas ) ;
258+ documentRef . body . appendChild ( host ) ;
259+
260+ const bezel = new fullscreenBezel ( { canvas, documentRef } ) ;
261+ bezel . attach ( ) ;
262+ assert . equal ( bezel . element . src , "/games/SpaceInvaders/assets/images/bezel.png" ) ;
263+ assert . equal ( bezel . element . src . includes ( "/games/SpaceInvaders/games/SpaceInvaders/" ) , false ) ;
264+ bezel . element . onerror ?. ( ) ;
265+ const bezelResult = bezel . sync ( { fullscreenActive : true , fullscreenElement : host } ) ;
266+ assert . equal ( bezelResult . visible , false ) ;
267+ assert . equal ( bezel . element . style . display , "none" ) ;
268+ }
269+
237270function testFullscreenBezelVisibilityAndHtmlAttachment ( ) {
238271 const documentRef = createDocumentStub ( ) ;
239272 const host = createElement ( "div" , documentRef ) ;
@@ -548,6 +581,46 @@ async function testBezelDetectionDoesNotOverwriteExistingStretchConfig() {
548581 }
549582}
550583
584+ async function testSampleGameBezelDetectionCreatesStretchConfig ( ) {
585+ const tempRoot = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "bezel-detected-spaceinvaders-config-" ) ) ;
586+ const documentRef = createDocumentStub ( "/games/SpaceInvaders/index.html" ) ;
587+ const host = createElement ( "div" , documentRef ) ;
588+ const canvas = createElement ( "canvas" , documentRef ) ;
589+ canvas . width = 960 ;
590+ canvas . height = 720 ;
591+ host . appendChild ( canvas ) ;
592+ documentRef . body . appendChild ( host ) ;
593+
594+ try {
595+ const bezel = new fullscreenBezel ( {
596+ canvas,
597+ documentRef,
598+ stretchConfigProvider ( configPath ) {
599+ return ensureBezelStretchConfigFile ( configPath , {
600+ cwd : tempRoot ,
601+ fsModule : fs ,
602+ pathModule : path
603+ } ) ;
604+ }
605+ } ) ;
606+
607+ bezel . attach ( ) ;
608+ bezel . element . naturalWidth = 1920 ;
609+ bezel . element . naturalHeight = 1080 ;
610+ bezel . element . onload ?. ( ) ;
611+ if ( bezel . stretchConfigPromise ) {
612+ await bezel . stretchConfigPromise ;
613+ }
614+
615+ const createdPath = path . resolve ( tempRoot , "games/SpaceInvaders/assets/images/bezel.stretch.override.json" ) ;
616+ const saved = JSON . parse ( await fs . readFile ( createdPath , "utf8" ) ) ;
617+ assert . deepEqual ( saved , { uniformEdgeStretchPx : 0 } ) ;
618+ assert . equal ( bezel . getState ( ) . stretchConfigPath , "games/SpaceInvaders/assets/images/bezel.stretch.override.json" ) ;
619+ } finally {
620+ await fs . rm ( tempRoot , { recursive : true , force : true } ) ;
621+ }
622+ }
623+
551624function testEngineRuntimeIntegration ( ) {
552625 const animationFrame = createAnimationFrameStub ( ) ;
553626 const originalDocument = globalThis . document ;
@@ -685,6 +758,7 @@ export async function run() {
685758 testBackgroundGameplayGatingAndOrder ( ) ;
686759 testGameImageConventionsAreGameAgnostic ( ) ;
687760 testNoOpWhenBackgroundMissing ( ) ;
761+ testSampleGameBackgroundAndBezelNoOpWhenMissing ( ) ;
688762 testFullscreenBezelVisibilityAndHtmlAttachment ( ) ;
689763 testNoOpWhenBezelMissing ( ) ;
690764 testTransparentWindowDetectionAndAspectFit ( ) ;
@@ -693,5 +767,6 @@ export async function run() {
693767 await testBezelStretchConfigAutoCreate ( ) ;
694768 await testBezelDetectionTriggersStretchConfigAutoCreate ( ) ;
695769 await testBezelDetectionDoesNotOverwriteExistingStretchConfig ( ) ;
770+ await testSampleGameBezelDetectionCreatesStretchConfig ( ) ;
696771 testEngineRuntimeIntegration ( ) ;
697772}
0 commit comments