@@ -9,6 +9,11 @@ import type { Services, Frameworks } from '@wdio/types'
99 */
1010let service : SnapshotService
1111
12+ interface SnapshotServiceArgs {
13+ updateState ?: SnapshotUpdateState
14+ snapshotsDirName ?: string
15+ }
16+
1217/**
1318 * Snapshot service to take snapshots of elements.
1419 * The `@wdio/runner` module will attach this service to the test environment
@@ -23,14 +28,17 @@ export class SnapshotService implements Services.ServiceInstance {
2328 #options: SnapshotStateOptions
2429 #snapshotResults: SnapshotResult [ ] = [ ]
2530
26- #snapshotEnvironment = new NodeSnapshotEnvironment ( )
31+ #snapshotEnvironment: NodeSnapshotEnvironment
2732 #snapshotClient = new SnapshotClient ( {
2833 isEqual : this . #isEqual. bind ( this ) ,
2934 } )
3035
31- constructor ( updateState : SnapshotUpdateState ) {
36+ constructor ( options ?: SnapshotServiceArgs ) {
37+ this . #snapshotEnvironment = new NodeSnapshotEnvironment ( {
38+ snapshotsDirName : options ?. snapshotsDirName
39+ } )
3240 this . #options = {
33- updateSnapshot : updateState ,
41+ updateSnapshot : options ?. updateState || 'new' ,
3442 snapshotEnvironment : this . #snapshotEnvironment,
3543 } as const
3644 }
@@ -74,9 +82,9 @@ export class SnapshotService implements Services.ServiceInstance {
7482 }
7583 }
7684
77- static initiate ( updateState : SnapshotUpdateState = 'new' ) {
85+ static initiate ( options ?: SnapshotServiceArgs ) {
7886 if ( ! service ) {
79- service = new SnapshotService ( updateState )
87+ service = new SnapshotService ( options )
8088 }
8189 return service
8290 }
0 commit comments