Coder Social home page Coder Social logo

bradparks / pwmetrics__paul_irish_webpagetest_time_to_visual_cli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulirish/pwmetrics

0.0 2.0 0.0 408 KB

Progressive web metrics at your fingertipz

License: Apache License 2.0

JavaScript 45.67% TypeScript 52.97% HTML 1.02% Shell 0.34%

pwmetrics__paul_irish_webpagetest_time_to_visual_cli's Introduction

pwmetrics

Progressive web metrics at your fingertipz. ๐Ÿ’…

CLI tool and lib to gather performance metrics via Lighthouse. IN BETA.

image

Documentation on these metrics in the works. If you hit bugs in the metrics collection, report at Lighthouse issues.

Install NPM pwmetrics package

$ yarn global add pwmetrics
# or
$ yarn add --dev pwmetrics

CLI Usage

$ pwmetrics <url> <flags>

pwmetrics http://example.com/

# --runs=n     Does n runs (eg. 3, 5), and reports the median run's numbers.
#              Median run selected by run with the median TTI.
pwmetrics http://example.com/ --runs=3

# --json       Reports json details to stdout.
pwmetrics http://example.com/ --json

# returns...
# {runs: [{
#   "timings": [
#     {
#       "name": "First Contentful Paint",
#       "value": 289.642
#     },
#     {
#       "name": "First Meaningful Paint",
#       "value": 289.6
#     },
#     ...

# --output-path       File path to save results.
pwmetrics http://example.com/ --output-path='pathToFile/file.json'

# --config        Provide configuration. See _Defining config_ below.
pwmetrics --config

# --submit       Submit results to Google Sheets. See _Defining submit_ below.
pwmetrics --submit

# --upload       Upload Lighthouse traces to Google Drive. See _Defining upload_ below.
pwmetrics --upload

# --view       View Lighthouse traces, which were uploaded to Google Drive, in DevTools. See _Defining view_ below.
pwmetrics --view

##
## CLI options useful for CI
##

# --expectations  Assert metrics results against provides values. See _Defining expectations_ below.
pwmetrics --expectations

Defining config

# run pwmetrics with config in package.json
pwmetrics --config

package.json

...
  "pwmetrics": {
    "url": "http://example.com/",
    // other configuration options
  }
...
# run pwmetrics with config in pwmetrics-config.js
pwmetrics --config=pwmetrics-config.js

pwmetrics-config.js

module.exports = {
  url: 'http://example.com/',
   // other configuration options. Read _All available configuration options_
}

All available configuration options

pwmetrics-config.js

module.exports = {
  url: 'http://example.com/',
  flags: { // AKA feature flags 
    runs: '3', // number or runs
    submit: true, // trurn on submitting to Google Sheets
    upload: true, // trurn on uploading to Google Drive
    view: true, // open uploaded traces to Google Drive in DevTools    
    expectations: true // trurn on assertation metrics results against provides values   
  },
  expectations: {
    // these expectations values are examples, for your cases set your own
    // it's not required to use all metrics, you can use just a few of them
    // Read _Available metrics_ where all keys are defined
    ttfcp: {
      warn: '>=1500',
      error: '>=2000'
    },
    ttfmp: {
      warn: '>=2000',
      error: '>=3000'
    },
    fv: {
      ...
    },
    psi: {
      ...
    },
    vc85: {
      ...
    },
    vs100: {
      ...
    },
    tti: {
      ...
    }
  },
  sheets: {
    type: 'GOOGLE_SHEETS', // sheets service type. Available types: GOOGLE_SHEETS
    options: {
      spreadsheetId: 'sheet_id',
      tableName: 'data'
    }
  },
  clientSecret: {
    // Data object. Can be get 
    // either 
    // by (using everything in step 1 here)[https://developers.google.com/sheets/api/quickstart/nodejs#step_1_turn_on_the_api_name]
    // or
    // by (using everything in step 1 here)[https://developers.google.com/drive/v3/web/quickstart/nodejs]
  }
}

Defining expectations

Recipes for using with CI

# run pwmetrics with config in package.json
pwmetrics --expectations

package.json

...
  "pwmetrics": {
    "url": "http://example.com/",
    "expectations": {
      ...
    }
  }
...
# run pwmetrics with config in pwmetrics-config.js
pwmetrics --expectations --config=pwmetrics-config.js

Defining submit

Submit results to Google Sheets

Instructions:

  • Copy this spreadsheet.
  • Copy the ID of the spreadsheet into the config as value of sheets.options.spreadsheetId property.
  • Setup Google Developer project and get credentials. (everything in step 1 here)
  • Take a client_secret and put it into the config as value of clientSecret property.
# run pwmetrics with config in package.json
pwmetrics --submit
# run pwmetrics with config in pwmetrics-config.js
pwmetrics --submit --config=pwmetrics-config.js

pwmetrics-config.js

module.exports = {
  'url': 'http://example.com/',
  'sheets': {
    ...
  },
  'clientSecret': {
    ...
  }
}

Defining upload

Upload Lighthouse traces to Google Drive

Instructions:

  • Setup Google Developer project and get credentials. (everything in step 1 here)
  • Take a client_secret and put it into the config as value of clientSecret property.
# run pwmetrics with config in package.json
pwmetrics --upload
# run pwmetrics with config in pwmetrics-config.js
pwmetrics --upload --config=pwmetrics-config.js

pwmetrics-config.js

module.exports = {
  'url': 'http://example.com/',
  'clientSecret': {
    ...
  }
}

View Lighthouse traces in timeline-viewer

Show Lighthouse traces in timeline-viewer.

Required to use upload flag

timeline-viewer - Shareable URLs for your Chrome DevTools Timeline traces.

# run pwmetrics with config in package.json
pwmetrics --upload --view
# run pwmetrics with config in your-own-file.js
pwmetrics --upload --view --config=your-own-file.js

pwmetrics-config.js

module.exports = {
  'url': 'http://example.com/',
  'clientSecret': {
    ...
  }
}

Available metrics:

  • ttfcp - First Contentful Paint
  • ttfmp - First Meaningful Paint
  • psi - Perceptual Speed Index
  • fv - First Visual Change
  • vc - Visually Complete 100%
  • tti - Time to Interactive
  • vc85 - Visually Complete 85%

Default Lighthouse options

  • disableCpuThrottling is set false by default. It means that CPU throttling 5x is enabled. To turn it off, run pwmetrics http:example.com --disableCpuThrottling

API

const PWMetrics = require('pwmetrics');

const pwMetrics = new PWMetrics('http://example.com/', options); // [All available configuration options](#all-available-configuration-options) can be used as `opts` 
pwMetrics.start(); // returns Promise

Options

Option Type Default Description
flags Object
{
  runs: 1,
  submit: false,
  upload: false,
  view: false,
  expectations: false,
  disableCpuThrottling: false
}
        
Feature flags
expectations Object {} See Defining expectations above.
sheets Object {} See Defining submit above.
clientSecret Object {} Client secrete data generated by Google API console. To setup Google Developer project and get credentials apply everything in step 1 here.

Recipes

License

Apache 2.0. Google Inc.

pwmetrics__paul_irish_webpagetest_time_to_visual_cli's People

Contributors

bubbit avatar denar90 avatar exogen avatar mickeykay avatar paulirish avatar pedro93 avatar radum avatar samccone avatar staabm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.