11import assert from "node:assert/strict" ;
2+ import fs from "node:fs" ;
3+ import os from "node:os" ;
24import path from "node:path" ;
35import test from "node:test" ;
46import { fileURLToPath } from "node:url" ;
@@ -20,13 +22,26 @@ function exampleCommand(example) {
2022 return `node ${ shellQuote ( path . join ( projectRoot , "examples" , example ) ) } ` ;
2123}
2224
23- async function launchChimera ( ) {
25+ function createStateDirectory ( configuration = {
26+ window : {
27+ width : 1280 ,
28+ height : 800 ,
29+ fullscreen : false ,
30+ } ,
31+ } ) {
32+ const directory = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "chimera-e2e-" ) ) ;
33+ const nextConfigPath = path . join ( directory , "config.json" ) ;
34+ fs . writeFileSync ( nextConfigPath , JSON . stringify ( configuration , null , "\t" ) ) ;
35+ return { directory, configPath : nextConfigPath } ;
36+ }
37+
38+ async function launchChimera ( { configPath : nextConfigPath = configPath } = { } ) {
2439 const electronApp = await electron . launch ( {
2540 args : [ projectRoot ] ,
2641 env : {
2742 ...process . env ,
2843 CHIMERA_E2E : "1" ,
29- CHIMERA_CONFIG_PATH : configPath ,
44+ CHIMERA_CONFIG_PATH : nextConfigPath ,
3045 } ,
3146 } ) ;
3247
@@ -502,6 +517,85 @@ test("closing the surface tab returns the shell to terminal mode", {concurrency:
502517 }
503518} ) ;
504519
520+ test ( "configuration refresh from an embedded surface updates terminal options" , { concurrency : false } , async ( ) => {
521+ const config = createStateDirectory ( ) ;
522+ const { electronApp, window} = await launchChimera ( { configPath : config . configPath } ) ;
523+
524+ try {
525+ await launchExampleFromShell ( window , "hello-world.mjs" ) ;
526+ const surfaceId = await waitForActiveSurfaceId ( window ) ;
527+ await window . evaluate ( ( ) => {
528+ window . __configurationUpdates = [ ] ;
529+ window . chimera . onConfigurationUpdated ( ( payload ) => {
530+ window . __configurationUpdates . push ( payload ) ;
531+ } ) ;
532+ } ) ;
533+
534+ fs . writeFileSync ( config . configPath , JSON . stringify ( {
535+ window : {
536+ width : 1280 ,
537+ height : 800 ,
538+ fullscreen : false ,
539+ } ,
540+ terminal : {
541+ fontSize : 23 ,
542+ scrollback : 4321 ,
543+ } ,
544+ } , null , "\t" ) ) ;
545+
546+ const status = await evaluateSurface ( electronApp , surfaceId , `
547+ fetch("/.well-known/chimera/configuration/refresh", {method: "POST"}).then((response) => response.status)
548+ ` ) ;
549+ assert . equal ( status , 204 ) ;
550+
551+ await window . waitForFunction ( async ( ) => {
552+ const options = await window . chimera . getTerminalOptions ( ) ;
553+ return options . fontSize === 23 && options . scrollback === 4321 ;
554+ } ) ;
555+ await window . waitForFunction ( ( ) => {
556+ return window . __configurationUpdates ?. some ( ( update ) => {
557+ return update . terminalOptions ?. fontSize === 23 && update . terminalOptions ?. scrollback === 4321 ;
558+ } ) ;
559+ } ) ;
560+ } finally {
561+ await electronApp . close ( ) ;
562+ }
563+ } ) ;
564+
565+ test ( "bookmark refresh from an embedded surface rebuilds the application menu" , { concurrency : false } , async ( ) => {
566+ const config = createStateDirectory ( ) ;
567+ const bookmarksPath = path . join ( config . directory , "bookmarks.json" ) ;
568+ const { electronApp, window} = await launchChimera ( { configPath : config . configPath } ) ;
569+
570+ try {
571+ await launchExampleFromShell ( window , "hello-world.mjs" ) ;
572+ const surfaceId = await waitForActiveSurfaceId ( window ) ;
573+
574+ fs . writeFileSync ( bookmarksPath , JSON . stringify ( [
575+ {
576+ title : "Surface Refresh Bookmark" ,
577+ command : "echo" ,
578+ args : [ "ok" ] ,
579+ } ,
580+ ] , null , "\t" ) ) ;
581+
582+ const status = await evaluateSurface ( electronApp , surfaceId , `
583+ fetch("/.well-known/chimera/bookmarks/refresh", {method: "POST"}).then((response) => response.status)
584+ ` ) ;
585+ assert . equal ( status , 204 ) ;
586+
587+ await electronApp . evaluate ( ( { Menu} ) => {
588+ const menu = Menu . getApplicationMenu ( ) ;
589+ const bookmarksMenu = menu . items . find ( ( item ) => item . label === "Bookmarks" ) ;
590+ return bookmarksMenu ?. submenu ?. items . some ( ( item ) => item . label === "Surface Refresh Bookmark" ) ?? false ;
591+ } ) . then ( ( found ) => {
592+ assert . equal ( found , true ) ;
593+ } ) ;
594+ } finally {
595+ await electronApp . close ( ) ;
596+ }
597+ } ) ;
598+
505599test ( "closing the only shell tab in a secondary window closes that window" , { concurrency : false } , async ( ) => {
506600 const { electronApp, window} = await launchChimera ( ) ;
507601
0 commit comments