import { device } from "detox" ; import * as fs from "fs" ; import * as path from "path" ; import { setStatusBar } from "./setStatusBar" ; export function getOutputDir ( projectRoot , locale ) { return path . resolve ( projectRoot , `meta/screenshots/${ device . getPlatform ( ) }/${ locale }/` ) ; } export async function takeScreenshotAsync ( { info , projectRoot , index , locale , } ) { const outputDir = getOutputDir ( projectRoot , locale ) ; fs . mkdirSync ( outputDir , { recursive : true } ) ; if ( index == null ) { index = fs . readdirSync ( outputDir ) . length ; } const name = `APP_${ device . name }_${ index }` . toUpperCase ( ) ; const imgPath = path . resolve ( outputDir , `${ name }.png` ) ; const imagePath = await device . takeScreenshot ( name ) ; await fs . promises . copyFile ( imagePath , imgPath ) ; } export function createCapture ( { projectRoot , locale , } ) { const captureAsync = ( ) => takeScreenshotAsync ( { projectRoot , locale , } ) ; const clearAsync = async ( ) => { const outputDir = getOutputDir ( projectRoot , locale ) ; await fs . promises . rmdir ( outputDir , { recursive : true } ) . catch ( ( ) => null ) ; } ; return { captureAsync , clearAsync , async resetAppAsync ( ) { await clearAsync ( ) ; setStatusBar ( ) ; await device . terminateApp ( ) ; await device . launchApp ( { languageAndLocale : { locale , language : locale } , launchArgs : { locale } , } ) ; } , } ; }