-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
pipe manifest fetch/parse error strings up for display #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,9 @@ class ManifestExists extends Audit { | |
*/ | ||
static audit(artifacts) { | ||
return ManifestExists.generateAuditResult( | ||
typeof artifacts.manifest !== 'undefined' | ||
typeof artifacts.manifest.value !== 'undefined', | ||
undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's this undefined arg? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the audit's The only place this is used currently is in the FMP output, which puts the actual time in parentheses. There's probably a better way of piping that through |
||
artifacts.manifest.debugString | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,15 @@ const aggregators = [ | |
require('../../../aggregators/is-sized-for-mobile-screen') | ||
]; | ||
|
||
function escapeHTML(str) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😬 |
||
return str.replace(/&/g, '&') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.replace(/>/g, '>') | ||
.replace(/</g, '<') | ||
.replace(/`/g, '`'); | ||
} | ||
|
||
function createResultsHTML(results) { | ||
let resultsHTML = ''; | ||
|
||
|
@@ -65,15 +74,18 @@ function createResultsHTML(results) { | |
|
||
let groupHTML = ''; | ||
item.score.subItems.forEach(subitem => { | ||
const debugString = subitem.debugString ? ` title="${escapeHTML(subitem.debugString)}"` : ''; | ||
|
||
// TODO: make this work with numeric values. | ||
const status = subitem.value ? | ||
'<span class="pass">Pass</span>' : '<span class="fail">Fail</span>'; | ||
groupHTML += `<li>${subitem.description}: ${status}</li>`; | ||
`<span class="pass" ${debugString}>Pass</span>` : | ||
`<span class="fail" ${debugString}>Fail</span>`; | ||
groupHTML += `<li>${escapeHTML(subitem.description)}: ${status}</li>`; | ||
}); | ||
|
||
resultsHTML += | ||
`<li class="${groupClass}"> | ||
<span class="group-name">${item.name}</span> | ||
<span class="group-name">${escapeHTML(item.name)}</span> | ||
<span class="group-score">(${score}%)</span> | ||
<ul> | ||
${groupHTML} | ||
|
@@ -91,5 +103,6 @@ export function runPwaAudits() { | |
.then(results => Aggregator.aggregate(aggregators, results)) | ||
.then(results => { | ||
return createResultsHTML(results); | ||
}); | ||
}) | ||
.catch(err => `<div class="error">Unable to audit page: ${escapeHTML(err.message)}</div>`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,15 +35,25 @@ class Manifest extends Gather { | |
const finalURL = url.resolve(options.url, manifestURL); | ||
|
||
request(finalURL, function(err, response, body) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add a test here around our handling of the 400+ response code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, what do you mean? We don't have any gatherers tests yet, and by the time it gets up to audits it's just a Another twist on this is that this will all change when we switch to letting the page fetch the manifest in #83 (which I'm working on next) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. k |
||
if (err) { | ||
return resolve(''); | ||
if (err || response.statusCode >= 400) { | ||
return reject(`${response.statusCode}: ${response.statusMessage}`); | ||
} | ||
|
||
resolve(body); | ||
}); | ||
}); | ||
} | ||
|
||
static _errorManifest(errorString) { | ||
return { | ||
manifest: { | ||
raw: undefined, | ||
value: undefined, | ||
debugString: errorString | ||
} | ||
}; | ||
} | ||
|
||
static gather(options) { | ||
const driver = options.driver; | ||
/** | ||
|
@@ -52,12 +62,26 @@ class Manifest extends Gather { | |
* resource is tracked in issue #83 | ||
*/ | ||
return driver.querySelector('head link[rel="manifest"]') | ||
.then(node => node && node.getAttribute('href')) | ||
.then(manifestURL => manifestURL && Manifest._loadFromURL(options, manifestURL)) | ||
.then(manifestContent => { | ||
return { | ||
manifest: manifestParser(manifestContent).value | ||
}; | ||
.then(node => { | ||
if (!node) { | ||
return this._errorManifest('No <link rel="manifest"> found in DOM.'); | ||
} | ||
|
||
return node.getAttribute('href').then(manifestURL => { | ||
if (!manifestURL) { | ||
return this._errorManifest('No href found on <link rel="manifest">.'); | ||
} | ||
|
||
return Manifest._loadFromURL(options, manifestURL) | ||
.then(manifestContent => { | ||
return { | ||
manifest: manifestParser(manifestContent) | ||
}; | ||
}) | ||
.catch(reason => { | ||
return this._errorManifest(`Unable to fetch manifest at ${manifestURL}: ${reason}.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we still need to add tests around these error messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a simple pass-through check. The more involved tests will be on the gatherer itself. |
||
}); | ||
}); | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally i really hate mixing the : syntax it is very confusing ... but maybe it is something to get used to for me.