Use dayjs instead of moment (#2200)

This commit is contained in:
Peter Hedenskog 2018-11-05 06:12:46 +01:00 committed by GitHub
parent 2e39959b25
commit 8703133374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 27 deletions

View File

@ -6,7 +6,7 @@ const api = require('webcoach');
const log = require('intel').getLogger('plugin.browsertime');
const merge = require('lodash.merge');
const analyzer = require('./analyzer');
const moment = require('moment');
const dayjs = require('dayjs');
const isEmpty = require('lodash.isempty');
const get = require('lodash.get');
const defaultConfig = require('./default/config');
@ -164,7 +164,7 @@ module.exports = {
run.cpu = result.cpu[runIndex];
}
run.timestamp = moment(result.timestamps[runIndex]).format(
run.timestamp = dayjs(result.timestamps[runIndex]).format(
TIME_FORMAT
);
@ -266,7 +266,7 @@ module.exports = {
}
// Let take the first runs timestamp and use that as the summary timestamp
result.timestamp = moment(result.timestamps[0]).format(TIME_FORMAT);
result.timestamp = dayjs(result.timestamps[0]).format(TIME_FORMAT);
if (options.chrome && options.chrome.collectConsoleLog) {
result.statistics.console = consoleLogAggregator.summarizeStats();

View File

@ -6,7 +6,7 @@ const Promise = require('bluebird');
const querystring = require('querystring');
const tsdbUtil = require('../../support/tsdbUtil');
const annotationsHelper = require('../../support/annotationsHelper');
const moment = require('moment');
const dayjs = require('dayjs');
module.exports = {
send(
@ -35,7 +35,7 @@ module.exports = {
screenshotType,
options
);
const timestamp = Math.round(moment() / 1000);
const timestamp = Math.round(dayjs() / 1000);
// if we have a category, let us send that category too
if (options.influxdb.tags) {
for (var row of options.influxdb.tags.split(',')) {

View File

@ -1,7 +1,7 @@
'use strict';
const Promise = require('bluebird'),
moment = require('moment'),
dayjs = require('dayjs'),
log = require('intel').getLogger('sitespeedio'),
intel = require('intel'),
os = require('os'),
@ -43,7 +43,7 @@ function runOptionalFunction(objects, fN) {
module.exports = {
run(options) {
const url = options.urls[0];
const timestamp = moment();
const timestamp = dayjs();
if (options.utc) {
timestamp.utc();

View File

@ -1,13 +1,13 @@
'use strict';
const moment = require('moment'),
const dayjs = require('dayjs'),
merge = require('lodash.merge'),
makeUuid = require('uuid').v4;
module.exports = function messageMaker(source) {
return {
make(type, data, extras) {
const timestamp = moment().format(),
const timestamp = dayjs().format(),
uuid = makeUuid();
return merge({ uuid, type, timestamp, source, data }, extras);

14
package-lock.json generated
View File

@ -1421,6 +1421,11 @@
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz",
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI="
},
"dayjs": {
"version": "1.7.7",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.7.7.tgz",
"integrity": "sha512-Qlkiu0NNDpYwhk0syK4ImvAl/5YnsEMkvC2O123INviGeOA3Q8s5VyVkZzmN5SC7Wv9bb1+rfwO+uSqtHB4UWw=="
},
"dbug": {
"version": "0.4.2",
"resolved": "https://registry.npmjs.org/dbug/-/dbug-0.4.2.tgz",
@ -2433,7 +2438,7 @@
},
"espree": {
"version": "3.5.4",
"resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz",
"resolved": "http://registry.npmjs.org/espree/-/espree-3.5.4.tgz",
"integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==",
"dev": true,
"requires": {
@ -5232,11 +5237,6 @@
}
}
},
"moment": {
"version": "2.22.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
"integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@ -5857,7 +5857,7 @@
},
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
},
"pinkie": {

View File

@ -72,6 +72,7 @@
"browsertime": "3.11.1",
"cli-color": "1.3.0",
"concurrent-queue": "7.0.2",
"dayjs": "1.7.7",
"fast-stats": "0.0.3",
"fs-extra": "7.0.0",
"influx": "5.0.7",
@ -93,7 +94,6 @@
"longjohn": "0.2.12",
"markdown": "0.5.0",
"mkdirp": "0.5.1",
"moment": "2.22.2",
"node-slack": "0.0.7",
"p-limit": "2.0.0",
"pagexray": "2.4.0",

View File

@ -2,7 +2,7 @@
const DataGenerator = require('../lib/plugins/graphite/data-generator'),
expect = require('chai').expect,
moment = require('moment');
dayjs = require('dayjs');
describe('graphite', function() {
describe('dataGenerator', function() {
@ -31,7 +31,7 @@ describe('graphite', function() {
connectivity: 'cable'
});
var data = generator.dataFromMessage(message, moment());
var data = generator.dataFromMessage(message, dayjs());
expect(data).to.match(/ns.pageSummary.sub_domain_com/);
expect(data).to.match(/bar.gpsi.median/);
expect(data).to.match(/foo_bar/);
@ -63,7 +63,7 @@ describe('graphite', function() {
browser: 'chrome',
connectivity: 'cable'
});
var data = generator.dataFromMessage(message, moment());
var data = generator.dataFromMessage(message, dayjs());
expect(data).to.match(
/ns.summary.sub_domain_com.chrome.cable.domains.www.sitespeed.io.dns.median [\d]{1,} [\d]*/
@ -97,7 +97,7 @@ describe('graphite', function() {
connectivity: 'cable',
graphite: { statsd: true }
});
var data = generator.dataFromMessage(message, moment());
var data = generator.dataFromMessage(message, dayjs());
data.forEach(function(line) {
expect(line).to.match(

View File

@ -1,7 +1,7 @@
'use strict';
const DataGenerator = require('../lib/plugins/influxdb/data-generator'),
moment = require('moment'),
dayjs = require('dayjs'),
expect = require('chai').expect;
describe('influxdb', function() {
@ -354,7 +354,7 @@ describe('influxdb', function() {
}
});
var data = generator.dataFromMessage(message, moment());
var data = generator.dataFromMessage(message, dayjs());
expect(data).to.not.be.empty;

View File

@ -1,10 +1,10 @@
'use strict';
const resultsStorage = require('../lib/core/resultsStorage');
const moment = require('moment');
const dayjs = require('dayjs');
const expect = require('chai').expect;
const timestamp = moment();
const timestamp = dayjs();
const timestampString = timestamp.format('YYYY-MM-DD-HH-mm-ss');
function createResultUrls(url, outputFolder, resultBaseURL) {

View File

@ -1,11 +1,11 @@
'use strict';
const resultsStorage = require('../lib/core/resultsStorage');
const moment = require('moment');
const dayjs = require('dayjs');
const path = require('path');
const expect = require('chai').expect;
const timestamp = moment();
const timestamp = dayjs();
const timestampString = timestamp.format('YYYY-MM-DD-HH-mm-ss');
function createManager(url, outputFolder) {