@@ -21,8 +21,9 @@ type TestArgs = {
2121} ;
2222
2323type WorkerArgs = {
24+ getProjectAuth : ( ) => Promise < ProjectAuth > ;
2425 getProjectMetadata : < TKey extends Extract < keyof ProjectMetadata , string > > ( key : TKey ) => ProjectMetadata [ TKey ] ;
25- setProjectAuth : ( auth : ProjectAuth ) => void ;
26+ setProjectAuth : ( auth : ProjectAuth ) => Promise < void > ;
2627} ;
2728
2829const pageModels = {
@@ -42,6 +43,18 @@ export const test = base.extend<TestArgs, WorkerArgs>({
4243 }
4344 ) ;
4445 } ,
46+ getProjectAuth : [
47+ async ( { getProjectMetadata } , use ) => {
48+ return use ( async ( ) => {
49+ const authStorageFile = getProjectMetadata ( 'authStorageFile' ) ;
50+ if ( ! fs . existsSync ( authStorageFile ) ) {
51+ throw new Error ( `Cannot get project auth: storage file does not exist: ${ authStorageFile } ` ) ;
52+ }
53+ return JSON . parse ( await fs . promises . readFile ( authStorageFile , 'utf8' ) ) as ProjectAuth ;
54+ } ) ;
55+ } ,
56+ { scope : 'worker' }
57+ ] ,
4558 getProjectMetadata : [
4659 async ( { } , use , workerInfo ) => {
4760 return use ( ( key ) => {
@@ -52,9 +65,12 @@ export const test = base.extend<TestArgs, WorkerArgs>({
5265 ] ,
5366 setProjectAuth : [
5467 async ( { getProjectMetadata } , use ) => {
55- return use ( ( auth ) => {
68+ return use ( async ( auth ) => {
5669 const authStorageFile = getProjectMetadata ( 'authStorageFile' ) ;
57- fs . writeFileSync ( authStorageFile , JSON . stringify ( auth , null , 2 ) , 'utf-8' ) ;
70+ if ( fs . existsSync ( authStorageFile ) ) {
71+ throw new Error ( `Cannot set project auth: storage file already exists: ${ authStorageFile } ` ) ;
72+ }
73+ await fs . promises . writeFile ( authStorageFile , JSON . stringify ( auth , null , 2 ) , 'utf-8' ) ;
5874 } ) ;
5975 } ,
6076 { scope : 'worker' }
0 commit comments