8
8
import * as fs from 'graceful-fs' ;
9
9
import type { Config } from '@jest/types' ;
10
10
import { getStackTraceLines , getTopFrame } from 'jest-message-util' ;
11
- import type { OptionsReceived as PrettyFormatOptions } from 'pretty-format' ;
12
11
import { InlineSnapshot , saveInlineSnapshots } from './InlineSnapshots' ;
13
- import type { SnapshotData } from './types' ;
12
+ import type { SnapshotData , SnapshotFormat } from './types' ;
14
13
import {
15
14
addExtraLineBreaks ,
16
15
getSnapshotData ,
@@ -23,28 +22,28 @@ import {
23
22
} from './utils' ;
24
23
25
24
export type SnapshotStateOptions = {
26
- updateSnapshot : Config . SnapshotUpdateState ;
27
- prettierPath ?: string | null ;
28
- expand ?: boolean ;
29
- snapshotFormat : PrettyFormatOptions ;
30
- rootDir : string ;
25
+ readonly updateSnapshot : Config . SnapshotUpdateState ;
26
+ readonly prettierPath ?: string | null ;
27
+ readonly expand ?: boolean ;
28
+ readonly snapshotFormat : SnapshotFormat ;
29
+ readonly rootDir : string ;
31
30
} ;
32
31
33
32
export type SnapshotMatchOptions = {
34
- testName : string ;
35
- received : unknown ;
36
- key ?: string ;
37
- inlineSnapshot ?: string ;
38
- isInline : boolean ;
39
- error ?: Error ;
33
+ readonly testName : string ;
34
+ readonly received : unknown ;
35
+ readonly key ?: string ;
36
+ readonly inlineSnapshot ?: string ;
37
+ readonly isInline : boolean ;
38
+ readonly error ?: Error ;
40
39
} ;
41
40
42
41
type SnapshotReturnOptions = {
43
- actual : string ;
44
- count : number ;
45
- expected ?: string ;
46
- key : string ;
47
- pass : boolean ;
42
+ readonly actual : string ;
43
+ readonly count : number ;
44
+ readonly expected ?: string ;
45
+ readonly key : string ;
46
+ readonly pass : boolean ;
48
47
} ;
49
48
50
49
type SaveStatus = {
@@ -57,15 +56,16 @@ export default class SnapshotState {
57
56
private _dirty : boolean ;
58
57
// @ts -expect-error - seemingly unused?
59
58
private _index : number ;
60
- private _updateSnapshot : Config . SnapshotUpdateState ;
59
+ private readonly _updateSnapshot : Config . SnapshotUpdateState ;
61
60
private _snapshotData : SnapshotData ;
62
- private _initialData : SnapshotData ;
63
- private _snapshotPath : string ;
61
+ private readonly _initialData : SnapshotData ;
62
+ private readonly _snapshotPath : string ;
64
63
private _inlineSnapshots : Array < InlineSnapshot > ;
65
- private _uncheckedKeys : Set < string > ;
66
- private _prettierPath : string | null ;
67
- private _snapshotFormat : PrettyFormatOptions ;
68
- private _rootDir : string ;
64
+ private readonly _uncheckedKeys : Set < string > ;
65
+ private readonly _prettierPath : string | null ;
66
+ private readonly _rootDir : string ;
67
+
68
+ readonly snapshotFormat : SnapshotFormat ;
69
69
70
70
added : number ;
71
71
expand : boolean ;
@@ -93,7 +93,7 @@ export default class SnapshotState {
93
93
this . unmatched = 0 ;
94
94
this . _updateSnapshot = options . updateSnapshot ;
95
95
this . updated = 0 ;
96
- this . _snapshotFormat = options . snapshotFormat ;
96
+ this . snapshotFormat = options . snapshotFormat ;
97
97
this . _rootDir = options . rootDir ;
98
98
}
99
99
@@ -213,7 +213,7 @@ export default class SnapshotState {
213
213
}
214
214
215
215
const receivedSerialized = addExtraLineBreaks (
216
- serialize ( received , undefined , this . _snapshotFormat ) ,
216
+ serialize ( received , undefined , this . snapshotFormat ) ,
217
217
) ;
218
218
const expected = isInline ? inlineSnapshot : this . _snapshotData [ key ] ;
219
219
const pass = expected === receivedSerialized ;
0 commit comments