@@ -77,36 +77,46 @@ export class SeleniumRecordingContainer extends SeleniumContainer {
7777 super ( image ) ;
7878 }
7979
80- public override async start ( ) : Promise < StartedSeleniumRecordingContainer > {
80+ private async createNetworkIfNeeded ( ) : Promise < StartedNetwork | undefined > {
81+ if ( this . networkMode ) {
82+ return undefined ;
83+ }
8184 const network = await new Network ( ) . start ( ) ;
8285 this . withNetwork ( network ) ;
86+ return network ;
87+ }
88+
89+ public override async start ( ) : Promise < StartedSeleniumRecordingContainer > {
90+ const internalNetwork = await this . createNetworkIfNeeded ( ) ;
8391 this . withNetworkAliases ( SELENIUM_NETWORK_ALIAS ) ;
8492
8593 const startedSeleniumContainer = await super . start ( ) ;
8694
8795 const startedFfmpegContainer = await new GenericContainer ( SELENIUM_VIDEO_IMAGE )
88- . withNetwork ( network )
96+ . withNetworkMode ( this . networkMode ! )
8997 . withEnvironment ( { DISPLAY_CONTAINER_NAME : SELENIUM_NETWORK_ALIAS } )
9098 . withWaitStrategy ( Wait . forLogMessage ( / .* v i d e o - r e c o r d i n g e n t e r e d R U N N I N G s t a t e .* / ) )
9199 . start ( ) ;
92100
93- return new StartedSeleniumRecordingContainer ( startedSeleniumContainer , startedFfmpegContainer , network ) ;
101+ return new StartedSeleniumRecordingContainer ( startedSeleniumContainer , startedFfmpegContainer , internalNetwork ) ;
94102 }
95103}
96104
97105export class StartedSeleniumRecordingContainer extends StartedSeleniumContainer {
98106 constructor (
99107 startedSeleniumContainer : StartedTestContainer ,
100108 private readonly startedFfmpegContainer : StartedTestContainer ,
101- private readonly network : StartedNetwork
109+ private readonly internalNetwork ? : StartedNetwork
102110 ) {
103111 super ( startedSeleniumContainer ) ;
104112 }
105113
106114 override async stop ( options ?: Partial < StopOptions > ) : Promise < StoppedSeleniumRecordingContainer > {
107115 const stoppedSeleniumContainer = await super . stop ( options ) ;
108116 const stoppedFfmpegContainer = await this . startedFfmpegContainer . stop ( { remove : false , timeout : 60_000 } ) ;
109- await this . network . stop ( ) ;
117+ if ( this . internalNetwork ) {
118+ await this . internalNetwork . stop ( ) ;
119+ }
110120 return new StoppedSeleniumRecordingContainer ( stoppedSeleniumContainer , stoppedFfmpegContainer ) ;
111121 }
112122}
0 commit comments