From 3a215994ff1f6ec1a1de6884c67afb91bf9d8937 Mon Sep 17 00:00:00 2001 From: s0ph1e Date: Sat, 11 Mar 2017 14:00:11 +0200 Subject: [PATCH 1/2] Export default options --- index.js | 2 ++ lib/scraper.js | 2 ++ test/unit/scraper-test.js | 12 +++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 70b8cd47..9b698f3c 100644 --- a/index.js +++ b/index.js @@ -3,3 +3,5 @@ var Scraper = require('./lib/scraper.js'); module.exports = function scrape (options, callback) { return new Scraper(options).scrape(callback); }; + +module.exports.defaults = Scraper.defaults; diff --git a/lib/scraper.js b/lib/scraper.js index 86b49b95..64a6e302 100644 --- a/lib/scraper.js +++ b/lib/scraper.js @@ -200,4 +200,6 @@ Scraper.prototype.scrape = function scrape (callback) { .asCallback(callback); }; +Scraper.defaults = _.clone(defaults); + module.exports = Scraper; diff --git a/test/unit/scraper-test.js b/test/unit/scraper-test.js index b019087b..558e381c 100644 --- a/test/unit/scraper-test.js +++ b/test/unit/scraper-test.js @@ -4,7 +4,7 @@ var should = require('should'); var sinon = require('sinon'); require('sinon-as-promised'); var nock = require('nock'); -var proxyquire = require('proxyquire'); +var proxyquire = require('proxyquire').noCallThru(); var fs = require('fs-extra'); var path = require('path'); var Scraper = require('../../lib/scraper'); @@ -480,4 +480,14 @@ describe('Scraper', function () { }); }); }); + + describe('defaults', function() { + it('should export defaults', function() { + var defaultsMock = { subdirectories: null, recursive: true, sources: [] }; + Scraper = proxyquire('../../lib/scraper', { + './config/defaults': defaultsMock + }); + should(Scraper.defaults).be.eql({ subdirectories: null, recursive: true, sources: [] }); + }); + }); }); From 5012ea8cf0d586892c1bcaa4e895ec681ee4a0a0 Mon Sep 17 00:00:00 2001 From: Sophia Antipenko Date: Sat, 11 Mar 2017 14:03:05 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba25c42e..c0b6fbb4 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ scrape(options, (error, result) => { * [onResourceSaved](#onresourcesaved) - callback called when resource is saved * [onResourceError](#onresourceerror) - callback called when resource's downloading is failed -Default options you can find in [lib/config/defaults.js](https://github.com/s0ph1e/node-website-scraper/blob/master/lib/config/defaults.js). +Default options you can find in [lib/config/defaults.js](https://github.com/s0ph1e/node-website-scraper/blob/master/lib/config/defaults.js) or get them using `scrape.defaults`. #### urls Array of objects which contain urls to download and filenames for them. **_Required_**.