[Startup Engineering] HW3+Part 3: Write SSJS headless grader

I was refer to here.

But it printed result twice.


[email protected]:~/bitstarter$ ./grader.js --checks checks.json --url http://fathomless-tor-9565.herokuapp.com/
require.main else :
{
 ".about": true,
 ".blank": true,
 ".faq": true,
 ".footer": true,
 ".heading": true,
 ".logo": true,
 ".navigation": true,
 ".order": true,
 ".pitch": true,
 ".section1": true,
 ".section2": true,
 ".social": true,
 ".subheading": true,
 ".thermometer": true,
 ".video": true,
 "h1": true
}
require.main else :
{
 ".about": true,
 ".blank": true,
 ".faq": true,
 ".footer": true,
 ".heading": true,
 ".logo": true,
 ".navigation": true,
 ".order": true,
 ".pitch": true,
 ".section1": true,
 ".section2": true,
 ".social": true,
 ".subheading": true,
 ".thermometer": true,
 ".video": true,
 "h1": true
}

so, I modified below.


if(require.main == module) {
 program
 .option('-c, --checks <check_file>', 'Path to checks.json', clone(assertFileExists), CHECKSFILE_DEFAULT)
 .option('-f, --file <html_file>', 'Path to index.html', clone(assertFileExists), HTMLFILE_DEFAULT)
 .option('-u, --url <url>', 'path to herokuapp url', clone(assertURLExists))
// .option('-u, --url <url>', 'path to herokuapp url', clone(assertURLExists), CHECKSURL_DEFAULT)
 .parse(process.argv);

if(!program.url){ //original logic. file existing - index.html
 var checkJson = checkHtmlFile(program.file, program.checks);
 var outJson = JSON.stringify(checkJson, null, 4);
 console.log("required.main if : n" + outJson);
 } else { // added
// rest.get(program.url).on('complete', function(result){
 var checkJson = checkURL(program.url, program.checks);
 var outJson = JSON.stringify(checkJson, null, 4);
 console.log("require.main else : n" + outJson);
 };

} else {
 exports.checkHtmlFile = checkHtmlFile;
}

RESULT :


[email protected]:~/bitstarter$ ./grader.js --checks checks.json --url http://fathomless-tor-9565.herokuapp.com/
require.main else :
{
 ".about": false,
 ".blank": false,
 ".faq": false,
 ".footer": false,
 ".heading": false,
 ".logo": false,
 ".navigation": false,
 ".order": false,
 ".pitch": false,
 ".section1": false,
 ".section2": false,
 ".social": false,
 ".subheading": false,
 ".thermometer": false,
 ".video": false,
 "h1": false
}
[email protected]:~/bitstarter$

앱 & 서비스 기획자입니다. 잘하고 싶어요.

  • Hi, this is a really useful blog, it pointed me in the right direction and saved me hours.

    • Thanks, but I am not a developer, just studying as project manager, so I don’t know well :)

Sliding Sidebar