Skip to content

Instantly share code, notes, and snippets.

@kahunacohen
Created October 29, 2018 09:23
Show Gist options
  • Save kahunacohen/a623d4597f2d60a7ce905d7cc506b93d to your computer and use it in GitHub Desktop.
Save kahunacohen/a623d4597f2d60a7ce905d7cc506b93d to your computer and use it in GitHub Desktop.
NCBI-written gatherer for ncbi_app meta
"use strict";
const Gatherer = require("lighthouse").Gatherer;
/**
* @fileoverview Extracts `window.myLoadMetrics` from the test page.
*/
class NCBIAppMeta extends Gatherer {
async afterPass(options) {
const driver = options.driver;
const expression = `(function() {
var meta = document.querySelector("meta[name=ncbi_app]");
ret = {name: false, content: false};
var content;
if (meta) {
content = meta.getAttribute("content");
ret.name = true;
ret.content = content && content.length > 3;
}
return ret;
})()`;
return await driver.evaluateAsync(expression);
}
}
module.exports = NCBIAppMeta;
@patrickhulce
Copy link

In general we try to write gatherers to just get the information and not pass the judgement yet, so for example this might return the content attribute value or null if it didn't exist and then the audit would check that it's length is > 3. If you think it's unlikely the test will ever change, this works too.

@kahunacohen
Copy link
Author

OK I kind of figured. Thanks for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment