Skip to content

Commit 80bfbd5

Browse files
committed
Remove createOutputObject, return Resource as-is
1 parent 634f1c9 commit 80bfbd5

File tree

4 files changed

+15
-48
lines changed

4 files changed

+15
-48
lines changed

lib/scraper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ Scraper.prototype.prepare = function prepare () {
128128

129129
Scraper.prototype.load = function load () {
130130
var self = this;
131-
return Promise.map(self.originalResources, function loadPage (po) {
132-
return self.loadResource(po).then(utils.createOutputObject);
131+
return Promise.map(self.originalResources, function loadResource (resource) {
132+
return self.loadResource(resource);
133133
});
134134
};
135135

test/functional/base-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var nock = require('nock');
33
var fs = require('fs-extra');
44
var cheerio = require('cheerio');
55
var scraper = require('../../index');
6+
var Resource = require('../../lib/resource');
67

78
var testDirname = __dirname + '/.base';
89
var mockDirname = __dirname + '/mocks/base';
@@ -68,16 +69,19 @@ describe('Functional base', function() {
6869
result.should.be.instanceOf(Array).and.have.length(3);
6970

7071
result[0].should.have.properties({ url: 'http://example.com/', filename: 'index.html' });
71-
result[0].should.have.properties('assets');
72-
result[0].assets.should.be.instanceOf(Array).and.have.length(4);
72+
result[0].should.have.properties('children');
73+
result[0].children.should.be.instanceOf(Array).and.have.length(4);
74+
result[0].children[0].should.be.instanceOf(Resource);
7375

7476
result[1].should.have.properties({ url: 'http://example.com/about', filename: 'about.html' });
75-
result[1].should.have.properties('assets');
76-
result[1].assets.should.be.instanceOf(Array).and.have.length(4);
77+
result[1].should.have.properties('children');
78+
result[1].children.should.be.instanceOf(Array).and.have.length(4);
79+
result[1].children[0].should.be.instanceOf(Resource);
7780

7881
result[2].should.have.properties({ url: 'http://blog.example.com/', filename: 'blog.html' }); // url after redirect
79-
result[2].should.have.properties('assets');
80-
result[2].assets.should.be.instanceOf(Array).and.have.length(1);
82+
result[2].should.have.properties('children');
83+
result[2].children.should.be.instanceOf(Array).and.have.length(1);
84+
result[2].children[0].should.be.instanceOf(Resource);
8185

8286
// should create directory and subdirectories
8387
fs.existsSync(testDirname).should.be.eql(true);

test/unit/scraper-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ describe('Scraper', function () {
210210
}).catch(done);
211211
});
212212

213-
it('should return array of objects with url, filename and assets', function(done) {
213+
it('should return array of objects with url, filename and childre', function(done) {
214214
nock('http://first-url.com').get('/').reply(200, 'OK');
215215
nock('http://second-url.com').get('/').reply(500);
216216

@@ -225,8 +225,8 @@ describe('Scraper', function () {
225225
s.prepare().bind(s).then(s.load).then(function(res) {
226226
res.should.be.instanceOf(Array);
227227
res.should.have.length(2);
228-
res[0].should.have.properties(['url', 'filename', 'assets']);
229-
res[1].should.have.properties(['url', 'filename', 'assets']);
228+
res[0].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
229+
res[1].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
230230
done();
231231
}).catch(done);
232232
});

test/unit/utils-test.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -83,41 +83,4 @@ describe('Common utils', function () {
8383
utils.getRelativePath('css/1.css', 'css/2.css').should.be.equal('2.css');
8484
});
8585
});
86-
87-
describe('#createOutputObject', function () {
88-
it('should create output object recursively', function() {
89-
var root = new Resource('http://google.com', 'google.html');
90-
root.createChild('http://child-one.com', 'child.html');
91-
root.createChild('http://child-two.com', 'child2.html');
92-
93-
var expected = {
94-
url: 'http://google.com',
95-
filename: 'google.html',
96-
assets: [{
97-
url: 'http://child-one.com',
98-
filename: 'child.html',
99-
assets: []
100-
}, {
101-
url: 'http://child-two.com',
102-
filename: 'child2.html',
103-
assets: []
104-
}]
105-
};
106-
107-
var result = utils.createOutputObject(root);
108-
result.should.eql(expected);
109-
});
110-
111-
it('should not fail on referential loop', function() {
112-
var root = new Resource('http://example.com', 'index.html');
113-
var child1 = root.createChild('http://child-one.com', 'child1.html');
114-
var child2 = root.createChild('http://child-two.com', 'child2.html');
115-
// create referential loop
116-
var rootCopy = child1.createChild('http://example.com');
117-
child1.updateChild(rootCopy, root);
118-
119-
var result = utils.createOutputObject(root);
120-
result.should.be.not.empty();
121-
});
122-
});
12386
});

0 commit comments

Comments
 (0)