Skip to content

Commit 00f6e13

Browse files
(feat): allow to set snapshot dir
1 parent 01c13ff commit 00f6e13

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const setOptions = setDefaultOptions
3333
/**
3434
* export snapshot utilities
3535
*/
36-
export * from './snapshot.js'
36+
export { SnapshotService } from './snapshot.js'
3737

3838
/**
3939
* export utils

src/snapshot.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import type { Services, Frameworks } from '@wdio/types'
99
*/
1010
let 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
}

types/expect-webdriverio.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ declare namespace ExpectWebdriverIO {
33
function setOptions(options: DefaultOptions): void
44
function getConfig(): any
55

6+
interface SnapshotServiceArgs {
7+
updateState?: import('@vitest/snapshot').SnapshotUpdateState
8+
snapshotsDirName?: string
9+
}
10+
611
class SnapshotService {
7-
static initiate(
8-
updateState?: import('@vitest/snapshot').SnapshotUpdateState
9-
): import('@wdio/types').Services.ServiceInstance & {
12+
static initiate(options: SnapshotServiceArgs): import('@wdio/types').Services.ServiceInstance & {
1013
results: import('@vitest/snapshot').SnapshotResult[]
1114
}
1215
}

0 commit comments

Comments
 (0)