Generate expected-metadata.json in generate-testcase.js

pull/35/head
Margaret Leibovic 9 years ago
parent 1b5d896b8b
commit 639c878af5

@ -89,15 +89,14 @@ function fetchSource(url, callbackFn) {
if (debug) {
console.log("End received");
}
// Sanitize:
rv = prettyPrint(serializeDocument(jsdom(rv)));
callbackFn(rv);
});
});
}
function onResponseReceived(source) {
// Sanitize:
source = prettyPrint(serializeDocument(jsdom(source)));
if (debug) {
console.log("writing");
}
@ -111,11 +110,11 @@ function onResponseReceived(source) {
if (debug) {
console.log("Running readability stuff");
}
runReadability(source, path.join(destRoot, "expected.html"));
runReadability(source, path.join(destRoot, "expected.html"), path.join(destRoot, "expected-metadata.json"));
});
}
function runReadability(source, destPath) {
function runReadability(source, destPath, metadataDestPath) {
var doc = new JSDOMParser().parse(source);
var uri = {
spec: "http://fakehost/test/page.html",
@ -133,13 +132,26 @@ function runReadability(source, destPath) {
console.error("No content generated by readability, not going to write expected.html!");
return;
}
fs.writeFile(destPath, prettyPrint(result.content), function(err) {
if (err) {
console.error("Couldn't write data to expected.html!");
console.error(err);
}
process.exit(0);
// Delete the result data we don't care about checking.
delete result.uri;
delete result.content;
delete result.length;
fs.writeFile(metadataDestPath, JSON.stringify(result, null, 2) + "\n", function(err) {
if (err) {
console.error("Couldn't write data to expected-metadata.json!");
console.error(err);
}
process.exit(0);
});
});
}

@ -1,5 +1,5 @@
{
"title": "Get your Frontend JavaScript Code Covered | Code",
"byline": "Nicolas Perriault —",
"excerpt": "width=device-width"
"excerpt": "Nicolas Perriault's homepage."
}

@ -1,5 +1,5 @@
{
"title": "Better Student Journalism — Medium",
"byline": "Pippin Lee",
"excerpt": "542599432471018"
"excerpt": "We pushed out the first version of the Open Journalism site in January. Heres what weve learned about student journali…"
}

@ -1,5 +1,5 @@
{
"title": "The sharing economy is a lie: Uber, Ayn Rand and the truth about tech\n and libertarians",
"byline": "Joanna Rothkopf",
"excerpt": "http://media.salon.com/2014/12/uber_rand_paul.jpg"
"excerpt": "Disruptive companies talk a good game about sharing. Uber's really just an under-regulated company making riches"
}

@ -1,5 +1,5 @@
{
"title": "Lupita Nyong'o's $150K Pearl Oscar Dress -- STOLEN!!!",
"byline": null,
"excerpt": "no"
"excerpt": "Lupita Nyong'o's now-famous Oscar dress -- adorned in pearls -- was stolen right out of her hotel room ... TMZ has learned. Law enforcement sources tell…"
}

@ -1,5 +1,5 @@
{
"title": "Attack stokes instability fears in North Africa",
"byline": "By Erin Cunningham",
"excerpt": "summary_large_image"
"excerpt": "The assault on Tunisias most renowned museum, in which gunmen killed at least 19 people, could heighten tensions in a nation that has become deeply divided between pro- and anti-Islamist factions."
}

@ -1,5 +1,5 @@
{
"title": "Where do strained U.S.-Israeli relations go after Netanyahus victory?",
"byline": "By Steven Mufson",
"excerpt": "summary_large_image"
"excerpt": "Few foreign leaders have so brazenly stood up to President Obama and the relationship could face its next test this month."
}

@ -1,5 +1,5 @@
{
"title": "Babies Who Eat Peanuts Early May Avoid Allergy",
"byline": "By Brenda Goodman, MA\n WebMD Health News",
"excerpt": "text/html; charset=UTF-8"
"excerpt": "Life-threatening peanut allergies have mysteriously been on the rise in the past decade, with little hope for a cure. But a groundbreaking new study may offer a way to stem that rise, while another may offer some hope for those who are already allergic."
}

Loading…
Cancel
Save