Skip to content

Commit

Permalink
added readme config example
Browse files Browse the repository at this point in the history
  • Loading branch information
thecreazy committed Oct 24, 2018
1 parent 46238e7 commit fc42e5b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 53 deletions.
47 changes: 44 additions & 3 deletions README.MD
Expand Up @@ -122,9 +122,50 @@ audit:

### Output examples

<img src="docs/pagespeed.png" width="70%" />
<img src="docs/lighthouse.png" width="70%" />
<img src="docs/a11y.png" width="100%" />
<img src="docs/pagespeed.png" width="50%" />
<img src="docs/lighthouse.png" width="50%" />
<img src="docs/a11y.png" width="50%" />



### Config json

You can also pass a custom config json, there are some examples:

- pagespeed

```json
{
pagespeed:{
"strategy" : [ "mobile", "desktop"], // Strategy to use when analyzing the page. this is the base settings
"locale": "en_US", // Locale results should be generated in.
"threshold": "70", // Threshold score to pass the PageSpeed test. Useful for setting a performance budget.
"pages": ["/"]. //Array of relative pages to analyze, default is only / (please, use relative path)
}
}
```

- lighthouse

```json
{
lighthouse:{
"extends" : [ "lighthouse:default" ], // (string|boolean|undefined) The extends property controls if your configuration should inherit from the default Lighthouse configuration.
"settings": {
"onlyCategories": ["performance"],
"onlyAudits": ["works-offline"],
}, // (Object|undefined) The settings property controls various aspects of running Lighthouse such as CPU/network throttling and audit whitelisting/blacklisting.
"audits": [
"first-meaningful-paint",
"first-interactive",
"byte-efficiency/uses-optimized-images",
] // (string[]) The audits property controls which audits to run and include with your Lighthouse report.
}
}
```

For full list of settings options see [here](https://github.com/GoogleChrome/lighthouse/blob/master/docs/configuration.md).


## Contributing

Expand Down
95 changes: 47 additions & 48 deletions lib/audits/A11y.js
Expand Up @@ -3,49 +3,48 @@ const pa11y = require( 'pa11y' );
const puppeteer = require( 'puppeteer' );

class Pagespeed {
constructor( url, opts = {}, isHeadless ) {
this.url = url;
this.auditName = `A11y`;
this.isHeadless = isHeadless;
this.browser = null;


this.config = Object.assign( {}, {}, opts );

this.start = this.start.bind( this );
this.a11Request = this.a11Request.bind( this )

}

async start() {
this.spinner = ora( `Start ${this.auditName} audit for ${this.url}` ).start();
try {
const result = await this.a11Request();
const formattedResult = this.formatResult( result )
if ( this.browser !== null ) await this.browser.close();
this.spinner.succeed( `Finish ${this.auditName} audit for ${this.url}` );
return !!formattedResult ? formattedResult : '# Well, your page have no problems';
} catch ( e ) {
console.log( e )
this.spinner.fail( `Fail ${this.auditName} audit for ${this.url}` );
return JSON.stringify( e )
constructor( url, opts = {}, isHeadless ) {
this.url = url;
this.auditName = `A11y`;
this.isHeadless = isHeadless;
this.browser = null;


this.config = Object.assign( {}, {}, opts );

this.start = this.start.bind( this );
this.a11Request = this.a11Request.bind( this )

}
}

async a11Request() {
if ( this.isHeadless ) {
this.browser = await this.getBrowserInstance();
async start() {
this.spinner = ora( `Start ${this.auditName} audit for ${this.url}` ).start();
try {
const result = await this.a11Request();
const formattedResult = this.formatResult( result )
if ( this.browser !== null ) await this.browser.close();
this.spinner.succeed( `Finish ${this.auditName} audit for ${this.url}` );
return !!formattedResult ? formattedResult : '# Well, your page have no problems';
} catch ( e ) {
this.spinner.fail( `Fail ${this.auditName} audit for ${this.url}` );
return JSON.stringify( e )
}
}
return pa11y( this.url, {
browser: this.browser,
...this.config
} )
.then( data => data.issues ? data.issues : [] )
}

formatResult( result ) {
const results = result.map( res => {
return `

async a11Request() {
if ( this.isHeadless ) {
this.browser = await this.getBrowserInstance();
}
return pa11y( this.url, {
browser: this.browser,
...this.config
} )
.then( data => data.issues ? data.issues : [] )
}

formatResult( result ) {
const results = result.map( res => {
return `
# Code: **${res.code}**
## Severity: **${res.type}**
Expand All @@ -59,16 +58,16 @@ class Pagespeed {
\`\`\`
`;
} );
} );

return results.join( '' );
}
return results.join( '' );
}

getBrowserInstance() {
return puppeteer.launch( {
args: [ '--headless', '--disable-gpu', '--disable-software-rasterizer', '--disable-dev-shm-usage', '--no-sandbox' ]
} );
}
getBrowserInstance() {
return puppeteer.launch( {
args: [ '--headless', '--disable-gpu', '--disable-software-rasterizer', '--disable-dev-shm-usage', '--no-sandbox' ]
} );
}

}

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "siteaudit",
"version": "1.2.0",
"version": "1.2.1",
"description": "Siteaudit will analize your site and generate Google Page Speed and Lighthouse report.",
"main": "/lib/index.js",
"scripts": {},
Expand Down Expand Up @@ -37,4 +37,4 @@
"bugs": {
"url": "https://github.com/thecreazy/siteaudit/issues"
}
}
}

0 comments on commit fc42e5b

Please sign in to comment.