Last active
August 29, 2015 13:58
-
-
Save zamber/9951669 to your computer and use it in GitHub Desktop.
DalekJS + Anvil -> screenshots for a dir full of .html files
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
/* | |
Iterate over the static frontend and make screenshots. | |
Point Anvil to the prod build dir where index.html is. | |
*/ | |
// Get IP for ievms + anvil | |
// https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js | |
var os = require('os'); | |
var ip; | |
var ifaces = os.networkInterfaces(); | |
for (var dev in ifaces) { | |
var alias = 0; | |
ifaces[dev].forEach( function (details) { | |
if (details.family == 'IPv4' & dev == 'en0') { | |
console.log(dev + (alias ? ':' + alias : ''), details.address); | |
ip = details.address; | |
++alias; | |
} | |
}); | |
} | |
var root = 'http://prod.' + ip + '.xip.io/'; // Anvil url | |
var path = 'build/prod/'; // Relative path for building the pages array | |
// get files from static preview path | |
var fs=require('fs'); | |
var pages = fs.readdirSync(path) | |
.filter( function (file) { return file.substr(-5) == '.html' }) | |
.filter( function (file) { return file.indexOf('index.html') == -1 }); | |
console.log(pages); | |
function testfunc(root, page) { | |
return function (test) { | |
test | |
.open(root + page) | |
.screenshot('screens/' + page.split('.')[0] + '-:browser' + '.png') | |
.log.message( 'Got it!' ) | |
.done(); | |
} | |
} | |
var exp = {}; | |
for (var page in pages) { | |
var txt = 'Shoot for ' + root + pages[page]; | |
exp[txt] = testfunc(root, pages[page]); | |
} | |
module.exports = exp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment