Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates for using lighthouse v3 #178

Merged
merged 26 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
tmp
.DS_Store
npm-debug.log
yarn-error.log
.idea

gsheets.config.js
Expand Down
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
language: node_js
matrix:
include:
- node_js: "6"
- node_js: "7"
env: RUN_RECIPES=1
allow_failures:
- node_js: "7"
- node_js: "8"
- node_js: "9"
env: RUN_RECIPES=1
dist: trusty
cache:
yarn: true
directories:
- node_modules
before_install:
- npm install -g --no-progress [email protected]
install:
- yarn install --no-progress
# if our e2e tests fail in the future it might be that we are not compatible
# with the latest puppeteer api so we probably need to run on chromimum
# @see https://github.com/GoogleChrome/lighthouse/pull/4640/files#r171425004
- export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
- yarn
before_script:
- export DISPLAY=:99.0
- export LIGHTHOUSE_CHROMIUM_PATH="$(pwd)/chrome-linux/chrome"
# see comment above about puppeteer
- export CHROME_PATH="$(which google-chrome-stable)"
- sh -e /etc/init.d/xvfb start
- sleep 3 # wait for xvfb to boot
- yarn build
addons:
chrome: stable
16 changes: 10 additions & 6 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
// Licensed under the Apache License, Version 2.0. See LICENSE
'use strict';

/* eslint-disable no-console */
/* eslint-disable no-logger */
const sysPath = require('path');
const fs = require('fs');
const yargs = require('yargs');

const PWMetrics = require('../lib/index');
const {getConfigFromFile} = require('../lib/utils/fs');
const {getMessageWithPrefix, getMessage} = require('../lib/utils/messages');
const {Logger} = require('../lib/utils/logger');
const logger = Logger.getInstance();

let config;

const cliFlags = yargs
Expand Down Expand Up @@ -91,7 +94,7 @@ const writeToDisk = function(fileName, data) {
const path = sysPath.join(process.cwd(), fileName);
fs.writeFile(path, data, err => {
if (err) reject(err);
console.log(getMessageWithPrefix('SUCCESS', 'SAVED_TO_JSON', path));
logger.log(getMessageWithPrefix('SUCCESS', 'SAVED_TO_JSON', path));
resolve();
});
});
Expand All @@ -104,15 +107,16 @@ pwMetrics.start()
// serialize accordingly
data = JSON.stringify(data, null, 2) + '\n';
// output to file.
if (options.flags.outputPath != 'stdout')
if (options.flags.outputPath != 'stdout') {
return writeToDisk(options.flags.outputPath, data);
// output to stdout
else if (data)
// output to stdout
} else if (data) {
process.stdout.write(data);
}
}
}).then(() => {
process.exit(0);
}).catch(err => {
console.error(err);
logger.error(err);
process.exit(1);
});
6 changes: 2 additions & 4 deletions lib/chart/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const wunderbar = require('@gribnoysup/wunderbar');
const eol = require('os').EOL;

import {Timing, ChartOptions} from '../../types/types';
const Logger = require('../utils/logger');
import {Logger} from '../utils/logger';
const logger = Logger.getInstance();

const drawChart = (timings: Timing[], options: ChartOptions) => {
export const drawChart = (timings: Timing[], options: ChartOptions) => {
const {lmargin, width, xlabel, xmin, xmax} = options;

const normalizedTimings = timings.map(value => {
Expand Down Expand Up @@ -53,5 +53,3 @@ const drawChart = (timings: Timing[], options: ChartOptions) => {
logger.log([chartTop, chart, chartBottom, chartScale].join(eol));
logger.log('');
};

module.exports = drawChart;
2 changes: 1 addition & 1 deletion lib/drive/gdrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const google = require('googleapis');
const promisify = require('micro-promisify');

import { Oauth2Client, AuthorizeCredentials, DriveResponse } from '../../types/types';
import { Logger } from '../utils/logger';
const GoogleOauth = require('../oauth/google-oauth');
const messages = require('../utils/messages');
const Logger = require('../utils/logger');
const logger = Logger.getInstance();

class GDrive {
Expand Down
23 changes: 9 additions & 14 deletions lib/expectations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright 2016 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE

import { Timing, ExpectationMetrics, NormalizedExpectationMetrics } from '../types/types';
const { getAssertionMessage, getMessageWithPrefix } = require('./utils/messages');
const Logger = require('./utils/logger');
import {Logger} from './utils/logger';
import {getAssertionMessage, getMessageWithPrefix} from './utils/messages';
import {Timing, ExpectationMetrics, NormalizedExpectationMetrics} from '../types/types';

const logger = Logger.getInstance();

function validateMetrics(metrics: ExpectationMetrics) {
export const validateMetrics = (metrics: ExpectationMetrics) => {
const metricsKeys = Object.keys(metrics);

if (!metrics || !metricsKeys.length) {
Expand All @@ -20,9 +21,9 @@ function validateMetrics(metrics: ExpectationMetrics) {
process.exit(1);
}
});
}
};

function normalizeMetrics(metrics: ExpectationMetrics): NormalizedExpectationMetrics {
export const normalizeExpectationMetrics = (metrics: ExpectationMetrics): NormalizedExpectationMetrics => {
let normalizedMetrics: NormalizedExpectationMetrics = {};
Object.keys(metrics).forEach(key => {
normalizedMetrics[key] = {
Expand All @@ -31,9 +32,9 @@ function normalizeMetrics(metrics: ExpectationMetrics): NormalizedExpectationMet
};
});
return normalizedMetrics;
}
};

function checkExpectations(metricsData: Timing[], expectationMetrics: NormalizedExpectationMetrics) {
export const checkExpectations = (metricsData: Timing[], expectationMetrics: NormalizedExpectationMetrics) => {
metricsData.forEach(metric => {
const metricName = metric.id;
const expectationValue = expectationMetrics[metricName];
Expand All @@ -52,10 +53,4 @@ function checkExpectations(metricsData: Timing[], expectationMetrics: Normalized
logger.log(msg);
}
});
}

module.exports = {
validateMetrics: validateMetrics,
normalizeMetrics: normalizeMetrics,
checkExpectations: checkExpectations
};
Loading