Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"nock": "^9.0.2",
"proxyquire": "^1.7.3",
"should": "^11.1.0",
"sinon": "^1.15.4",
"sinon-as-promised": "^4.0.0"
"sinon": "^2.1.0"
}
}
1 change: 0 additions & 1 deletion test/functional/error-handling/error-handling.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var should = require('should');
var nock = require('nock');
var sinon = require('sinon');
require('sinon-as-promised');
var fs = require('fs-extra');
var Promise = require('bluebird');
var Scraper = require('../../../lib/scraper');
Expand Down
1 change: 0 additions & 1 deletion test/unit/request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const should = require('should');
const nock = require('nock');
const sinon = require('sinon');
require('sinon-as-promised');
const proxyquire = require('proxyquire');
const Request = require('../../lib/request');

Expand Down
1 change: 0 additions & 1 deletion test/unit/resource-handler/css.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var should = require('should');
var Promise = require('bluebird');
var sinon = require('sinon');
require('sinon-as-promised')(Promise);
var Resource = require('../../../lib/resource');
var CssResourceHandler = require('../../../lib/resource-handler/css');

Expand Down
3 changes: 1 addition & 2 deletions test/unit/resource-handler/html.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require('should');
var Promise = require('bluebird');
var sinon = require('sinon');
require('sinon-as-promised')(Promise);
var Resource = require('../../../lib/resource');
var HtmlHandler = require('../../../lib/resource-handler/html');

Expand All @@ -13,7 +12,7 @@ describe('ResourceHandler: Html', function () {
var htmlHandler;

beforeEach(function() {
htmlHandler = new HtmlHandler({ sources: [] }, sinon.stub().resolves());
htmlHandler = new HtmlHandler({ sources: [] }, sinon.stub().returns(Promise.resolve()));
});

describe('<base> tag', function () {
Expand Down
33 changes: 16 additions & 17 deletions test/unit/resource-handler/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var should = require('should');
var sinon = require('sinon');
var Bluebird = require('bluebird');
require('sinon-as-promised')(Bluebird);
var Promise = require('bluebird');
var proxyquire = require('proxyquire');
var Resource = require('../../../lib/resource');
var ResourceHandler = require('../../../lib/resource-handler');
Expand Down Expand Up @@ -39,7 +38,7 @@ describe('ResourceHandler', function() {
'./css': cssHandlerStub
});

var handleChildResStub = sinon.stub(ResourceHandler.prototype, 'handleChildrenResources').resolves();
var handleChildResStub = sinon.stub(ResourceHandler.prototype, 'handleChildrenResources').returns(Promise.resolve());
var options = { defaultFilename: 'test' };
var context = { dummy: 'context' };

Expand Down Expand Up @@ -140,8 +139,8 @@ describe('ResourceHandler', function() {
parentResource = new Resource('http://example.com', 'test.txt');

scraperContext = {
requestResource: sinon.stub().resolves(),
loadResource: sinon.stub().resolves()
requestResource: sinon.stub().returns(Promise.resolve()),
loadResource: sinon.stub().returns(Promise.resolve())
};

resHandler = new ResourceHandler({defaultFilename: 'index.html'}, scraperContext);
Expand Down Expand Up @@ -184,9 +183,9 @@ describe('ResourceHandler', function() {
'http://second.com/img/c.jpg'
]);

scraperContext.requestResource.onFirstCall().resolves(new Resource('http://first.com/img/a.jpg', 'local/a.jpg'));
scraperContext.requestResource.onSecondCall().resolves(new Resource('http://first.com/b.jpg', 'local/b.jpg'));
scraperContext.requestResource.onThirdCall().resolves(new Resource('http://second.com/img/c.jpg', 'local/c.jpg'));
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(new Resource('http://first.com/img/a.jpg', 'local/a.jpg')));
scraperContext.requestResource.onSecondCall().returns(Promise.resolve(new Resource('http://first.com/b.jpg', 'local/b.jpg')));
scraperContext.requestResource.onThirdCall().returns(Promise.resolve(new Resource('http://second.com/img/c.jpg', 'local/c.jpg')));

var updateChildSpy = sinon.spy(parentResource, 'updateChild');

Expand Down Expand Up @@ -217,9 +216,9 @@ describe('ResourceHandler', function() {
'http://second.com/img/c.jpg'
]);

scraperContext.requestResource.onFirstCall().resolves(null);
scraperContext.requestResource.onSecondCall().resolves(null);
scraperContext.requestResource.onThirdCall().resolves(new Resource('http://second.com/img/c.jpg', 'local/c.jpg'));
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(null));
scraperContext.requestResource.onSecondCall().returns(Promise.resolve(null));
scraperContext.requestResource.onThirdCall().returns(Promise.resolve(new Resource('http://second.com/img/c.jpg', 'local/c.jpg')));

var updateChildSpy = sinon.spy(parentResource, 'updateChild');

Expand All @@ -244,9 +243,9 @@ describe('ResourceHandler', function() {

pathContainer.updateText.returns('UPDATED TEXT');

scraperContext.requestResource.onFirstCall().resolves(new Resource('http://first.com/img/a.jpg', 'local/a.jpg'));
scraperContext.requestResource.onSecondCall().resolves(null);
scraperContext.requestResource.onThirdCall().rejects(new Error('some error'));
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(new Resource('http://first.com/img/a.jpg', 'local/a.jpg')));
scraperContext.requestResource.onSecondCall().returns(Promise.resolve(null));
scraperContext.requestResource.onThirdCall().returns(Promise.reject(new Error('some error')));

return resHandler.handleChildrenResources(pathContainer, parentResource).then(function (updatedText) {
updatedText.should.be.eql('UPDATED TEXT');
Expand All @@ -257,7 +256,7 @@ describe('ResourceHandler', function() {
it('should keep hash in urls', function () {
var resourceStub = new Resource('http://example.com/page1.html', 'local/page1.html');
sinon.stub(resourceStub, 'getType').returns('html');
scraperContext.requestResource.onFirstCall().resolves(resourceStub);
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(resourceStub));

pathContainer.getPaths.returns(['http://example.com/page1.html#hash']);

Expand All @@ -276,7 +275,7 @@ describe('ResourceHandler', function() {
describe('prettifyUrls', function () {
it('should not prettifyUrls by default', function() {
var resourceStub = new Resource('http://example.com/other-page/index.html', 'other-page/index.html');
scraperContext.requestResource.onFirstCall().resolves(resourceStub);
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(resourceStub));

pathContainer.getPaths.returns(['http://example.com/other-page/index.html']);

Expand All @@ -294,7 +293,7 @@ describe('ResourceHandler', function() {

it('should prettifyUrls if specified', function() {
var resourceStub = new Resource('http://example.com/other-page/index.html', 'other-page/index.html');
scraperContext.requestResource.onFirstCall().resolves(resourceStub);
scraperContext.requestResource.onFirstCall().returns(Promise.resolve(resourceStub));

pathContainer.getPaths.returns(['http://example.com/other-page/index.html']);
resHandler.options.prettifyUrls = true;
Expand Down
1 change: 0 additions & 1 deletion test/unit/scraper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var should = require('should');
var sinon = require('sinon');
require('sinon-as-promised');
var nock = require('nock');
var proxyquire = require('proxyquire').noCallThru();
var fs = require('fs-extra');
Expand Down