-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
normalizing/splitting canonical tests
- Loading branch information
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const path = require('path'); | ||
const express = require('express'); | ||
|
||
module.exports = (Automaton)=>{ | ||
return { | ||
render : { | ||
table : (h, b)=>{ | ||
let headers = b && h; | ||
let body = b || h; | ||
let result = ''; | ||
if(headers) result += `<thead>${body.map((row)=>{ | ||
return `<tr>${row.map((item)=>{ | ||
return `<th>${item}</th>` | ||
})}</tr>` | ||
})}</thead>`; | ||
result += `<tbody>${body.map((row)=>{ | ||
return `<tr>${row.map((item)=>{ | ||
return `<td>${item}</td>` | ||
})}</tr>` | ||
})}</tbody>`; | ||
return `<table>${result}</table>` | ||
} | ||
}, | ||
endpointsAgainstDefinition : function(endpoints, xml, engine, values, instance, complete){ | ||
let done = complete; | ||
let app = instance; | ||
let data = values; | ||
if(typeof instance === 'function' && !complete){ | ||
done = instance; | ||
app = null; | ||
} | ||
if(typeof values === 'function' && !complete){ | ||
done = values; | ||
data = {}; | ||
app = null; | ||
} | ||
if(!app) app = express(); | ||
Object.keys(endpoints).forEach((method)=>{ | ||
Object.keys(endpoints[method]).forEach((path)=>{ | ||
app[method.toLowerCase()](path, endpoints[method][path]); | ||
}); | ||
}); | ||
let server = app.listen(8080, (err)=>{ | ||
if(err) throw err; | ||
let scraper = new Automaton({ | ||
body: xml, | ||
environment : data | ||
}, engine); | ||
scraper.run((err, resultData)=>{ | ||
done(err, resultData, (cleanupComplete)=>{ | ||
server.close(()=>{ | ||
if(cleanupComplete) cleanupComplete(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module.exports = (Automaton, should)=>{ | ||
const base = require('../base.js')(Automaton); | ||
|
||
return (engine, complete)=>{ | ||
let startTime = (new Date()).getTime(); | ||
base.endpointsAgainstDefinition({ | ||
"GET" : { | ||
"/" : (req, res)=>{ | ||
res.setHeader('content-type', 'text/html') | ||
res.send(`<html> | ||
<head></head> | ||
<body>${base.render.table([ | ||
['foo', 'bar', 'baz'] | ||
])}</body> | ||
</html>`); | ||
} | ||
} | ||
}, ` | ||
<go url="http://\${host}/" delay="3s"> | ||
<set xpath="//table/tbody/tr" push="true" variable="matches"> | ||
<set xpath="//td[1]/text()" variable="first"></set> | ||
<set xpath="//td[2]/text()" variable="second"></set> | ||
<set xpath="//td[3]/text()" variable="third"></set> | ||
</set> | ||
<emit variables="matches"></emit> | ||
</go> | ||
`, engine, { | ||
host : 'localhost:8080' | ||
}, (err, data, cleanup)=>{ | ||
let finishTime = (new Date()).getTime(); | ||
let difference = finishTime - startTime; | ||
difference.should.be.above(3000); | ||
should.not.exist(err); | ||
should.exist(data); | ||
should.exist(data.matches); | ||
should.exist(data.matches[0]); | ||
should.exist(data.matches[0].first); | ||
should.exist(data.matches[0].second); | ||
should.exist(data.matches[0].third); | ||
data.matches[0].first.should.equal('foo'); | ||
data.matches[0].second.should.equal('bar'); | ||
data.matches[0].third.should.equal('baz'); | ||
cleanup(()=>{ | ||
complete(); | ||
}) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module.exports = (Automaton, should)=>{ | ||
const base = require('../base.js')(Automaton); | ||
|
||
return (engine, complete)=>{ | ||
let startTime = (new Date()).getTime(); | ||
base.endpointsAgainstDefinition({ | ||
"GET" : { | ||
"/" : (req, res)=>{ | ||
res.setHeader('content-type', 'text/html') | ||
res.send(`<html> | ||
<head> | ||
<script> | ||
let toRender = '${base.render.table([ | ||
['foo', 'bar', 'baz'] | ||
])}'; | ||
setTimeout(()=>{ | ||
document.body.innerHTML = toRender; | ||
}, 5 * 1000); | ||
</script> | ||
</head> | ||
<body></body> | ||
</html>`); | ||
} | ||
} | ||
}, ` | ||
<go url="http://\${host}/" until-exists="//table"> | ||
<set xpath="//table/tbody/tr" push="true" variable="matches"> | ||
<set xpath="//td[1]/text()" variable="first"></set> | ||
<set xpath="//td[2]/text()" variable="second"></set> | ||
<set xpath="//td[3]/text()" variable="third"></set> | ||
</set> | ||
<emit variables="matches"></emit> | ||
</go> | ||
`, engine, { | ||
host : 'localhost:8080' | ||
}, (err, data, cleanup)=>{ | ||
let finishTime = (new Date()).getTime(); | ||
let difference = finishTime - startTime; | ||
difference.should.be.above(5000); | ||
should.not.exist(err); | ||
should.exist(data); | ||
should.exist(data.matches); | ||
should.exist(data.matches[0]); | ||
should.exist(data.matches[0].first); | ||
should.exist(data.matches[0].second); | ||
should.exist(data.matches[0].third); | ||
data.matches[0].first.should.equal('foo'); | ||
data.matches[0].second.should.equal('bar'); | ||
data.matches[0].third.should.equal('baz'); | ||
cleanup(()=>{ | ||
complete(); | ||
}) | ||
}); | ||
} | ||
} |