diff --git a/package.json b/package.json index 2892061b..c5cbb1a3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/functional/error-handling/error-handling.test.js b/test/functional/error-handling/error-handling.test.js index 2e64982b..3371d4d5 100644 --- a/test/functional/error-handling/error-handling.test.js +++ b/test/functional/error-handling/error-handling.test.js @@ -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'); diff --git a/test/unit/request-test.js b/test/unit/request-test.js index a08ecdcb..2d64f9ea 100644 --- a/test/unit/request-test.js +++ b/test/unit/request-test.js @@ -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'); diff --git a/test/unit/resource-handler/css.test.js b/test/unit/resource-handler/css.test.js index 3ceadf5a..b1a39b9f 100644 --- a/test/unit/resource-handler/css.test.js +++ b/test/unit/resource-handler/css.test.js @@ -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'); diff --git a/test/unit/resource-handler/html.test.js b/test/unit/resource-handler/html.test.js index 139f6aa4..c8f5b1d7 100644 --- a/test/unit/resource-handler/html.test.js +++ b/test/unit/resource-handler/html.test.js @@ -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'); @@ -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(' tag', function () { diff --git a/test/unit/resource-handler/index.test.js b/test/unit/resource-handler/index.test.js index 57dbc907..1efb1ad4 100644 --- a/test/unit/resource-handler/index.test.js +++ b/test/unit/resource-handler/index.test.js @@ -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'); @@ -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' }; @@ -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); @@ -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'); @@ -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'); @@ -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'); @@ -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']); @@ -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']); @@ -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; diff --git a/test/unit/scraper-test.js b/test/unit/scraper-test.js index 558e381c..e36b8c37 100644 --- a/test/unit/scraper-test.js +++ b/test/unit/scraper-test.js @@ -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');