1- const httpServer = require ( " http-server" ) ;
2- const puppeteer = require ( " puppeteer" ) ;
3- const lighthouse = require ( " lighthouse" ) ;
4- const chromeLauncher = require ( " chrome-launcher" ) ;
5- require ( " dotenv" ) . config ( ) ;
1+ const httpServer = require ( ' http-server' ) ;
2+ const puppeteer = require ( ' puppeteer' ) ;
3+ const lighthouse = require ( ' lighthouse' ) ;
4+ const chromeLauncher = require ( ' chrome-launcher' ) ;
5+ require ( ' dotenv' ) . config ( ) ;
66
77const getServer = ( url , serveDir ) => {
88 if ( url ) {
@@ -18,13 +18,13 @@ const getServer = (url, serveDir) => {
1818 }
1919
2020 if ( ! serveDir ) {
21- throw new Error ( " Empty publish dir" ) ;
21+ throw new Error ( ' Empty publish dir' ) ;
2222 }
2323
2424 console . log ( `Serving and scanning site from directory '${ serveDir } '` ) ;
2525 const s = httpServer . createServer ( { root : serveDir } ) ;
2626 const port = 5000 ;
27- const host = " localhost" ;
27+ const host = ' localhost' ;
2828 const server = {
2929 listen : ( func ) => s . listen ( port , host , func ) ,
3030 close : ( ) => s . close ( ) ,
@@ -35,7 +35,7 @@ const getServer = (url, serveDir) => {
3535const belowThreshold = ( id , expected , results ) => {
3636 const category = results . find ( ( c ) => c . id === id ) ;
3737 if ( ! category ) {
38- console . warn ( " Could not find category" , id ) ;
38+ console . warn ( ' Could not find category' , id ) ;
3939 }
4040 const actual = category ? category . score : Number . MAX_SAFE_INTEGER ;
4141 return actual < expected ;
@@ -67,15 +67,15 @@ module.exports = {
6767 } ,
6868 } ;
6969
70- if ( typeof thresholds === " string" ) {
70+ if ( typeof thresholds === ' string' ) {
7171 thresholds = JSON . parse ( thresholds ) ;
7272 }
7373
7474 const { server, url } = getServer ( auditUrl , serveDir ) ;
7575 const browserFetcher = puppeteer . createBrowserFetcher ( ) ;
7676 const revisions = await browserFetcher . localRevisions ( ) ;
7777 if ( revisions . length <= 0 ) {
78- throw new Error ( " Could not find local browser" ) ;
78+ throw new Error ( ' Could not find local browser' ) ;
7979 }
8080 const info = await browserFetcher . revisionInfo ( revisions [ 0 ] ) ;
8181
@@ -85,7 +85,7 @@ module.exports = {
8585 try {
8686 chrome = await chromeLauncher . launch ( {
8787 chromePath : info . executablePath ,
88- chromeFlags : [ " --headless" , " --no-sandbox" , " --disable-gpu" ] ,
88+ chromeFlags : [ ' --headless' , ' --no-sandbox' , ' --disable-gpu' ] ,
8989 } ) ;
9090 const results = await lighthouse ( url , {
9191 port : chrome . port ,
@@ -108,7 +108,7 @@ module.exports = {
108108 throw error ;
109109 } else {
110110 const categories = Object . values (
111- results . lhr . categories
111+ results . lhr . categories ,
112112 ) . map ( ( { title, score, id } ) => ( { title, score, id } ) ) ;
113113
114114 const errors = Object . entries ( thresholds )
@@ -122,7 +122,7 @@ module.exports = {
122122 } ) ;
123123
124124 if ( errors . length > 0 ) {
125- throw new Error ( errors . join ( "\n" ) ) ;
125+ throw new Error ( errors . join ( '\n' ) ) ;
126126 }
127127 }
128128 } catch ( error ) {
0 commit comments