@lhci/utils
Advanced tools
Comparing version 0.2.1-alpha.3 to 0.3.0-alpha.0
{ | ||
"name": "@lhci/utils", | ||
"version": "0.2.1-alpha.3", | ||
"version": "0.3.0-alpha.0", | ||
"license": "Apache-2.0", | ||
@@ -13,5 +13,6 @@ "repository": { | ||
"dependencies": { | ||
"isomorphic-fetch": "^2.2.1" | ||
"isomorphic-fetch": "^2.2.1", | ||
"tree-kill": "^1.2.1" | ||
}, | ||
"gitHead": "b014cbaefe989e45a883d4ba5c9e2d6174daf5c7" | ||
"gitHead": "17fc5a1405200672bc756af0712c54ca3858dc07" | ||
} |
@@ -165,2 +165,10 @@ /** | ||
/** | ||
* @param {string} slug | ||
* @return {Promise<LHCI.ServerCommand.Project | undefined>} | ||
*/ | ||
async findProjectBySlug(slug) { | ||
return this._convert404ToUndefined(this._get(`/v1/projects/slug:${slug}`)); | ||
} | ||
/** | ||
* @param {StrictOmit<LHCI.ServerCommand.Project, 'id'|'token'>} unsavedProject | ||
@@ -267,2 +275,12 @@ * @return {Promise<LHCI.ServerCommand.Project>} | ||
* @protected | ||
* @param {StrictOmit<LHCI.ServerCommand.Project, 'id'|'token'>} unsavedProject | ||
* @return {Promise<LHCI.ServerCommand.Project>} | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
async _createProject(unsavedProject) { | ||
throw new Error('Unimplemented'); | ||
} | ||
/** | ||
* @protected | ||
* @param {StrictOmit<LHCI.ServerCommand.Statistic, 'id'>} unsavedStatistic | ||
@@ -269,0 +287,0 @@ * @return {Promise<LHCI.ServerCommand.Statistic>} |
@@ -429,8 +429,7 @@ /** | ||
if (options.assertMatrix) { | ||
const {assertMatrix, ...restOptions} = options; | ||
if (Object.keys(restOptions).length) { | ||
if (options.assertions || options.preset || options.budgetsFile || options.aggregationMethod) { | ||
throw new Error('Cannot use assertMatrix with other options'); | ||
} | ||
arrayOfOptions = assertMatrix; | ||
arrayOfOptions = options.assertMatrix; | ||
} | ||
@@ -437,0 +436,0 @@ |
@@ -244,5 +244,6 @@ /** | ||
* @param {DetailItemEntry} compareEntry | ||
* @param {Array<{key: string}>} headings | ||
* @return {Array<LHCI.AuditDiff>} | ||
*/ | ||
function findAuditDetailItemKeyDiffs(auditId, baseEntry, compareEntry) { | ||
function findAuditDetailItemKeyDiffs(auditId, baseEntry, compareEntry, headings) { | ||
/** @type {Array<LHCI.AuditDiff>} */ | ||
@@ -254,3 +255,6 @@ const diffs = []; | ||
const compareValue = compareEntry.item[key]; | ||
// If these aren't numeric, comparable values, skip the key. | ||
if (typeof baseValue !== 'number' || typeof compareValue !== 'number') continue; | ||
// If these aren't shown in the table, skip the key. | ||
if (!headings.some(heading => heading.key === key)) continue; | ||
@@ -322,6 +326,14 @@ diffs.push( | ||
function replaceNondeterministicStrings(s) { | ||
return s | ||
.replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, 'UUID') | ||
.replace(/:[0-9]{3,5}\//, ':PORT/') | ||
.replace(/\.[0-9a-f]{8}\.(js|css|woff|html|png|jpeg|jpg|svg)/, '.HASH.$1'); | ||
return ( | ||
s | ||
// YouTube Embeds | ||
.replace(/www-embed-player-[0-9a-z]+/i, 'www-embed-player') | ||
.replace(/player_ias-[0-9a-z]+/i, 'player_ias') | ||
// UUIDs | ||
.replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi, 'UUID') | ||
// localhost Ports | ||
.replace(/:[0-9]{3,5}\//, ':PORT/') | ||
// Hash components embedded in filenames | ||
.replace(/(\.|-)[0-9a-f]{8}\.(js|css|woff|html|png|jpeg|jpg|svg)/i, '$1HASH.$2') | ||
); | ||
} | ||
@@ -337,2 +349,4 @@ | ||
if (typeof item.groupLabel === 'string') return item.groupLabel; | ||
// For user-timings | ||
if (typeof item.name === 'string') return item.name; | ||
// For dom-size | ||
@@ -439,5 +453,6 @@ if (typeof item.statistic === 'string') return item.statistic; | ||
* @param {Array<Record<string, any>>} compareItems | ||
* @param {Array<{key: string}>} headings | ||
* @return {Array<LHCI.AuditDiff>} | ||
*/ | ||
function findAuditDetailItemsDiffs(auditId, baseItems, compareItems) { | ||
function findAuditDetailItemsDiffs(auditId, baseItems, compareItems, headings) { | ||
/** @type {Array<LHCI.AuditDiff>} */ | ||
@@ -448,3 +463,3 @@ const diffs = []; | ||
if (base && compare) { | ||
diffs.push(...findAuditDetailItemKeyDiffs(auditId, base, compare)); | ||
diffs.push(...findAuditDetailItemKeyDiffs(auditId, base, compare, headings)); | ||
} else if (compare) { | ||
@@ -507,5 +522,7 @@ diffs.push({type: 'itemAddition', auditId, compareItemIndex: compare.index}); | ||
* @param {LH.AuditResult} audit | ||
* @return {Required<Pick<Required<LH.AuditResult>['details'],'items'|'headings'>>} | ||
*/ | ||
function normalizeDetailsItems(audit) { | ||
return (audit.details && audit.details.items) || []; | ||
function normalizeDetails(audit) { | ||
if (!audit.details) return {items: [], headings: []}; | ||
return {items: audit.details.items || [], headings: audit.details.headings || []}; | ||
} | ||
@@ -559,2 +576,3 @@ | ||
let hasItemDetails = false; | ||
if ( | ||
@@ -564,4 +582,6 @@ (baseAudit.details && baseAudit.details.items) || | ||
) { | ||
const baseItems = normalizeDetailsItems(baseAudit); | ||
const compareItems = normalizeDetailsItems(compareAudit); | ||
hasItemDetails = true; | ||
const {items: baseItems, headings: baseHeadings} = normalizeDetails(baseAudit); | ||
const {items: compareItems, headings: compareHeadings} = normalizeDetails(compareAudit); | ||
const headings = baseHeadings.concat(compareHeadings); | ||
@@ -577,3 +597,3 @@ diffs.push( | ||
diffs.push(...findAuditDetailItemsDiffs(auditId, baseItems, compareItems)); | ||
diffs.push(...findAuditDetailItemsDiffs(auditId, baseItems, compareItems, headings)); | ||
@@ -607,8 +627,8 @@ if (options.synthesizeItemKeyDiffs) { | ||
// If the only diff found was a numericValue/displayValue diff *AND* we were passing, skip it. | ||
// This only happens on audits that have flaky | ||
// If the only diff found was a numericValue/displayValue diff *AND* it seems like the result was flaky, skip it. | ||
// The result is likely flaky if the audit passed *OR* it was supposed to have details but no details items changed. | ||
const isAllPassing = compareAudit.score === 1 && baseAudit.score === 1; | ||
if ( | ||
filteredDiffs.every(diff => diff.type === 'displayValue' || diff.type === 'numericValue') && | ||
compareAudit.score === 1 && | ||
baseAudit.score === 1 | ||
(isAllPassing || hasItemDetails) | ||
) { | ||
@@ -615,0 +635,0 @@ return []; |
@@ -65,8 +65,9 @@ /** | ||
*/ | ||
function getCurrentBranch() { | ||
function getCurrentBranchRaw_() { | ||
// Use Travis CI vars if available. | ||
if (envVars.TRAVIS_PULL_REQUEST_BRANCH) return envVars.TRAVIS_PULL_REQUEST_BRANCH.slice(0, 40); | ||
if (envVars.TRAVIS_BRANCH) return envVars.TRAVIS_BRANCH.slice(0, 40); | ||
if (envVars.TRAVIS_PULL_REQUEST_BRANCH) return envVars.TRAVIS_PULL_REQUEST_BRANCH; | ||
if (envVars.TRAVIS_BRANCH) return envVars.TRAVIS_BRANCH; | ||
// Use GitHub Actions vars if available. See https://github.com/GoogleChrome/lighthouse-ci/issues/43#issuecomment-551174778 | ||
if (envVars.GITHUB_HEAD_REF) return envVars.GITHUB_HEAD_REF.slice(0, 40); | ||
if (envVars.GITHUB_HEAD_REF) return envVars.GITHUB_HEAD_REF; | ||
if (envVars.GITHUB_REF) return envVars.GITHUB_REF; | ||
@@ -77,3 +78,3 @@ const result = childProcess.spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { | ||
const branch = result.stdout.trim().slice(0, 40); | ||
const branch = result.stdout.trim(); | ||
if (result.status !== 0 || branch === 'HEAD') { | ||
@@ -89,2 +90,11 @@ throw new Error('Unable to determine current branch with `git rev-parse --abbrev-ref HEAD`'); | ||
*/ | ||
function getCurrentBranch() { | ||
const branch = getCurrentBranchRaw_(); | ||
if (branch === 'HEAD') throw new Error('Unable to determine current branch'); | ||
return branch.replace('refs/heads/', '').slice(0, 40); | ||
} | ||
/** | ||
* @return {string} | ||
*/ | ||
function getExternalBuildUrl() { | ||
@@ -91,0 +101,0 @@ return envVars.TRAVIS_BUILD_WEB_URL || ''; |
@@ -111,2 +111,11 @@ /** | ||
/** | ||
* @param {string} s | ||
* @param {number} length | ||
* @param {string} [padding] | ||
*/ | ||
padEnd(s, length, padding = ' ') { | ||
if (s.length >= length) return s; | ||
return `${s}${padding.repeat(length)}`.slice(0, length); | ||
}, | ||
/** | ||
* Deep clones an object via JSON.parse/JSON.stringify. | ||
@@ -113,0 +122,0 @@ * @template T |
@@ -20,2 +20,3 @@ /** | ||
'load-fast-enough-for-pwa': ['warn', {}], | ||
'uses-rel-preload': ['warn', {minScore: 1}], | ||
// Not useful diagnostic audits (off) | ||
@@ -41,3 +42,2 @@ 'critical-request-chains': ['off', {}], | ||
'uses-rel-preconnect': ['error', {maxLength: 0}], | ||
'uses-rel-preload': ['error', {maxLength: 0}], | ||
'uses-responsive-images': ['error', {maxLength: 0}], | ||
@@ -70,3 +70,3 @@ 'uses-text-compression': ['error', {maxLength: 0}], | ||
'duplicate-id': ['error', {}], | ||
'errors-in-console': ['error', {}], | ||
'errors-in-console': ['error', {maxLength: 0}], | ||
'external-anchors-use-rel-noopener': ['error', {}], | ||
@@ -73,0 +73,0 @@ 'font-display': ['error', {}], |
@@ -195,2 +195,3 @@ /** | ||
token: '', | ||
slug: '', | ||
}, | ||
@@ -202,2 +203,3 @@ { | ||
token: '', | ||
slug: '', | ||
}, | ||
@@ -454,3 +456,9 @@ ], | ||
const project = {id: '0', name: 'Example', externalUrl: 'https://www.example.com', token: ''}; | ||
const project = { | ||
id: '0', | ||
name: 'Example', | ||
externalUrl: 'https://www.example.com', | ||
token: '', | ||
slug: '', | ||
}; | ||
/** @type {Array<LHCI.ServerCommand.Build>} */ | ||
@@ -457,0 +465,0 @@ const builds = []; |
@@ -40,4 +40,15 @@ /** | ||
} | ||
/** | ||
* Returns a random character from the character class [a-z0-9]. | ||
* @param {number} input | ||
* @return {string} | ||
*/ | ||
static toAlphanumeric(input) { | ||
const valueOutOf36 = Math.round(input * 35); | ||
if (valueOutOf36 < 10) return valueOutOf36.toString(); | ||
return String.fromCharCode(97 + valueOutOf36 - 10); | ||
} | ||
} | ||
module.exports = PRandom; |
@@ -40,2 +40,3 @@ /** | ||
build.projectId = projects[Number(build.projectId)].id; | ||
build.lifecycle = 'unsealed'; | ||
builds.push(await client.createBuild(build)); | ||
@@ -48,2 +49,3 @@ } | ||
run.buildId = builds[Number(run.buildId)].id; | ||
run.representative = false; | ||
await client.createRun({ | ||
@@ -50,0 +52,0 @@ ...run, |
370505
8501
2
3
+ Addedtree-kill@^1.2.1
+ Addedtree-kill@1.2.2(transitive)