66 */
77
88import path from 'path' ;
9- import { Config } from '@jest/types' ;
9+ import { Config , Snapshot } from '@jest/types' ;
1010import chalk from 'chalk' ;
1111
12- export type SnapshotResolver = {
13- testPathForConsistencyCheck : string ;
14- resolveSnapshotPath ( testPath : Config . Path , extension ?: string ) : Config . Path ;
15- resolveTestPath ( snapshotPath : Config . Path , extension ?: string ) : Config . Path ;
16- } ;
17-
1812export const EXTENSION = 'snap' ;
1913export const DOT_EXTENSION = '.' + EXTENSION ;
2014
2115export const isSnapshotPath = ( path : string ) : boolean =>
2216 path . endsWith ( DOT_EXTENSION ) ;
2317
24- const cache : Map < Config . Path , SnapshotResolver > = new Map ( ) ;
18+ const cache : Map < Config . Path , Snapshot . SnapshotResolver > = new Map ( ) ;
2519export const buildSnapshotResolver = (
2620 config : Config . ProjectConfig ,
27- ) : SnapshotResolver => {
21+ ) : Snapshot . SnapshotResolver => {
2822 const key = config . rootDir ;
2923 if ( ! cache . has ( key ) ) {
3024 cache . set ( key , createSnapshotResolver ( config . snapshotResolver ) ) ;
@@ -34,13 +28,13 @@ export const buildSnapshotResolver = (
3428
3529function createSnapshotResolver (
3630 snapshotResolverPath ?: Config . Path | null ,
37- ) : SnapshotResolver {
31+ ) : Snapshot . SnapshotResolver {
3832 return typeof snapshotResolverPath === 'string'
3933 ? createCustomSnapshotResolver ( snapshotResolverPath )
4034 : createDefaultSnapshotResolver ( ) ;
4135}
4236
43- function createDefaultSnapshotResolver ( ) : SnapshotResolver {
37+ function createDefaultSnapshotResolver ( ) : Snapshot . SnapshotResolver {
4438 return {
4539 resolveSnapshotPath : ( testPath : Config . Path ) =>
4640 path . join (
@@ -65,10 +59,10 @@ function createDefaultSnapshotResolver(): SnapshotResolver {
6559
6660function createCustomSnapshotResolver (
6761 snapshotResolverPath : Config . Path ,
68- ) : SnapshotResolver {
69- const custom : SnapshotResolver = require ( snapshotResolverPath ) ;
62+ ) : Snapshot . SnapshotResolver {
63+ const custom : Snapshot . SnapshotResolver = require ( snapshotResolverPath ) ;
7064
71- const keys : [ keyof SnapshotResolver , string ] [ ] = [
65+ const keys : [ keyof Snapshot . SnapshotResolver , string ] [ ] = [
7266 [ 'resolveSnapshotPath' , 'function' ] ,
7367 [ 'resolveTestPath' , 'function' ] ,
7468 [ 'testPathForConsistencyCheck' , 'string' ] ,
@@ -101,7 +95,7 @@ function mustImplement(propName: string, requiredType: string) {
10195 ) ;
10296}
10397
104- function verifyConsistentTransformations ( custom : SnapshotResolver ) {
98+ function verifyConsistentTransformations ( custom : Snapshot . SnapshotResolver ) {
10599 const resolvedSnapshotPath = custom . resolveSnapshotPath (
106100 custom . testPathForConsistencyCheck ,
107101 ) ;
0 commit comments