-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from 0xc0d3c5/execute-scrape-tests-within-nodejs
Execute scrape.test.js within a Node.js environment
- Loading branch information
Showing
4 changed files
with
44 additions
and
13 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
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
require('./suites/node.test.js'); | ||
require('./suites/node.scrape.test.js'); |
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,30 @@ | ||
/** | ||
* artoo scrape method node unit tests | ||
* =================================== | ||
* | ||
*/ | ||
var cheerio = require('cheerio'), | ||
artoo = require('../../build/artoo.node.js'); | ||
|
||
function readFile(path) { | ||
return fs.readFileSync(path, 'utf-8'); | ||
} | ||
|
||
// Monkey patch - begin | ||
var assert = require('assert') | ||
var fs = require('fs') | ||
var $ | ||
|
||
helpers = { | ||
// Define a nodejs compliant fetchHTMLResource | ||
fetchHTMLResource: function (name, cb) { | ||
var $newDom = cheerio.load('<div id="' + name + '"></div>'); | ||
artoo.setContext($newDom) | ||
$newDom('#' + name).append(readFile(__dirname + '/../resources/' + name + '.html')); | ||
$ = $newDom | ||
cb('#' + name); | ||
} | ||
}; | ||
// Monkey patch - end | ||
|
||
eval(readFile(__dirname + '/scrape.test.js')) |
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