Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Run eslint for Compat 2021 script (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip authored Jan 13, 2022
1 parent 8af13e1 commit e48e44f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions compat-2021/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'
'use strict';

// TODO: There's a lot of reused code from browser-specific-failures.js here,
// that could be put into lib/
Expand All @@ -11,15 +11,15 @@ const lib = require('../lib');
const moment = require('moment');
const path = require('path');

flags.defineStringList('products', ['chrome','firefox','safari'], 'Products to include (comma-separated)');
flags.defineStringList('products', ['chrome', 'firefox', 'safari'], 'Products to include (comma-separated)');
flags.defineString('from', '2018-07-01', 'Starting date (inclusive)');
flags.defineString('to', moment().format('YYYY-MM-DD'),
'Ending date (exclusive)');
flags.defineBoolean('experimental', false,
'Calculate metrics for experimental runs.');
flags.parse();

const ROOT_DIR = path.join(__dirname, "..");
const ROOT_DIR = path.join(__dirname, '..');

const CATEGORIES = [
'aspect-ratio',
Expand Down Expand Up @@ -84,24 +84,24 @@ async function fetchAlignedRunsFromServer(products, from, to, experimental) {
let params = `&label=master&label=${label}`;
for (const product of products) {
params += `&product=${product}`;
}
}
const runsUri = `${RUNS_URI}${params}`;

console.log(`Fetching aligned runs from ${from.format('YYYY-MM-DD')} ` +
`to ${to.format('YYYY-MM-DD')}`);

let cachedCount = 0;
const before = moment();
const alignedRuns = new Map();
while (from < to) {
const formattedFrom = from.format('YYYY-MM-DD');
from.add(1, 'days');
const formattedTo = from.format('YYYY-MM-DD');

// We advance the date (if necessary) before doing anything more, so that
// code later in the loop body can just 'continue' without checking.
from = advanceDateToSkipBadDataIfNecessary(from, experimental);

// Attempt to read the runs from the cache.
// TODO: Consider https://github.com/tidoust/fetch-filecache-for-crawling
let runs;
Expand Down Expand Up @@ -140,7 +140,7 @@ async function fetchAlignedRunsFromServer(products, from, to, experimental) {
const after = moment();
console.log(`Fetched ${alignedRuns.size} sets of runs in ` +
`${after - before} ms (${cachedCount} cached)`);

return alignedRuns;
}

Expand Down Expand Up @@ -188,11 +188,13 @@ function scoreRuns(runs, allTestsSet) {

lib.results.walkTests(run.tree, (path, test, results) => {
const testname = path + '/' + test;
if (!allTestsSet.has(testname))
if (!allTestsSet.has(testname)) {
return;
}

if (!testResults.has(testname))
if (!testResults.has(testname)) {
testResults.set(testname, []);
}

// TODO: Validate the data by checking that all statuses are recognized.

Expand Down Expand Up @@ -390,7 +392,7 @@ async function main() {
for (const category of CATEGORIES) {
console.log(`Scoring runs for ${category}`);
const dateToScores = await scoreCategory(
category, experimental, products, alignedRuns);
category, experimental, products, alignedRuns);

// Grab the latest dateToScores to produce the summary of recent results.
const latestEntry = Array.from(dateToScores.values()).pop();
Expand Down Expand Up @@ -421,7 +423,7 @@ async function main() {
// individual categories, but we need it mapped by product.
for (let browserIdx = 0; browserIdx < products.length; browserIdx++) {
let version;
let productScores = [];
const productScores = [];
for (const category of CATEGORIES) {
const {sha, versions, scores, testResults} = dateToScoresMaps.get(category).get(date);
productScores.push(scores[browserIdx]);
Expand All @@ -443,4 +445,4 @@ async function main() {
main().catch(reason => {
console.error(reason);
process.exit(1);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"install": "git clone --bare https://github.com/ecosystem-infra/wpt-results.git && git --git-dir=wpt-results.git remote set-url --push origin git@github.com:ecosystem-infra/wpt-results.git || git --git-dir=wpt-results.git fetch --tags",
"lint": "eslint browser-specific-failures.js lib/browser-specific.js",
"lint": "eslint browser-specific-failures.js lib/browser-specific.js compat-2021/main.js",
"test": "npm run lint && npm run test-unit",
"test-unit": "mocha -u bdd ./test/*.js"
},
Expand Down

0 comments on commit e48e44f

Please sign in to comment.