forked from paulirish/pwmetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
61 lines (55 loc) · 1.29 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2016 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE
'use strict';
/* eslint-disable no-console */
const gulp = require('gulp');
const PWMetrics = require('../../lib/');
const METRICS = require('../../lib/metrics');
/**
* Run pwmetrics
*/
const runPwmetrics = function() {
const url = 'https://www.engadget.com/';
return new PWMetrics(url, {
flags: {
runs: 3,
expectations: true,
chromeFlags: '--headless --enable-logging --no-sandbox',
},
expectations: {
[METRICS.TTFMP]: {
warn: '>=1000',
error: '>=2000'
},
[METRICS.TTI]: {
warn: '>=5000',
error: '>=8000'
},
[METRICS.TTFCPUIDLE]: {
warn: '>=1500',
error: '>=2000'
}
}
}).start();
};
/**
* Handle ok result
* @param {Object} results - Pwmetrics results obtained through Lighthouse
*/
const handleOk = function(results) {
console.log(JSON.stringify(results, null, 2));
process.exit(0);
};
/**
* Handle error
*/
const handleError = function(e) {
console.error(e); // eslint-disable-line no-console
process.exit(1);
};
gulp.task('pwmetrics', function() {
return runPwmetrics()
.then(handleOk)
.catch(handleError);
});
gulp.task('default', ['pwmetrics']);