import fs from 'fs' ; import path from 'path' ; import { suite } from 'uvu' ; import * as assert from 'uvu/assert' ; import { cleanupPage , DIST_DIR , E2ETestContext , renderPage , setup , sleep , teardown , } from './utils' ; const fileTest = suite ( 'file' ) ; const test = suite < E2ETestContext > ( 'e2e' ) ; test . before ( async ( context ) => { try { await setup ( context ) ; } catch ( error ) { console . error ( error ) ; process . exit ( 1 ) ; } } ) ; test . after ( async ( context ) => { try { await teardown ( context ) ; } catch ( error ) { console . error ( error ) ; process . exit ( 1 ) ; } } ) ; test . after . each ( async ( context ) => { try { await cleanupPage ( context ) ; } catch ( error ) { console . error ( error ) ; process . exit ( 1 ) ; } } ) ; [ 'background.js' , 'icon16.png' , 'icon48.png' , 'icon128.png' , 'manifest.json' , 'newtab.html' , 'newtab.js' , 'settings.html' , 'settings.js' , ] . forEach ( ( filename ) => { fileTest ( `dist/${ filename } exists` , ( ) => { const filePath = path . join ( DIST_DIR , filename ) ; assert . ok ( fs . statSync ( filePath ) ) ; } ) ; } ) ; test ( 'renders newtab app' , async ( context ) => { const { page } = await renderPage ( context , 'chrome-extension://cpcibnbdmpmcmnkhoiilpnlaepkepknb/newtab.html' ) ; assert . ok ( await page . $ ( '#b' ) ) ; assert . ok ( await page . $ ( '#s' ) ) ; assert . ok ( await page . $ ( '#m' ) ) ; assert . ok ( await page . $ ( '#d' ) ) ; await sleep ( 200 ) ; assert . is ( context . unhandledErrors . length , 0 , 'zero unhandled errors' ) ; assert . is ( context . consoleMessages . length , 0 , 'zero console messages' ) ; } ) ; test ( 'renders settings app' , async ( context ) => { const { page } = await renderPage ( context , 'chrome-extension://cpcibnbdmpmcmnkhoiilpnlaepkepknb/settings.html' ) ; assert . ok ( await page . $ ( '.row > select' ) ) ; await sleep ( 200 ) ; assert . is ( context . unhandledErrors . length , 0 , 'zero unhandled errors' ) ; assert . is ( context . consoleMessages . length , 0 , 'zero console messages' ) ; } ) ; fileTest . run ( ) ; test . run ( ) ;