11import { access } from 'node:fs/promises' ;
2- import { join , relative , resolve } from 'node:path' ;
2+ import { relative , resolve } from 'node:path' ;
33
44import type { Page , TestInfo } from '@playwright/test' ;
55
6- import { getTestSlug } from '../actions' ;
7- import { extractTestSlug } from '../utils/extractTestSlug' ;
6+ import { defaultDumpsFilePathBuilder } from './dumpsFilePathBulders' ;
87
98export type InitDumpsOptions = {
109 /**
@@ -48,28 +47,15 @@ export type InitDumpsOptions = {
4847 */
4948 zip ?: boolean ;
5049
51- /**
52- * User path to the directory with dumps. By default, the path is calculated as
53- * testInfo.snapshotPath('').replace(/-snapshots\/[^/]+$/, '-data/' + slug)
54- * @param testInfo TestInfo information about the current test
55- * @param slug test slug
56- *
57- * @returns string path to the directory with dumps
58- *
59- * @deprecated use dumpsFilePath.
60- */
61- dumpsPath ?: ( testInfo : TestInfo , slug : string ) => string ;
62-
6350 /**
6451 * Custom path to the dump file. Overrides the path generated by dumpsPath.
6552 * @param params Parameters for constructing a path:
6653 * @param params.testInfo TestInfo information about the current test
67- * @param params.slug test slug
6854 * @param params.zip Flag to use zip archive for .har
6955 *
7056 * @returns string path to dump file
7157 */
72- dumpsFilePath ?: ( params : { testInfo : TestInfo ; slug : string ; zip : boolean } ) => string ;
58+ dumpsFilePath ?: ( params : { testInfo : TestInfo ; zip : boolean } ) => string ;
7359} ;
7460
7561/**
@@ -79,8 +65,7 @@ export async function initDumps(
7965 page : Page ,
8066 testInfo : TestInfo ,
8167 {
82- dumpsPath : dumpsPathBuilder = defaultPathBuilder ,
83- dumpsFilePath : dumpsFilePathBuilder ,
68+ dumpsFilePath : dumpsFilePathBuilder = defaultDumpsFilePathBuilder ,
8469 rootPath,
8570 forceUpdateIfHarMissing = false ,
8671 updateTimeout,
@@ -90,25 +75,9 @@ export async function initDumps(
9075 update = false ,
9176 } : InitDumpsOptions = { } ,
9277) {
93- let slug : string ;
94-
95- try {
96- slug = getTestSlug ( page ) ;
97- } catch ( error ) {
98- console . warn ( error ) ;
99- // Backward compatibility
100- slug = extractTestSlug ( testInfo . title , true ) ;
101- }
102-
10378 let harPath : string ;
10479
105- if ( dumpsFilePathBuilder ) {
106- harPath = dumpsFilePathBuilder ( { testInfo, slug, zip } ) ;
107- } else {
108- const dumpsPath = dumpsPathBuilder ( testInfo , slug ) ;
109-
110- harPath = join ( dumpsPath , zip ? 'har.zip' : 'har.har' ) ;
111- }
80+ harPath = dumpsFilePathBuilder ( { testInfo, zip } ) ;
11281
11382 if ( rootPath ) {
11483 harPath = relative ( rootPath , harPath ) ;
@@ -137,7 +106,3 @@ export async function initDumps(
137106 url,
138107 } ) ;
139108}
140-
141- function defaultPathBuilder ( testInfo : TestInfo , slug : string ) {
142- return testInfo . snapshotPath ( '' ) . replace ( / - s n a p s h o t s \/ [ ^ / ] + $ / , '-data/' + slug ) ;
143- }
0 commit comments