diff --git a/package.json b/package.json
index 2c58b324..1e8863ee 100644
--- a/package.json
+++ b/package.json
@@ -49,10 +49,10 @@
},
"devDependencies": {
"c8": "^10.0.0",
+ "chai": "^6.2.0",
"eslint": "^8.5.0",
"mocha": "^11.0.1",
"nock": "^14.0.0",
- "should": "^13.2.3",
"sinon": "^21.0.0"
},
"files": [
diff --git a/test/e2e/e2e-test.js b/test/e2e/e2e-test.js
index 41de4392..391ed754 100644
--- a/test/e2e/e2e-test.js
+++ b/test/e2e/e2e-test.js
@@ -1,12 +1,13 @@
-import 'should';
import scrape from 'website-scraper';
import fs from 'fs-extra';
+import * as chai from 'chai';
import { readFile } from 'fs/promises';
const urls = JSON.parse(await readFile(new URL('./urls.json', import.meta.url)));
const options = JSON.parse(await readFile(new URL('./options.json', import.meta.url)));
const resultDirname = './test/e2e/results';
+chai.should();
describe('E2E', function() {
before(function() {
@@ -26,7 +27,7 @@ describe('E2E', function() {
scraperOptions.urls = [ { url: url, filename: 'index.html' } ];
scraperOptions.filenameGenerator = 'byType';
return scrape(scraperOptions).then(function(result) {
- result.should.be.ok();
+ result.should.be.ok;
});
});
@@ -37,7 +38,7 @@ describe('E2E', function() {
scraperOptions.urls = [ { url: url } ];
scraperOptions.filenameGenerator = 'bySiteStructure';
return scrape(scraperOptions).then(function(result) {
- result.should.be.ok();
+ result.should.be.ok;
});
});
});
diff --git a/test/functional/base/base.test.js b/test/functional/base/base.test.js
index 1979a051..78527b09 100644
--- a/test/functional/base/base.test.js
+++ b/test/functional/base/base.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -72,18 +74,21 @@ describe('Functional: base', function() {
// should return right result
result.should.be.instanceOf(Array).and.have.length(3);
- result[0].should.have.properties({ url: 'http://example.com/', filename: 'index.html' });
- result[0].should.have.properties('children');
+ result[0].should.have.property('url', 'http://example.com/');
+ result[0].should.have.property('filename', 'index.html');
+ result[0].should.have.property('children');
result[0].children.should.be.instanceOf(Array).and.have.length(4);
result[0].children[0].should.be.instanceOf(Resource);
- result[1].should.have.properties({ url: 'http://example.com/about', filename: 'about.html' });
- result[1].should.have.properties('children');
+ result[1].should.have.property('url', 'http://example.com/about');
+ result[1].should.have.property('filename', 'about.html');
+ result[1].should.have.property('children');
result[1].children.should.be.instanceOf(Array).and.have.length(4);
result[1].children[0].should.be.instanceOf(Resource);
- result[2].should.have.properties({ url: 'http://blog.example.com/', filename: 'blog.html' }); // url after redirect
- result[2].should.have.properties('children');
+ result[2].should.have.property('url', 'http://blog.example.com/'); // url after redirect
+ result[2].should.have.property('filename', 'blog.html');
+ result[2].should.have.property('children');
result[2].children.should.be.instanceOf(Array).and.have.length(1);
result[2].children[0].should.be.instanceOf(Resource);
@@ -102,7 +107,7 @@ describe('Functional: base', function() {
// all sources in index.html should be replaced with local paths
let $ = cheerio.load(fs.readFileSync(testDirname + '/index.html').toString());
$('link[rel="stylesheet"]').attr('href').should.be.eql('css/index.css');
- $('style').html().should.containEql('img/background.png');
+ $('style').html().should.contain('img/background.png');
$('img').attr('src').should.be.eql('img/cat.jpg');
$('script').attr('src').should.be.eql('js/script.min.js');
@@ -115,22 +120,22 @@ describe('Functional: base', function() {
// all sources in index.css should be replaces with local files recursively
const indexCss = fs.readFileSync(testDirname + '/css/index.css').toString();
- indexCss.should.not.containEql('files/index-import-1.css');
- indexCss.should.not.containEql('files/index-import-2.css');
- indexCss.should.not.containEql('http://example.com/files/index-image-1.png');
- indexCss.should.containEql('index-import-1.css');
- indexCss.should.containEql('index-import-2.css');
- indexCss.should.containEql('../img/index-image-1.png');
+ indexCss.should.not.contain('files/index-import-1.css');
+ indexCss.should.not.contain('files/index-import-2.css');
+ indexCss.should.not.contain('http://example.com/files/index-image-1.png');
+ indexCss.should.contain('index-import-1.css');
+ indexCss.should.contain('index-import-2.css');
+ indexCss.should.contain('../img/index-image-1.png');
const indexImportCss = fs.readFileSync(testDirname + '/css/index-import-2.css').toString();
- indexImportCss.should.not.containEql('http://example.com/files/index-image-2.png');
- indexImportCss.should.containEql('../img/index-image-2.png');
+ indexImportCss.should.not.contain('http://example.com/files/index-image-2.png');
+ indexImportCss.should.contain('../img/index-image-2.png');
// should deal with base tag in about.html and not load new resources
// all sources in about.html should be replaced with already loaded local resources
$ = cheerio.load(fs.readFileSync(testDirname + '/about.html').toString());
$('link[rel="stylesheet"]').attr('href').should.be.eql('css/index.css');
- $('style').html().should.containEql('img/background.png');
+ $('style').html().should.contain('img/background.png');
$('img').attr('src').should.be.eql('img/cat.jpg');
$('script').attr('src').should.be.eql('js/script.min.js');
@@ -144,21 +149,21 @@ describe('Functional: base', function() {
return scrape({...options, filenameGenerator: 'bySiteStructure'}).then(function(result) {
result.should.be.instanceOf(Array).and.have.length(3);
- should(result[0].url).eql('http://example.com/');
- should(result[0].filename).equalFileSystemPath('example.com/index.html');
- result[0].should.have.properties('children');
+ result[0].url.should.eql('http://example.com/');
+ result[0].filename.should.equalFileSystemPath('example.com/index.html');
+ result[0].should.have.property('children');
result[0].children.should.be.instanceOf(Array).and.have.length(4);
result[0].children[0].should.be.instanceOf(Resource);
- should(result[1].url).eql('http://example.com/about');
- should(result[1].filename).equalFileSystemPath('example.com/about/index.html');
- result[1].should.have.properties('children');
+ result[1].url.should.eql('http://example.com/about');
+ result[1].filename.should.equalFileSystemPath('example.com/about/index.html');
+ result[1].should.have.property('children');
result[1].children.should.be.instanceOf(Array).and.have.length(4);
result[1].children[0].should.be.instanceOf(Resource);
- should(result[2].url).eql('http://blog.example.com/'); // url after redirect
- should(result[2].filename).equalFileSystemPath('blog.example.com/index.html');
- result[2].should.have.properties('children');
+ result[2].url.should.eql('http://blog.example.com/'); // url after redirect
+ result[2].filename.should.equalFileSystemPath('blog.example.com/index.html');
+ result[2].should.have.property('children');
result[2].children.should.be.instanceOf(Array).and.have.length(1);
result[2].children[0].should.be.instanceOf(Resource);
@@ -177,7 +182,7 @@ describe('Functional: base', function() {
// all sources in index.html should be replaced with local paths
let $ = cheerio.load(fs.readFileSync(testDirname + '/example.com/index.html').toString());
$('link[rel="stylesheet"]').attr('href').should.be.eql('index.css');
- $('style').html().should.containEql('background.png');
+ $('style').html().should.contain('background.png');
$('img').attr('src').should.be.eql('cat.jpg');
$('script').attr('src').should.be.eql('script.min.js');
@@ -190,18 +195,18 @@ describe('Functional: base', function() {
// all sources in index.css should be replaces with local files recursively
const indexCss = fs.readFileSync(testDirname + '/example.com/index.css').toString();
- indexCss.should.containEql('files/index-import-1.css');
- indexCss.should.containEql('files/index-import-2.css');
- indexCss.should.containEql('files/index-image-1.png');
+ indexCss.should.contain('files/index-import-1.css');
+ indexCss.should.contain('files/index-import-2.css');
+ indexCss.should.contain('files/index-image-1.png');
const indexImportCss = fs.readFileSync(testDirname + '/example.com/files/index-import-2.css').toString();
- indexImportCss.should.containEql('index-image-2.png');
+ indexImportCss.should.contain('index-image-2.png');
// should deal with base tag in about.html and not load new resources
// all sources in about.html should be replaced with already loaded local resources
$ = cheerio.load(fs.readFileSync(testDirname + '/example.com/about/index.html').toString());
$('link[rel="stylesheet"]').attr('href').should.be.eql('../index.css');
- $('style').html().should.containEql('../background.png');
+ $('style').html().should.contain('../background.png');
$('img').attr('src').should.be.eql('../cat.jpg');
$('script').attr('src').should.be.eql('../script.min.js');
diff --git a/test/functional/base/check-it-works.js b/test/functional/base/check-it-works.js
index 3bb61b5d..1a7827a8 100644
--- a/test/functional/base/check-it-works.js
+++ b/test/functional/base/check-it-works.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -28,9 +29,9 @@ describe('Functional: check it works', function() {
};
return scrape(options).then((result) => {
- should(result[0].url).be.eql('http://example.com/');
- should(result[0].filename).be.eql('index.html');
- should(result[0].text).be.eql('
TEST PROMISES');
+ result[0].url.should.be.eql('http://example.com/');
+ result[0].filename.should.be.eql('index.html');
+ result[0].text.should.be.eql('TEST PROMISES');
});
});
});
diff --git a/test/functional/binary-resources/images.test.js b/test/functional/binary-resources/images.test.js
index 140c3294..e21c10be 100644
--- a/test/functional/binary-resources/images.test.js
+++ b/test/functional/binary-resources/images.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -63,7 +65,7 @@ describe('Functional: images', () => {
const resultPng = fs.readFileSync(testDirname + '/img/test-image.png');
const resultJpg = fs.readFileSync(testDirname + '/img/test-image.jpg');
- should(resultPng).be.eql(originalPng);
- should(resultJpg).be.eql(originalJpg);
+ resultPng.should.be.eql(originalPng);
+ resultJpg.should.be.eql(originalJpg);
});
});
diff --git a/test/functional/callbacks/callbacks.test.js b/test/functional/callbacks/callbacks.test.js
index 7f6b3279..041cd538 100644
--- a/test/functional/callbacks/callbacks.test.js
+++ b/test/functional/callbacks/callbacks.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -45,12 +47,12 @@ describe('Functional: onResourceSaved and onResourceError callbacks in plugin',
};
return scrape(options).then(function() {
- should(resourceSavedStub.calledOnce).be.eql(true);
- should(resourceSavedStub.args[0][0].resource.url).be.eql('http://example.com/');
+ resourceSavedStub.calledOnce.should.be.eql(true);
+ resourceSavedStub.args[0][0].resource.url.should.be.eql('http://example.com/');
- should(resourceErrorStub.calledOnce).be.eql(true);
- should(resourceErrorStub.args[0][0].resource.url).be.eql('http://nodejs.org/');
- should(resourceErrorStub.args[0][0].error.message).be.eql('REQUEST ERROR!!');
+ resourceErrorStub.calledOnce.should.be.eql(true);
+ resourceErrorStub.args[0][0].resource.url.should.be.eql('http://nodejs.org/');
+ resourceErrorStub.args[0][0].error.message.should.be.eql('REQUEST ERROR!!');
});
});
@@ -80,11 +82,11 @@ describe('Functional: onResourceSaved and onResourceError callbacks in plugin',
};
return scrape(options).then(function() {
- should(true).eql(false);
+ false.should.be.true;
}).catch(() => {
- should(resourceErrorStub.calledOnce).be.eql(true);
- should(resourceErrorStub.args[0][0].resource.url).be.eql('http://nodejs.org/');
- should(resourceErrorStub.args[0][0].error.message).be.eql('REQUEST ERROR!!');
+ resourceErrorStub.calledOnce.should.be.eql(true);
+ resourceErrorStub.args[0][0].resource.url.should.be.eql('http://nodejs.org/');
+ resourceErrorStub.args[0][0].error.message.should.be.eql('REQUEST ERROR!!');
});
});
});
diff --git a/test/functional/circular-dependencies/circular-dependencies.test.js b/test/functional/circular-dependencies/circular-dependencies.test.js
index d5a5c229..0896a540 100644
--- a/test/functional/circular-dependencies/circular-dependencies.test.js
+++ b/test/functional/circular-dependencies/circular-dependencies.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
diff --git a/test/functional/css-handling/css-handling.test.js b/test/functional/css-handling/css-handling.test.js
index 211b2b1f..b7bda540 100644
--- a/test/functional/css-handling/css-handling.test.js
+++ b/test/functional/css-handling/css-handling.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -51,10 +53,10 @@ describe('Functional: css handling', function() {
const indexHtml = fs.readFileSync(testDirname + '/index.html').toString();
- should(indexHtml).containEql('local/style-tag.png');
- should(indexHtml).containEql('local/style-attr.png');
+ indexHtml.should.contain('local/style-tag.png');
+ indexHtml.should.contain('local/style-attr.png');
- should(indexHtml).containEql('background: url(\'css-like-text-in-html.png\')');
+ indexHtml.should.contain("background: url('css-like-text-in-html.png')");
});
});
});
diff --git a/test/functional/data-url/data-url.test.js b/test/functional/data-url/data-url.test.js
index c494dd69..fdfa94bf 100644
--- a/test/functional/data-url/data-url.test.js
+++ b/test/functional/data-url/data-url.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -37,12 +39,12 @@ describe('Functional: data urls handling', function () {
const actualIndexHtml = fs.readFileSync(testDirname + '/index.html').toString();
- should(actualIndexHtml).containEql('');
- should(actualIndexHtml).containEql('');
- should(actualIndexHtml).containEql('');
- should(actualIndexHtml).containEql('');
- should(actualIndexHtml).containEql('');
- should(actualIndexHtml).containEql('
');
+ actualIndexHtml.should.contain('');
+ actualIndexHtml.should.contain('');
+ actualIndexHtml.should.contain('');
+ actualIndexHtml.should.contain('');
+ actualIndexHtml.should.contain('');
+ actualIndexHtml.should.contain('
');
});
});
});
diff --git a/test/functional/encoding/encoding.test.js b/test/functional/encoding/encoding.test.js
index b8c3db5f..918deedc 100644
--- a/test/functional/encoding/encoding.test.js
+++ b/test/functional/encoding/encoding.test.js
@@ -32,11 +32,11 @@ describe('Functional: encoding', () => {
await scrape(options);
const scrapedIndex = await fs.readFile(testDirname + '/index.html', { encoding: 'utf8' });
- scrapedIndex.should.be.containEql('저는 7년 동안 한국에서 살았어요.
');
- scrapedIndex.should.be.containEql('Слава Україні!
');
- scrapedIndex.should.be.containEql('加入网站
');
- scrapedIndex.should.be.containEql('Обладнання та ПЗ
');
- scrapedIndex.should.be.containEql('PAR PASSION DU VÉLO
');
+ scrapedIndex.should.contain('\uc800\ub294 7\ub144 \ub3d9\uc548 \ud55c\uad6d\uc5d0\uc11c \uc0b4\uc558\uc5b4\uc694.
');
+ scrapedIndex.should.contain('\u0421\u043b\u0430\u0432\u0430 \u0423\u043a\u0440\u0430\u0457\u043d\u0456!
');
+ scrapedIndex.should.contain('\u52a0\u5165\u7f51\u7ad9
');
+ scrapedIndex.should.contain('\u041e\u0431\u043b\u0430\u0434\u043d\u0430\u043d\u043d\u044f \u0442\u0430 \u041f\u0417
');
+ scrapedIndex.should.contain('PAR PASSION DU V\u00c9LO
');
});
it('should save the page with enconding from html meta tag', async () => {
@@ -45,10 +45,10 @@ describe('Functional: encoding', () => {
await scrape(options);
const scrapedIndex = await fs.readFile(testDirname + '/index.html', { encoding: 'utf8' });
- scrapedIndex.should.be.containEql('저는 7년 동안 한국에서 살았어요.
');
- scrapedIndex.should.be.containEql('Слава Україні!
');
- scrapedIndex.should.be.containEql('加入网站
');
- scrapedIndex.should.be.containEql('Обладнання та ПЗ
');
- scrapedIndex.should.be.containEql('PAR PASSION DU VÉLO
');
+ scrapedIndex.should.contain('\uc800\ub294 7\ub144 \ub3d9\uc548 \ud55c\uad6d\uc5d0\uc11c \uc0b4\uc558\uc5b4\uc694.
');
+ scrapedIndex.should.contain('\u0421\u043b\u0430\u0432\u0430 \u0423\u043a\u0440\u0430\u0457\u043d\u0456!
');
+ scrapedIndex.should.contain('\u52a0\u5165\u7f51\u7ad9
');
+ scrapedIndex.should.contain('\u041e\u0431\u043b\u0430\u0434\u043d\u0430\u043d\u043d\u044f \u0442\u0430 \u041f\u0417
');
+ scrapedIndex.should.contain('PAR PASSION DU V\u00c9LO
');
});
});
diff --git a/test/functional/error-handling/error-handling.test.js b/test/functional/error-handling/error-handling.test.js
index 9360b668..e9a8e993 100644
--- a/test/functional/error-handling/error-handling.test.js
+++ b/test/functional/error-handling/error-handling.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -65,11 +67,11 @@ describe('Functional error handling', function() {
};
return scrape(scraperOptions).then(function() {
- should(true).be.eql(false);
+ false.should.be.true;
}).catch(function (err) {
- should(err.message).be.eql('FS FAILED!');
- should(saveResourceStub.callCount).be.eql(3);
- should(handleErrorStub.callCount).be.eql(1);
+ err.message.should.be.eql('FS FAILED!');
+ saveResourceStub.callCount.should.be.eql(3);
+ handleErrorStub.callCount.should.be.eql(1);
});
});
@@ -83,8 +85,8 @@ describe('Functional error handling', function() {
};
return scrape(scraperOptions).then(function() {
- should(saveResourceStub.callCount).be.eql(7);
- should(handleErrorStub.callCount).be.eql(0);
+ saveResourceStub.callCount.should.be.eql(7);
+ handleErrorStub.callCount.should.be.eql(0);
});
});
});
@@ -113,11 +115,11 @@ describe('Functional error handling', function() {
scraper.options.ignoreErrors = false;
return scraper.scrape().then(function() {
- should(true).be.eql(false);
+ false.should.be.true;
}).catch(function (err) {
fs.existsSync(testDirname).should.be.eql(false);
- should(err.message).be.eql('RESOURCE HANDLER FAILED!');
- should(handleResourceStub.callCount).be.eql(4);
+ err.message.should.be.eql('RESOURCE HANDLER FAILED!');
+ handleResourceStub.callCount.should.be.eql(4);
});
});
@@ -125,7 +127,7 @@ describe('Functional error handling', function() {
scraper.options.ignoreErrors = true;
return scraper.scrape().then(function() {
- should(handleResourceStub.callCount).be.eql(7);
+ handleResourceStub.callCount.should.be.eql(7);
fs.existsSync(testDirname).should.be.eql(true);
});
});
diff --git a/test/functional/html-entities/html-entities.test.js b/test/functional/html-entities/html-entities.test.js
index cb682dd5..18b99e6b 100644
--- a/test/functional/html-entities/html-entities.test.js
+++ b/test/functional/html-entities/html-entities.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -58,34 +60,34 @@ describe('Functional: html entities', function() {
fs.existsSync(testDirname + '/index.html').should.be.eql(true);
const indexHtml = fs.readFileSync(testDirname + '/index.html').toString();
- should(indexHtml).containEql('href="local/fonts.css');
+ indexHtml.should.contain('href="local/fonts.css');
fs.existsSync(testDirname + '/local/fonts.css').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/local/fonts.css').toString()).be.eql('fonts.css');
+ fs.readFileSync(testDirname + '/local/fonts.css').toString().should.be.eql('fonts.css');
// single quote (') replaced with ' in attribute
- should(indexHtml).containEql('background: url(\'local/style-attr.png\')');
+ indexHtml.should.contain('background: url(\'local/style-attr.png\')');
fs.existsSync(testDirname + '/local/style-attr.png').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/local/style-attr.png').toString()).be.eql('style-attr.png');
+ fs.readFileSync(testDirname + '/local/style-attr.png').toString().should.be.eql('style-attr.png');
// double quote (") replaced with " in attribute
- should(indexHtml).containEql('background: url("local/style-attr2.png")');
+ indexHtml.should.contain('background: url("local/style-attr2.png")');
fs.existsSync(testDirname + '/local/style-attr2.png').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/local/style-attr2.png').toString()).be.eql('style-attr2.png');
+ fs.readFileSync(testDirname + '/local/style-attr2.png').toString().should.be.eql('style-attr2.png');
- should(indexHtml).containEql('img src="local/img.png');
+ indexHtml.should.contain('img src="local/img.png');
fs.existsSync(testDirname + '/local/img.png').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/local/img.png').toString()).be.eql('img.png');
+ fs.readFileSync(testDirname + '/local/img.png').toString().should.be.eql('img.png');
- should(indexHtml).containEql('href="index_1.html"');
+ indexHtml.should.contain('href="index_1.html"');
fs.existsSync(testDirname + '/index_1.html').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/index_1.html').toString()).be.eql('index_1.html');
+ fs.readFileSync(testDirname + '/index_1.html').toString().should.be.eql('index_1.html');
fs.existsSync(testDirname + '/local/style.css').should.be.eql(true);
const styleCss = fs.readFileSync(testDirname + '/local/style.css').toString();
- should(styleCss).containEql('url(\'external-style.png\')');
+ styleCss.should.contain('url(\'external-style.png\')');
fs.existsSync(testDirname + '/local/external-style.png').should.be.eql(true);
- should(fs.readFileSync(testDirname + '/local/external-style.png').toString()).be.eql('external-style.png');
+ fs.readFileSync(testDirname + '/local/external-style.png').toString().should.be.eql('external-style.png');
});
});
@@ -106,6 +108,6 @@ describe('Functional: html entities', function() {
becomes
*/
- should(indexHtml).containEql('data-test="[{"breakpoint": 1200,"slidesToShow": 3}]"');
+ indexHtml.should.contain('data-test="[{"breakpoint": 1200,"slidesToShow": 3}]"');
});
});
diff --git a/test/functional/html-id-href/html-id-href.test.js b/test/functional/html-id-href/html-id-href.test.js
index ed93c623..85b9d33d 100644
--- a/test/functional/html-id-href/html-id-href.test.js
+++ b/test/functional/html-id-href/html-id-href.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -50,15 +52,15 @@ describe('Functional html id href', function() {
const indexHtml = fs.readFileSync(testDirname + '/index.html').toString();
// should update path to external svgs
- should(indexHtml).containEql('xlink:href="local/sprite.svg#icon-undo"');
- should(indexHtml).containEql('href="local/sprite.svg#icon-redo"');
+ indexHtml.should.contain('xlink:href="local/sprite.svg#icon-undo"');
+ indexHtml.should.contain('href="local/sprite.svg#icon-redo"');
// should keep links to local svgs
- should(indexHtml).containEql('xlink:href="#codrops" class="codrops-1"');
- should(indexHtml).containEql('xlink:href="#codrops" class="codrops-2"');
- should(indexHtml).containEql('xlink:href="#codrops" class="codrops-3"');
+ indexHtml.should.contain('xlink:href="#codrops" class="codrops-1"');
+ indexHtml.should.contain('xlink:href="#codrops" class="codrops-2"');
+ indexHtml.should.contain('xlink:href="#codrops" class="codrops-3"');
- should(indexHtml).containEql('Go to top (this page)');
- should(indexHtml).containEql('Go to top (other page)');
+ indexHtml.should.contain('Go to top (this page)');
+ indexHtml.should.contain('Go to top (other page)');
});
});
});
diff --git a/test/functional/max-depth/max-depth.test.js b/test/functional/max-depth/max-depth.test.js
index 00e788da..8b30e8e9 100644
--- a/test/functional/max-depth/max-depth.test.js
+++ b/test/functional/max-depth/max-depth.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -150,12 +152,12 @@ describe('Functional: maxDepth and maxRecursiveDepth ', () => {
fs.existsSync(testDirname + '/pageC.html').should.be.eql(true);
const pageASaved = fs.readFileSync(testDirname + '/pageA.html').toString();
- pageASaved.should.containEql(' maxRecursiveDepth
+ pageBSaved.should.contain(' maxRecursiveDepth
});
});
diff --git a/test/functional/recursive/recursive.test.js b/test/functional/recursive/recursive.test.js
index 44cff191..b3eeedbe 100644
--- a/test/functional/recursive/recursive.test.js
+++ b/test/functional/recursive/recursive.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
diff --git a/test/functional/redirect/redirect.test.js b/test/functional/redirect/redirect.test.js
index a7e4f16f..4aef79cc 100644
--- a/test/functional/redirect/redirect.test.js
+++ b/test/functional/redirect/redirect.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -54,9 +56,9 @@ describe('Functional redirects', function() {
fs.existsSync(testDirname + '/true-page.html').should.be.eql(true);
// should update all urls to true-page.html
- fs.readFileSync(testDirname + '/index.html').toString().should.containEql('1');
- fs.readFileSync(testDirname + '/index.html').toString().should.containEql('2');
- fs.readFileSync(testDirname + '/index.html').toString().should.containEql('3');
+ fs.readFileSync(testDirname + '/index.html').toString().should.contain('1');
+ fs.readFileSync(testDirname + '/index.html').toString().should.contain('2');
+ fs.readFileSync(testDirname + '/index.html').toString().should.contain('3');
// true-page.html should have body from 1st response
fs.readFileSync(testDirname + '/true-page.html').toString().should.be.eql('true page 1');
@@ -98,11 +100,11 @@ describe('Functional redirects', function() {
style1.should.be.eql('about/style.css');
const index = fs.readFileSync(testDirname + '/index.html').toString();
- index.should.containEql('');
+ index.should.contain('');
const about = fs.readFileSync(testDirname + '/about.html').toString();
- about.should.containEql('');
- about.should.containEql('');
+ about.should.contain('');
+ about.should.contain('');
});
});
});
diff --git a/test/functional/request-concurrency/request-concurrency.test.js b/test/functional/request-concurrency/request-concurrency.test.js
index e258d977..7f0ff0dd 100644
--- a/test/functional/request-concurrency/request-concurrency.test.js
+++ b/test/functional/request-concurrency/request-concurrency.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -61,6 +63,6 @@ describe('Functional concurrent requests', function() {
});
it('should have maximum concurrent requests == requestConcurrency option', () => {
- maxConcurrentRequests.should.be.belowOrEqual(1);
+ maxConcurrentRequests.should.be.at.most(1);
});
});
diff --git a/test/functional/request-response-customizations/after-response-action.test.js b/test/functional/request-response-customizations/after-response-action.test.js
index bde7ca38..2aeb4511 100644
--- a/test/functional/request-response-customizations/after-response-action.test.js
+++ b/test/functional/request-response-customizations/after-response-action.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -54,12 +56,17 @@ describe('Functional: afterResponse action in plugin', function() {
};
return scrape(options).then(function(result) {
- should(result[0]).have.properties({ url: 'http://example.com/1.html', filename: '1.html', saved: true });
- should(result[1]).have.properties({ url: 'http://example.com/2.html', filename: '2.html', saved: false });
+ result[0].should.have.property('url', 'http://example.com/1.html');
+ result[0].should.have.property('filename', '1.html');
+ result[0].should.have.property('saved', true);
+
+ result[1].should.have.property('url', 'http://example.com/2.html');
+ result[1].should.have.property('filename', '2.html');
+ result[1].should.have.property('saved', false);
fs.existsSync(testDirname + '/1.html').should.be.eql(true);
const indexHtml = fs.readFileSync(testDirname + '/1.html').toString();
- should(indexHtml).containEql('content of 1.html');
+ indexHtml.should.contain('content of 1.html');
fs.existsSync(testDirname + '/2.html').should.be.eql(false);
});
diff --git a/test/functional/request-response-customizations/request.test.js b/test/functional/request-response-customizations/request.test.js
index f65926b7..1bee9dc1 100644
--- a/test/functional/request-response-customizations/request.test.js
+++ b/test/functional/request-response-customizations/request.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -34,7 +36,7 @@ describe('Functional: customize request options with plugin', function() {
return scrape(options).then(function() {
fs.existsSync(testDirname + '/index.html').should.be.eql(true);
const indexHtml = fs.readFileSync(testDirname + '/index.html').toString();
- should(indexHtml).containEql('response for url with query');
+ indexHtml.should.contain('response for url with query');
});
});
@@ -64,7 +66,7 @@ describe('Functional: customize request options with plugin', function() {
return scrape(options).then(function() {
fs.existsSync(testDirname + '/index.html').should.be.eql(true);
const indexHtml = fs.readFileSync(testDirname + '/index.html').toString();
- should(indexHtml).containEql('response for url with query');
+ indexHtml.should.contain('response for url with query');
});
});
});
diff --git a/test/functional/resource-saver/resource-saver.test.js b/test/functional/resource-saver/resource-saver.test.js
index 9ddea99a..3ef6fe0b 100644
--- a/test/functional/resource-saver/resource-saver.test.js
+++ b/test/functional/resource-saver/resource-saver.test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -47,8 +49,8 @@ describe('Functional: plugin for saving resources', () => {
};
return scrape(options).catch(function() {
- should(saveResourceStub.calledOnce).be.eql(true);
- should(saveResourceStub.args[0][0].resource.url).be.eql('http://example.com/');
+ saveResourceStub.calledOnce.should.be.eql(true);
+ saveResourceStub.args[0][0].resource.url.should.be.eql('http://example.com/');
});
});
@@ -63,8 +65,8 @@ describe('Functional: plugin for saving resources', () => {
};
return scrape(options).catch(function() {
- should(handleErrorStub.calledOnce).be.eql(true);
- should(handleErrorStub.args[0][0].error.message).be.eql('SCRAPER AWFUL ERROR');
+ handleErrorStub.calledOnce.should.be.eql(true);
+ handleErrorStub.args[0][0].error.message.should.be.eql('SCRAPER AWFUL ERROR');
});
});
diff --git a/test/functional/resource-without-ext/resource-without-ext.test.js b/test/functional/resource-without-ext/resource-without-ext.test.js
index be818082..afc07466 100644
--- a/test/functional/resource-without-ext/resource-without-ext.test.js
+++ b/test/functional/resource-without-ext/resource-without-ext.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
diff --git a/test/functional/update-missing-sources/update-missing-sources.test.js b/test/functional/update-missing-sources/update-missing-sources.test.js
index 1cacdcd2..a07c3cc9 100644
--- a/test/functional/update-missing-sources/update-missing-sources.test.js
+++ b/test/functional/update-missing-sources/update-missing-sources.test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import nock from 'nock';
import fs from 'fs-extra';
@@ -55,7 +57,7 @@ describe('Functional: update missing sources', () => {
const indexBody = fs.readFileSync(testDirname + '/index.html').toString();
- indexBody.should.containEql('
{
const indexBody = fs.readFileSync(testDirname + '/index.html').toString();
- indexBody.should.containEql('
{
const indexBody = fs.readFileSync(testDirname + '/index.html').toString();
- indexBody.should.containEql('
{
const link = fs.readFileSync(testDirname + '/link1.html').toString();
- link.should.containEql(' {
const index = fs.readFileSync(testDirname + '/index.html').toString();
- index.should.containEql(`.a { background: url('a.png') }`);
- index.should.containEql(`.b { background: url('http://example.com/b.png') }`);
- index.should.containEql(`.c { background: url('c.png') }`);
+ index.should.contain(`.a { background: url('a.png') }`);
+ index.should.contain(`.b { background: url('http://example.com/b.png') }`);
+ index.should.contain(`.c { background: url('c.png') }`);
});
});
});
-
diff --git a/test/unit/filename-generator/by-site-structure-test.js b/test/unit/filename-generator/by-site-structure-test.js
index 208a9eae..99f5e4ce 100644
--- a/test/unit/filename-generator/by-site-structure-test.js
+++ b/test/unit/filename-generator/by-site-structure-test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import sinon from 'sinon';
@@ -75,7 +77,7 @@ describe('FilenameGenerator: bySiteStructure', () => {
const resourceFilename = new Array(1000).fill('a').join('') + '.png';
const r = new Resource('http://example.com/' + resourceFilename);
const filename = bySiteStructureFilenameGenerator(r, options);
- should(filename.length).be.lessThan(255);
+ filename.length.should.be.lessThan(255);
});
it('should shorten filename if resource is html without ext and default name is too long', () => {
@@ -85,7 +87,7 @@ describe('FilenameGenerator: bySiteStructure', () => {
const filepath = bySiteStructureFilenameGenerator(r, { defaultFilename: defaultFilename });
const filenameParts = filepath.split('/');
const filename = filenameParts[filenameParts.length - 1];
- should(filename.length).be.lessThan(255);
+ filename.length.should.be.lessThan(255);
});
it('should return decoded filepath', () => {
diff --git a/test/unit/filename-generator/by-type-test.js b/test/unit/filename-generator/by-type-test.js
index 92b11f85..a8ed8d58 100644
--- a/test/unit/filename-generator/by-type-test.js
+++ b/test/unit/filename-generator/by-type-test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../../utils/assertions.js';
import sinon from 'sinon';
@@ -112,7 +114,7 @@ describe('FilenameGenerator: byType', () => {
const resourceFilename = new Array(1000).fill('a').join('') + '.png';
const r = new Resource('http://example.com/a.png', resourceFilename);
const filename = byTypeFilenameGenerator(r, {}, []);
- should(filename.length).be.lessThan(255);
+ filename.length.should.be.lessThan(255);
});
it('should return different short filename if first short filename is occupied', () => {
@@ -122,13 +124,13 @@ describe('FilenameGenerator: byType', () => {
const r2 = new Resource('http://second-example.com/a.png', resourceFilename);
const f1 = byTypeFilenameGenerator(r1, {}, []);
- should(f1.length).be.lessThan(255);
+ f1.length.should.be.lessThan(255);
const f2 = byTypeFilenameGenerator(r2, {}, [ f1 ]);
- should(f2.length).be.lessThan(255);
- should(f2).not.be.eql(f1);
+ f2.length.should.be.lessThan(255);
+ f2.should.not.be.eql(f1);
- should(f2).not.be.eql(f1);
+ f2.should.not.be.eql(f1);
});
it('should return decoded url-based filename', () => {
diff --git a/test/unit/plugins.test.js b/test/unit/plugins.test.js
index e69de29b..895286e0 100644
--- a/test/unit/plugins.test.js
+++ b/test/unit/plugins.test.js
@@ -0,0 +1,10 @@
+import * as chai from 'chai';
+chai.should();
+
+describe('Array', function() {
+ describe('#indexOf()', function() {
+ it('should return -1 when the value is not present', function() {
+ [1,2,3].indexOf(4).should.eql(-1);
+ });
+ });
+});
diff --git a/test/unit/request-test.js b/test/unit/request-test.js
index 80db6cc0..b2ee7256 100644
--- a/test/unit/request-test.js
+++ b/test/unit/request-test.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import sinon from 'sinon';
import nock from 'nock';
import request from '../../lib/request.js';
@@ -28,7 +29,7 @@ describe('request', () => {
};
return request.get({url, options}).then(() => {
- scope.isDone().should.be.eql(true);
+ scope.isDone().should.eql(true);
});
});
@@ -42,7 +43,7 @@ describe('request', () => {
.reply(200);
return request.get({url, referer}).then(() => {
- scope.isDone().should.be.eql(true);
+ scope.isDone().should.eql(true);
});
});
@@ -52,11 +53,11 @@ describe('request', () => {
let handlerStub = sinon.stub().resolves('');
return request.get({url, afterResponse: handlerStub}).then(() => {
- scope.isDone().should.be.eql(true);
- should(handlerStub.calledOnce).be.eql(true);
+ scope.isDone().should.eql(true);
+ handlerStub.calledOnce.should.eql(true);
const afterResponseArgs = handlerStub.getCall(0).args[0];
- should(afterResponseArgs.response.body).be.eql('TEST BODY');
- should(afterResponseArgs.response.headers).be.eql({});
+ afterResponseArgs.response.body.should.eql('TEST BODY');
+ afterResponseArgs.response.headers.should.eql({});
});
});
@@ -71,9 +72,9 @@ describe('request', () => {
});
return request.get({url, afterResponse: handlerStub}).then((data) => {
- should(data.body).be.eql('a');
- should(data.metadata).be.eql('b');
- should(data.encoding).be.eql('utf8');
+ data.body.should.eql('a');
+ data.metadata.should.eql('b');
+ data.encoding.should.eql('utf8');
});
});
@@ -85,9 +86,9 @@ describe('request', () => {
});
return request.get({url, afterResponse: handlerStub}).then((data) => {
- should(data.body).be.eql('a');
- should(data.metadata).be.eql(null);
- should(data.encoding).be.eql('binary');
+ data.body.should.eql('a');
+ (data.metadata === null).should.be.true;
+ data.encoding.should.eql('binary');
});
});
@@ -97,8 +98,8 @@ describe('request', () => {
const handlerStub = sinon.stub().resolves('test body');
return request.get({url, afterResponse: handlerStub}).then((data) => {
- should(data.body).be.eql('test body');
- should(data.metadata).be.eql(null);
+ data.body.should.eql('test body');
+ (data.metadata === null).should.be.true;
});
});
@@ -108,10 +109,10 @@ describe('request', () => {
const handlerStub = sinon.stub().resolves(['1', '2']);
return request.get({url, afterResponse: handlerStub}).then(() => {
- should(true).be.eql(false);
+ true.should.eql(false);
}).catch((e) => {
- should(e).be.instanceOf(Error);
- should(e.message).match(/Wrong response handler result. Expected string or object, but received/);
+ e.should.be.instanceOf(Error);
+ e.message.should.match(/Wrong response handler result. Expected string or object, but received/);
});
});
});
@@ -123,11 +124,13 @@ describe('request', () => {
});
return request.get({url}).then((data) => {
- data.should.have.properties(['url', 'body', 'mimeType']);
- data.url.should.be.eql('http://www.google.com/');
- data.body.should.be.eql('Hello from Google!');
- data.mimeType.should.be.eql('text/html');
- data.encoding.should.be.eql('utf8');
+ data.should.have.property('url');
+ data.should.have.property('body');
+ data.should.have.property('mimeType');
+ data.url.should.eql('http://www.google.com/');
+ data.body.should.eql('Hello from Google!');
+ data.mimeType.should.eql('text/html');
+ data.encoding.should.eql('utf8');
});
});
@@ -136,11 +139,11 @@ describe('request', () => {
nock(url).get('/').reply(200, 'Hello from Google!', {});
return request.get({url}).then((data) => {
- data.should.have.properties(['url', 'body', 'mimeType']);
- data.url.should.be.eql('http://www.google.com/');
- data.body.should.be.eql('Hello from Google!');
- data.encoding.should.be.eql('binary');
- should(data.mimeType).be.eql(null);
+ data.should.include.all.keys(['url', 'body', 'mimeType', 'encoding']);
+ data.url.should.eql('http://www.google.com/');
+ data.body.should.eql('Hello from Google!');
+ data.encoding.should.eql('binary');
+ data.should.have.property('mimeType', null);
});
});
});
@@ -149,7 +152,7 @@ describe('get encoding', () => {
it('should return binary by default', () => {
const result = request.getEncoding(null);
- should(result).be.eql('binary');
+ result.should.eql('binary');
});
it('should return binary when no content-type header supplies', () => {
@@ -157,7 +160,7 @@ describe('get encoding', () => {
headers: {}
});
- should(result).be.eql('binary');
+ result.should.eql('binary');
});
it('should return binary when content type header doesn\'t include utf-8', () => {
@@ -165,7 +168,7 @@ describe('get encoding', () => {
headers: {}
});
- should(result).be.eql('binary');
+ result.should.eql('binary');
});
it('should return binary when content type header doesn\'t include utf-8', () => {
@@ -175,7 +178,7 @@ describe('get encoding', () => {
}
});
- should(result).be.eql('binary');
+ result.should.eql('binary');
});
it('should return utf8 when content type includes utf-8', () => {
@@ -185,7 +188,7 @@ describe('get encoding', () => {
}
});
- should(result).be.eql('utf8');
+ result.should.eql('utf8');
});
it('should return utf8 response object includes it', () => {
@@ -193,7 +196,7 @@ describe('get encoding', () => {
encoding: 'utf8'
});
- should(result).be.eql('utf8');
+ result.should.eql('utf8');
});
});
@@ -203,10 +206,10 @@ describe('transformResult', () => {
request.transformResult([1,2,3]);
// We shouldn't get here.
- should(true).eql(false);
+ true.should.eql(false);
} catch (e) {
- should(e).be.instanceOf(Error);
- should(e.message).eql('Wrong response handler result. Expected string or object, but received array');
+ e.should.be.instanceOf(Error);
+ e.message.should.eql('Wrong response handler result. Expected string or object, but received array');
}
});
@@ -215,10 +218,10 @@ describe('transformResult', () => {
request.transformResult(new Error('Oh no'));
// We shouldn't get here.
- should(true).eql(false);
+ true.should.eql(false);
} catch (e) {
- should(e).be.instanceOf(Error);
- should(e.message).eql('Oh no');
+ e.should.be.instanceOf(Error);
+ e.message.should.eql('Oh no');
}
});
@@ -227,10 +230,10 @@ describe('transformResult', () => {
request.transformResult(true);
// We shouldn't get here.
- should(true).eql(false);
+ true.should.eql(false);
} catch (e) {
- should(e).be.instanceOf(Error);
- should(e.message).eql('Wrong response handler result. Expected string or object, but received boolean');
+ e.should.be.instanceOf(Error);
+ e.message.should.eql('Wrong response handler result. Expected string or object, but received boolean');
}
});
@@ -241,9 +244,9 @@ describe('transformResult', () => {
metadata: { foo: 'bar' }
});
- should(result).have.property('body', 'SOME BODY');
- should(result).have.property('encoding', 'utf8');
- should(result).have.property('metadata', { foo: 'bar' });
+ result.should.have.property('body', 'SOME BODY');
+ result.should.have.property('encoding', 'utf8');
+ result.should.have.property('metadata').that.eql({ foo: 'bar' });
});
it('should handle object with empty body string', () => {
@@ -252,9 +255,9 @@ describe('transformResult', () => {
encoding: 'utf8',
});
- should(result).have.property('body', '');
- should(result).have.property('encoding', 'utf8');
- should(result).have.property('metadata', null);
+ result.should.have.property('body', '');
+ result.should.have.property('encoding', 'utf8');
+ result.should.have.property('metadata', null);
});
it('should handle object with defaults and buffer body', () => {
@@ -262,28 +265,26 @@ describe('transformResult', () => {
body: Buffer.from('SOME BODY'),
});
- should(result).have.property('body', 'SOME BODY');
- should(result).have.property('encoding', 'binary');
- should(result).have.property('metadata', null);
+ result.should.have.property('body', 'SOME BODY');
+ result.should.have.property('encoding', 'binary');
+ result.should.have.property('metadata', null);
});
it('should handle raw string input', () => {
const result = request.transformResult('SOME BODY');
- should(result).have.property('body', 'SOME BODY');
- should(result).have.property('encoding', 'binary');
- should(result).have.property('metadata', null);
+ result.should.have.property('body', 'SOME BODY');
+ result.should.have.property('encoding', 'binary');
+ result.should.have.property('metadata', null);
});
it('should handle null input', () => {
const result = request.transformResult(null);
-
- should(result).eqls(null);
+ (result === null).should.be.true;
});
it('should handle undefined input', () => {
const result = request.transformResult(undefined);
-
- should(result).eqls(null);
+ (result === null).should.be.true;
});
});
diff --git a/test/unit/resource-handler/css.test.js b/test/unit/resource-handler/css.test.js
index 5dc4dbdd..4d34c01c 100644
--- a/test/unit/resource-handler/css.test.js
+++ b/test/unit/resource-handler/css.test.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import sinon from 'sinon';
import Resource from '../../../lib/resource.js';
import CssResourceHandler from '../../../lib/resource-handler/css/index.js';
@@ -12,8 +13,8 @@ describe('ResourceHandler: Css', () => {
const cssHandler = new CssResourceHandler({}, {downloadChildrenPaths});
return cssHandler.handle(originalResource).then((updatedResource) => {
- should(updatedResource).be.equal(originalResource);
- should(updatedResource.getText()).be.eql('updated text');
+ updatedResource.should.be.equal(originalResource);
+ updatedResource.getText().should.be.eql('updated text');
});
});
@@ -25,8 +26,8 @@ describe('ResourceHandler: Css', () => {
const cssHandler = new CssResourceHandler({}, {downloadChildrenPaths});
return cssHandler.handle(originalResource).then((updatedResource) => {
- should(updatedResource).be.equal(originalResource);
- should(updatedResource.getEncoding()).be.eql('utf8');
+ updatedResource.should.be.equal(originalResource);
+ updatedResource.getEncoding().should.be.eql('utf8');
});
});
});
diff --git a/test/unit/resource-handler/html.test.js b/test/unit/resource-handler/html.test.js
index 0882c4e0..316033ef 100644
--- a/test/unit/resource-handler/html.test.js
+++ b/test/unit/resource-handler/html.test.js
@@ -1,4 +1,7 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+const should = chai.should();
+
import sinon from 'sinon';
import Resource from '../../../lib/resource.js';
import HtmlHandler from '../../../lib/resource-handler/html/index.js';
@@ -84,7 +87,7 @@ describe('ResourceHandler: Html', () => {
return htmlHandler.handle(resource).then(() =>{
resource.getUrl().should.be.eql('http://some-other-domain.com/src');
- resource.getText().should.not.containEql(' {
return htmlHandler.handle(resource).then(() => {
resource.getUrl().should.be.eql('http://example.com/src');
- resource.getText().should.not.containEql(' {
return htmlHandler.handle(resource).then(() => {
resource.getUrl().should.be.eql('http://example.com');
- resource.getText().should.containEql('');
+ resource.getText().should.contain('');
});
});
});
@@ -143,7 +146,7 @@ describe('ResourceHandler: Html', () => {
resource.setText(html);
await htmlHandler.handle(resource);
- should(resource.getEncoding()).eql('utf8');
+ resource.getEncoding().should.eql('utf8');
});
});
@@ -161,7 +164,7 @@ describe('ResourceHandler: Html', () => {
resource.setText(html);
return htmlHandler.handle(resource).then(() => {
- resource.getText().should.containEql('Этот текст не должен быть преобразован в html entities');
+ resource.getText().should.contain('Этот текст не должен быть преобразован в html entities');
});
});
@@ -181,7 +184,7 @@ describe('ResourceHandler: Html', () => {
resource.setText(html);
return htmlHandler.handle(resource).then(() => {
- resource.getText().should.containEql('viewBox="0 0 100 100"');
+ resource.getText().should.contain('viewBox="0 0 100 100"');
});
});
@@ -278,14 +281,14 @@ describe('ResourceHandler: Html', () => {
resource.setText(html);
// before handle should contain both integrity checks
- resource.getText().should.containEql('integrity="sha256-gaWb8m2IHSkoZnT23u/necREOC//MiCFtQukVUYMyuU="');
- resource.getText().should.containEql('integrity="sha256-X+Q/xqnlEgxCczSjjpp2AUGGgqM5gcBzhRQ0p+EAUEk="');
+ resource.getText().should.contain('integrity="sha256-gaWb8m2IHSkoZnT23u/necREOC//MiCFtQukVUYMyuU="');
+ resource.getText().should.contain('integrity="sha256-X+Q/xqnlEgxCczSjjpp2AUGGgqM5gcBzhRQ0p+EAUEk="');
return htmlHandler.handle(resource).then(() => {
// after handle should contain integrity check for styles
// but not contain integrity check for script because it was loaded
- resource.getText().should.containEql('integrity="sha256-gaWb8m2IHSkoZnT23u/necREOC//MiCFtQukVUYMyuU="');
- resource.getText().should.not.containEql('integrity="sha256-X+Q/xqnlEgxCczSjjpp2AUGGgqM5gcBzhRQ0p+EAUEk="');
+ resource.getText().should.contain('integrity="sha256-gaWb8m2IHSkoZnT23u/necREOC//MiCFtQukVUYMyuU="');
+ resource.getText().should.not.contain('integrity="sha256-X+Q/xqnlEgxCczSjjpp2AUGGgqM5gcBzhRQ0p+EAUEk="');
});
});
@@ -310,6 +313,6 @@ describe('ResourceHandler: Html', () => {
await htmlHandler.handle(resource);
const text = resource.getText();
- should(text).containEql('style="width: 300px; height: 300px; background-image:url("./images/cat.jpg")"');
+ text.should.contain('style="width: 300px; height: 300px; background-image:url("./images/cat.jpg")"');
});
});
diff --git a/test/unit/resource-handler/index.test.js b/test/unit/resource-handler/index.test.js
index bc4612b6..a13b2a97 100644
--- a/test/unit/resource-handler/index.test.js
+++ b/test/unit/resource-handler/index.test.js
@@ -1,4 +1,7 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+const should = chai.should();
+
import sinon from 'sinon';
import path from 'path';
import Resource from '../../../lib/resource.js';
@@ -18,12 +21,12 @@ describe('ResourceHandler', function() {
sources: [{ selector: 'dummyTag', attr: 'dummyAttr' }]
};
const resHandler = new ResourceHandler(options);
- resHandler.options.should.containEql({
+ resHandler.options.should.deep.include({
prettifyUrls: 'a',
defaultFilename: 'test',
sources: [{ selector: 'dummyTag', attr: 'dummyAttr' }]
});
- resHandler.options.should.not.containEql({
+ resHandler.options.should.not.deep.include({
a: 1,
b: 2
});
@@ -71,7 +74,7 @@ describe('ResourceHandler', function() {
sinon.stub(r, 'getType').returns('other');
const specificResourceHandler = resourceHandler.getResourceHandler(r);
- should(specificResourceHandler).be.eql(null);
+ (specificResourceHandler === null).should.equal(true);
});
});
@@ -104,7 +107,7 @@ describe('ResourceHandler', function() {
const r = new Resource('http://example.com');
return resHandler.handleResource(r).then(function(returnedResource) {
- should(returnedResource).be.eql(r);
+ returnedResource.should.be.eql(r);
});
});
});
@@ -174,15 +177,15 @@ describe('ResourceHandler', function() {
const updateTextStub = pathContainer.updateText;
updateTextStub.calledOnce.should.be.eql(true);
updateTextStub.args[0][0].length.should.be.eql(3);
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://first.com/img/a.jpg',
newPath: 'local/a.jpg'
});
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://first.com/b.jpg',
newPath: 'local/b.jpg'
});
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://second.com/img/c.jpg',
newPath: 'local/c.jpg'
});
@@ -207,7 +210,7 @@ describe('ResourceHandler', function() {
const updateTextStub = pathContainer.updateText;
updateTextStub.calledOnce.should.be.eql(true);
updateTextStub.args[0][0].length.should.be.eql(1);
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://second.com/img/c.jpg',
newPath: 'local/c.jpg'
});
@@ -245,7 +248,7 @@ describe('ResourceHandler', function() {
const updateTextStub = pathContainer.updateText;
updateTextStub.calledOnce.should.be.eql(true);
updateTextStub.args[0][0].length.should.be.eql(1);
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://example.com/page1.html#hash',
newPath: 'local/page1.html#hash'
});
@@ -265,7 +268,7 @@ describe('ResourceHandler', function() {
const updateTextStub = pathContainer.updateText;
updateTextStub.calledOnce.should.be.eql(true);
updateTextStub.args[0][0].length.should.be.eql(1);
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://example.com/other-page/index.html',
newPath: 'other-page/index.html'
});
@@ -283,7 +286,7 @@ describe('ResourceHandler', function() {
const updateTextStub = pathContainer.updateText;
updateTextStub.calledOnce.should.be.eql(true);
updateTextStub.args[0][0].length.should.be.eql(1);
- updateTextStub.args[0][0].should.containEql({
+ updateTextStub.args[0][0].should.deep.include({
oldPath: 'http://example.com/other-page/index.html',
newPath: 'other-page/'
});
diff --git a/test/unit/resource-handler/path-containers/css-text.test.js b/test/unit/resource-handler/path-containers/css-text.test.js
index 5abb46be..a436d7ab 100644
--- a/test/unit/resource-handler/path-containers/css-text.test.js
+++ b/test/unit/resource-handler/path-containers/css-text.test.js
@@ -1,11 +1,12 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import CssText from '../../../../lib/resource-handler/path-containers/css-text.js';
describe('PathsContainer: CssText', function () {
describe('constructor', function() {
it('should set text to empty string if nothing passed', function() {
const cssText = new CssText();
- should(cssText.text).be.eql('');
+ cssText.text.should.eql('');
});
});
@@ -18,9 +19,9 @@ describe('PathsContainer: CssText', function () {
`;
const cssText = new CssText(text);
const resultPaths = cssText.getPaths();
- should(resultPaths).containEql('a.jpg');
- should(resultPaths).containEql('b.jpg');
- should(resultPaths).containEql('c.jpg');
+ resultPaths.should.contain('a.jpg');
+ resultPaths.should.contain('b.jpg');
+ resultPaths.should.contain('c.jpg');
});
it('should return paths from @import', function() {
@@ -30,8 +31,8 @@ describe('PathsContainer: CssText', function () {
`;
const cssText = new CssText(text);
const resultPaths = cssText.getPaths();
- should(resultPaths).containEql('style1.css');
- should(resultPaths).containEql('style2.css');
+ resultPaths.should.contain('style1.css');
+ resultPaths.should.contain('style2.css');
});
it('should return paths from @import url()', function() {
@@ -41,8 +42,8 @@ describe('PathsContainer: CssText', function () {
`;
const cssText = new CssText(text);
const resultPaths = cssText.getPaths();
- should(resultPaths).containEql('style1.css');
- should(resultPaths).containEql('style2.css');
+ resultPaths.should.contain('style1.css');
+ resultPaths.should.contain('style2.css');
});
});
@@ -64,7 +65,7 @@ describe('PathsContainer: CssText', function () {
.b {background: url('images/b.jpg')}
.c {background: url("images/c.jpg")}
`;
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
it('should update all duplicated paths in text', function() {
@@ -82,7 +83,7 @@ describe('PathsContainer: CssText', function () {
.b {background: url('newImg.jpg')}
.c {background: url("newImg.jpg")}
`;
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
it('should update only completely equal paths (should not update partially matched)', function() {
@@ -100,7 +101,7 @@ describe('PathsContainer: CssText', function () {
@import 'mystyle.css';
@import url('another-style.css');
`;
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
it('should update only specified paths', function() {
@@ -118,7 +119,7 @@ describe('PathsContainer: CssText', function () {
.b {background: url('b.jpg')}
.c {background: url("c.jpg")}
`;
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
});
});
diff --git a/test/unit/resource-handler/path-containers/html-common-tag.test.js b/test/unit/resource-handler/path-containers/html-common-tag.test.js
index a3c053d9..8c8e74c0 100644
--- a/test/unit/resource-handler/path-containers/html-common-tag.test.js
+++ b/test/unit/resource-handler/path-containers/html-common-tag.test.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import HtmlCommonTag from '../../../../lib/resource-handler/path-containers/html-common-tag.js';
describe('PathsContainer: HtmlCommonTag', function () {
@@ -6,7 +7,7 @@ describe('PathsContainer: HtmlCommonTag', function () {
describe('constructor', function() {
it('should set text to empty string if nothing passed', function() {
const htmlCommonTag = new HtmlCommonTag();
- should(htmlCommonTag.text).be.eql('');
+ htmlCommonTag.text.should.eql('');
});
});
@@ -15,35 +16,35 @@ describe('PathsContainer: HtmlCommonTag', function () {
const text = 'image.jpg';
const htmlCommonTag = new HtmlCommonTag(text);
const resultPaths = htmlCommonTag.getPaths();
- should(resultPaths).containEql('image.jpg');
+ resultPaths.should.contain('image.jpg');
});
it('should not return path with same-page id', function() {
const text = '#top';
const htmlCommonTag = new HtmlCommonTag(text);
const resultPaths = htmlCommonTag.getPaths();
- should(resultPaths).be.instanceOf(Array).and.have.length(0);
+ resultPaths.should.be.instanceOf(Array).and.have.length(0);
});
it('should return path with other-page id', function() {
const text = 'other.html#top';
const htmlCommonTag = new HtmlCommonTag(text);
const resultPaths = htmlCommonTag.getPaths();
- should(resultPaths).containEql('other.html#top');
+ resultPaths.should.contain('other.html#top');
});
it('should not return path is uri schema is not supported (mailto: skype: etc)', function() {
const text1 = 'mailto:sophie@example.com';
const resultPaths1 = new HtmlCommonTag(text1).getPaths();
- should(resultPaths1).be.instanceOf(Array).and.have.length(0);
+ resultPaths1.should.be.instanceOf(Array).and.have.length(0);
const text2 = 'skype:profile_name';
const resultPaths2 = new HtmlCommonTag(text2).getPaths();
- should(resultPaths2).be.instanceOf(Array).and.have.length(0);
+ resultPaths2.should.be.instanceOf(Array).and.have.length(0);
const text3 = 'javascript:alert("Hello World!");';
const resultPaths3 = new HtmlCommonTag(text3).getPaths();
- should(resultPaths3).be.instanceOf(Array).and.have.length(0);
+ resultPaths3.should.be.instanceOf(Array).and.have.length(0);
});
});
@@ -55,7 +56,7 @@ describe('PathsContainer: HtmlCommonTag', function () {
{ oldPath: 'image.jpg', newPath: 'images/image.jpg' }
]);
const expectedResultText = 'images/image.jpg';
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
});
});
diff --git a/test/unit/resource-handler/path-containers/html-img-srcset-tag.test.js b/test/unit/resource-handler/path-containers/html-img-srcset-tag.test.js
index 5b8ada0d..c492d8d4 100644
--- a/test/unit/resource-handler/path-containers/html-img-srcset-tag.test.js
+++ b/test/unit/resource-handler/path-containers/html-img-srcset-tag.test.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import HtmlImgSrcSetTag from '../../../../lib/resource-handler/path-containers/html-img-srcset-tag.js';
describe('PathsContainer: HtmlImgSrcSetTag', function () {
@@ -6,7 +7,7 @@ describe('PathsContainer: HtmlImgSrcSetTag', function () {
describe('constructor', function() {
it('should set text to empty string if nothing passed', function() {
const htmlImgSrcSetTag = new HtmlImgSrcSetTag();
- should(htmlImgSrcSetTag.text).be.eql('');
+ htmlImgSrcSetTag.text.should.eql('');
});
});
@@ -15,8 +16,8 @@ describe('PathsContainer: HtmlImgSrcSetTag', function () {
const text = 'image150.jpg 150w, image45.jpg 45w';
const htmlImgSrcSetTag = new HtmlImgSrcSetTag(text);
const resultPaths = htmlImgSrcSetTag.getPaths();
- should(resultPaths).containEql('image150.jpg');
- should(resultPaths).containEql('image45.jpg');
+ resultPaths.should.contain('image150.jpg');
+ resultPaths.should.contain('image45.jpg');
});
});
@@ -29,7 +30,7 @@ describe('PathsContainer: HtmlImgSrcSetTag', function () {
{ oldPath: 'image45.jpg', newPath: 'images/45.jpg' }
]);
const expectedResultText = 'images/150.jpg 150w, images/45.jpg 45w';
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
it('should update all duplicated paths in text', function() {
@@ -39,7 +40,7 @@ describe('PathsContainer: HtmlImgSrcSetTag', function () {
{ oldPath: 'image.jpg', newPath: 'newImage.jpg' }
]);
const expectedResultText = 'newImage.jpg 150w, newImage.jpg 45w';
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
it('should update only specified paths', function () {
@@ -49,7 +50,7 @@ describe('PathsContainer: HtmlImgSrcSetTag', function () {
{ oldPath: 'image150.jpg', newPath: 'images/150.jpg' }
]);
const expectedResultText = 'images/150.jpg 150w, image45.jpg 45w';
- should(actualResultText).be.eql(expectedResultText);
+ actualResultText.should.eql(expectedResultText);
});
});
});
diff --git a/test/unit/resource-test.js b/test/unit/resource-test.js
index 8f0d14e3..545b0f71 100644
--- a/test/unit/resource-test.js
+++ b/test/unit/resource-test.js
@@ -1,4 +1,6 @@
-import 'should';
+import * as chai from 'chai';
+chai.should();
+import '../../test/utils/assertions.js';
import Resource from '../../lib/resource.js';
describe('Resource', function() {
@@ -12,7 +14,7 @@ describe('Resource', function() {
it('should set correct url and filename', function() {
const parent = new Resource('http://example.com');
const child = parent.createChild('http://google.com', 'google.html');
- child.getUrl().should.be.eql('http://google.com');
+ child.getUrl().should.eql('http://google.com');
child.getFilename().should.equalFileSystemPath('google.html');
});
@@ -25,10 +27,10 @@ describe('Resource', function() {
it('should set depth', function() {
const parent = new Resource('http://example.com');
const child = parent.createChild('http://google.com');
- child.depth.should.be.eql(1);
+ child.depth.should.eql(1);
const childOfChild = child.createChild('http://google.com.ua');
- childOfChild.depth.should.be.eql(2);
+ childOfChild.depth.should.eql(2);
});
});
});
diff --git a/test/unit/scraper-init-test.js b/test/unit/scraper-init-test.js
index 080c5976..35030887 100644
--- a/test/unit/scraper-init-test.js
+++ b/test/unit/scraper-init-test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+
import '../utils/assertions.js';
import Scraper from '../../lib/scraper.js';
import Resource from '../../lib/resource.js';
@@ -62,8 +64,8 @@ describe('Scraper initialization', function () {
});
s.options.sources.should.have.length(2);
- s.options.sources.should.containEql({ selector: 'img', attr: 'src' });
- s.options.sources.should.containEql({ selector: 'a', attr: 'href' });
+ s.options.sources.should.deep.include({ selector: 'img', attr: 'src' });
+ s.options.sources.should.deep.include({ selector: 'a', attr: 'href' });
});
});
@@ -108,7 +110,7 @@ describe('Scraper initialization', function () {
subdirectories: null
});
- should(s.options.subdirectories).eql(null);
+ (s.options.subdirectories === null).should.be.true;
});
});
@@ -119,7 +121,7 @@ describe('Scraper initialization', function () {
directory: testDirname
});
- s.options.request.should.containEql({
+ s.options.request.should.deep.include({
throwHttpErrors: false,
responseType: 'buffer',
decompress: true,
@@ -141,7 +143,7 @@ describe('Scraper initialization', function () {
}
});
- s.options.request.should.eql({
+ s.options.request.should.deep.include({
throwHttpErrors: true,
responseType: 'buffer',
decompress: true,
@@ -163,7 +165,7 @@ describe('Scraper initialization', function () {
}
});
- s.options.request.should.containEql({
+ s.options.request.should.deep.include({
encoding: 'another encoding',
decompress: true,
https: {
@@ -182,8 +184,8 @@ describe('Scraper initialization', function () {
};
const s = new Scraper(options);
- should(typeof s.resourceHandler.requestResource).be.eql('function');
- should(typeof s.resourceHandler.getReference).be.eql('function');
+ s.resourceHandler.requestResource.should.be.a('function');
+ s.resourceHandler.getReference.should.be.a('function');
});
});
@@ -194,8 +196,8 @@ describe('Scraper initialization', function () {
directory: testDirname
});
- s.options.urls.should.be.an.instanceOf(Array).and.have.length(1);
- s.options.urls[0].should.be.eql({url: 'http://not-array-url.com', filename: 'index.html'});
+ s.options.urls.should.be.an('array').with.lengthOf(1);
+ s.options.urls[0].should.eql({url: 'http://not-array-url.com', filename: 'index.html'});
});
});
@@ -210,13 +212,13 @@ describe('Scraper initialization', function () {
directory: testDirname
});
- s.resources.should.be.an.instanceOf(Array).and.have.length(3);
- s.resources[0].should.be.an.instanceOf(Resource);
- s.resources[0].url.should.be.eql('http://first-url.com');
- s.resources[1].should.be.an.instanceOf(Resource);
- s.resources[1].url.should.be.eql('http://second-url.com');
- s.resources[2].should.be.an.instanceOf(Resource);
- s.resources[2].url.should.be.eql('http://third-url.com');
+ s.resources.should.be.an('array').with.lengthOf(3);
+ s.resources[0].should.be.instanceOf(Resource);
+ s.resources[0].url.should.eql('http://first-url.com');
+ s.resources[1].should.be.instanceOf(Resource);
+ s.resources[1].url.should.eql('http://second-url.com');
+ s.resources[2].should.be.instanceOf(Resource);
+ s.resources[2].url.should.eql('http://third-url.com');
});
it('should use urls filename', function() {
@@ -244,17 +246,17 @@ describe('Scraper initialization', function () {
directory: testDirname
});
- s.actions.beforeStart.length.should.be.eql(2);
- s.actions.afterFinish.length.should.be.eql(0);
- s.actions.error.length.should.be.eql(1);
+ s.actions.beforeStart.length.should.eql(2);
+ s.actions.afterFinish.length.should.eql(0);
+ s.actions.error.length.should.eql(1);
- s.actions.beforeRequest.length.should.be.eql(0);
- s.actions.afterResponse.length.should.be.eql(0);
- s.actions.onResourceSaved.length.should.be.eql(0);
- s.actions.onResourceError.length.should.be.eql(0);
+ s.actions.beforeRequest.length.should.eql(0);
+ s.actions.afterResponse.length.should.eql(0);
+ s.actions.onResourceSaved.length.should.eql(0);
+ s.actions.onResourceError.length.should.eql(0);
- s.actions.saveResource.length.should.be.eql(1);
- s.actions.generateFilename.length.should.be.eql(1);
+ s.actions.saveResource.length.should.eql(1);
+ s.actions.generateFilename.length.should.eql(1);
});
it('should add actions when plugin set', () => {
@@ -273,17 +275,17 @@ describe('Scraper initialization', function () {
]
});
- s.actions.beforeStart.length.should.be.eql(3);
- s.actions.afterFinish.length.should.be.eql(1);
- s.actions.error.length.should.be.eql(1);
+ s.actions.beforeStart.length.should.eql(3);
+ s.actions.afterFinish.length.should.eql(1);
+ s.actions.error.length.should.eql(1);
- s.actions.beforeRequest.length.should.be.eql(0);
- s.actions.afterResponse.length.should.be.eql(0);
- s.actions.onResourceSaved.length.should.be.eql(0);
- s.actions.onResourceError.length.should.be.eql(0);
+ s.actions.beforeRequest.length.should.eql(0);
+ s.actions.afterResponse.length.should.eql(0);
+ s.actions.onResourceSaved.length.should.eql(0);
+ s.actions.onResourceError.length.should.eql(0);
- s.actions.saveResource.length.should.be.eql(1);
- s.actions.generateFilename.length.should.be.eql(1);
+ s.actions.saveResource.length.should.eql(1);
+ s.actions.generateFilename.length.should.eql(1);
});
it('should add actions when multiple plugins set', () => {
@@ -311,18 +313,18 @@ describe('Scraper initialization', function () {
]
});
- s.actions.beforeStart.length.should.be.eql(4);
- s.actions.afterFinish.length.should.be.eql(1);
- s.actions.error.length.should.be.eql(1);
+ s.actions.beforeStart.length.should.eql(4);
+ s.actions.afterFinish.length.should.eql(1);
+ s.actions.error.length.should.eql(1);
- s.actions.beforeRequest.length.should.be.eql(1);
- s.actions.afterResponse.length.should.be.eql(0);
+ s.actions.beforeRequest.length.should.eql(1);
+ s.actions.afterResponse.length.should.eql(0);
- s.actions.onResourceSaved.length.should.be.eql(1);
- s.actions.onResourceError.length.should.be.eql(0);
+ s.actions.onResourceSaved.length.should.eql(1);
+ s.actions.onResourceError.length.should.eql(0);
- s.actions.saveResource.length.should.be.eql(1);
- s.actions.generateFilename.length.should.be.eql(1);
+ s.actions.saveResource.length.should.eql(1);
+ s.actions.generateFilename.length.should.eql(1);
});
it('should throw error if plugin has wrong action', () => {
@@ -341,10 +343,10 @@ describe('Scraper initialization', function () {
new MyPlugin()
]
});
- should(false).eql(true);
+ false.should.be.true;
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.message).be.eql('Unknown action "wrongAction"');
+ err.should.be.instanceOf(Error);
+ err.message.should.eql('Unknown action "wrongAction"');
}
});
});
@@ -356,8 +358,8 @@ describe('Scraper initialization', function () {
directory: testDirname
});
- s.actions.saveResource.length.should.be.eql(1);
- s.actions.generateFilename.length.should.be.eql(1);
+ s.actions.saveResource.length.should.eql(1);
+ s.actions.generateFilename.length.should.eql(1);
});
});
});
diff --git a/test/unit/scraper-test.js b/test/unit/scraper-test.js
index e85f3602..0b195c2d 100644
--- a/test/unit/scraper-test.js
+++ b/test/unit/scraper-test.js
@@ -1,4 +1,5 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
import sinon from 'sinon';
import nock from 'nock';
import fs from 'fs-extra';
@@ -70,7 +71,7 @@ describe('Scraper', () => {
const r = new Resource('http://example.com/a.png', 'a.png');
r.setText('some text');
- return s.saveResource(r).then(() => should(true).eql(false)).catch(() => {
+ return s.saveResource(r).then(() => false.should.be.true).catch(() => {
s.handleError.calledOnce.should.be.eql(true);
s.handleError.calledWith(dummyError).should.be.eql(true);
});
@@ -103,8 +104,9 @@ describe('Scraper', () => {
rr.should.be.eql(r);
rr.getUrl().should.be.eql('http://example.com/a.png');
- rr.getFilename().should.be.not.empty();
- rr.getText().should.be.not.empty();
+ rr.getFilename().should.not.be.empty;
+ rr.getText().should.be.a.string;
+ rr.getText().should.not.be.empty;
});
it('should return null if the urlFilter returns false', async () =>{
@@ -118,7 +120,7 @@ describe('Scraper', () => {
r.getDepth = sinon.stub().returns(2);
const rr = await s.requestResource(r);
- should.equal(rr, null);
+ (rr === null).should.be.true;
});
it('should ignore urlFilter if resource depth=0', async () => {
@@ -138,8 +140,9 @@ describe('Scraper', () => {
rr.should.be.eql(r);
rr.getUrl().should.be.eql('http://example.com');
- rr.getFilename().should.be.not.empty();
- rr.getText().should.be.not.empty();
+ rr.getFilename().should.not.be.empty;
+ rr.getText().should.be.a.string;
+ rr.getText().should.not.be.empty;
});
});
@@ -160,8 +163,9 @@ describe('Scraper', () => {
rr.should.be.eql(r);
rr.getUrl().should.be.eql('http://example.com/a.png');
- rr.getFilename().should.be.not.empty();
- rr.getText().should.be.not.empty();
+ rr.getFilename().should.not.be.empty;
+ rr.getText().should.be.a.string;
+ rr.getText().should.not.be.empty;
});
it('should request the resource if maxDepth is set and resource depth is less than maxDept', async () =>{
@@ -181,8 +185,9 @@ describe('Scraper', () => {
rr.should.be.eql(r);
rr.getUrl().should.be.eql('http://example.com/a.png');
- rr.getFilename().should.be.not.empty();
- rr.getText().should.be.not.empty();
+ rr.getFilename().should.not.be.empty;
+ rr.getText().should.be.a.string;
+ rr.getText().should.not.be.empty;
});
it('should request the resource if maxDepth is set and resource depth is equal to maxDept', async () =>{
@@ -201,8 +206,9 @@ describe('Scraper', () => {
const rr = await s.requestResource(r);
rr.should.be.eql(r);
rr.getUrl().should.be.eql('http://example.com/a.png');
- rr.getFilename().should.be.not.empty();
- rr.getText().should.be.not.empty();
+ rr.getFilename().should.not.be.empty;
+ rr.getText().should.be.a.string;
+ rr.getText().should.not.be.empty;
});
it('should return null if maxDepth is set and resource depth is greater than maxDepth', async () =>{
@@ -216,7 +222,7 @@ describe('Scraper', () => {
r.getDepth = sinon.stub().returns(4);
const rr = await s.requestResource(r);
- should.equal(rr, null);
+ (rr === null).should.be.true;
});
});
@@ -233,7 +239,7 @@ describe('Scraper', () => {
try {
await s.requestResource(r);
- should(true).eql(false);
+ false.should.be.true;
} catch (err) {
s.handleError.calledOnce.should.be.eql(true);
}
@@ -269,12 +275,12 @@ describe('Scraper', () => {
const r = new Resource('http://example.com');
await s.requestResource(r);
- should(r.getText()).be.eql('test body');
- should(r.getUrl()).be.eql('http://example.com');
- should(r.getType()).be.eql('html');
- should(r.getFilename()).be.eql('generated-filename');
- should(r.getEncoding()).be.eql('utf8');
- should(r.metadata).be.eql(metadata);
+ r.getText().should.be.eql('test body');
+ r.getUrl().should.be.eql('http://example.com');
+ r.getType().should.be.eql('html');
+ r.getFilename().should.be.eql('generated-filename');
+ r.getEncoding().should.be.eql('utf8');
+ r.metadata.should.be.eql(metadata);
});
});
@@ -286,7 +292,7 @@ describe('Scraper', () => {
ignoreErrors: true
});
return s.handleError(new Error('Request failed!')).then(() => {
- should(true).be.eql(true);
+ true.should.be.true;
});
});
@@ -297,9 +303,9 @@ describe('Scraper', () => {
ignoreErrors: false
});
return s.handleError(new Error('Request failed!')).then(() => {
- should(false).be.eql(true);
+ false.should.be.true;
}).catch(() => {
- should(true).be.eql(true);
+ true.should.be.true;
});
});
});
@@ -331,7 +337,7 @@ describe('Scraper', () => {
sinon.stub(s, 'load').rejects(new Error('Awful error'));
return s.scrape().then(() => {
- should(true).be.eql(false);
+ false.should.be.true();
}).catch((err) => {
err.should.be.instanceOf(Error);
err.message.should.be.eql('Awful error');
@@ -353,8 +359,10 @@ describe('Scraper', () => {
return s.scrape().then((res) => {
res.should.be.instanceOf(Array);
res.should.have.length(2);
- res[0].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
- res[1].should.be.instanceOf(Resource).and.have.properties(['url', 'filename', 'children']);
+ res[0].should.be.instanceOf(Resource);
+ res[0].should.include.keys(['url', 'filename', 'children']);
+ res[1].should.be.instanceOf(Resource);
+ res[1].should.include.keys(['url', 'filename', 'children']);
});
});
});
@@ -376,16 +384,16 @@ describe('Scraper', () => {
const result = await s.runActions('beforeStart', {options: s.options});
- should(beforeStartActionStub1.callCount).eql(1);
- should(beforeStartActionStub1.args[0][0]).be.eql({options: s.options});
+ beforeStartActionStub1.callCount.should.be.eql(1);
+ beforeStartActionStub1.args[0][0].should.be.eql({options: s.options});
- should(beforeStartActionStub2.callCount).eql(1);
- should(beforeStartActionStub2.args[0][0]).be.eql({options: s.options, result: 1});
+ beforeStartActionStub2.callCount.should.be.eql(1);
+ beforeStartActionStub2.args[0][0].should.be.eql({options: s.options, result: 1});
- should(beforeStartActionStub3.callCount).eql(1);
- should(beforeStartActionStub3.args[0][0]).be.eql({options: s.options, result: 2});
+ beforeStartActionStub3.callCount.should.be.eql(1);
+ beforeStartActionStub3.args[0][0].should.be.eql({options: s.options, result: 2});
- should(result).eql({result: 3});
+ result.should.be.eql({result: 3});
});
it('should fail if one of actions fails', async () => {
@@ -404,17 +412,17 @@ describe('Scraper', () => {
try {
await s.runActions('beforeStart', {options: s.options});
- should(false).eql(true);
+ false.should.be.true();
} catch (err) {
- should(beforeStartActionStub1.callCount).eql(1);
- should(beforeStartActionStub1.args[0][0]).be.eql({options: s.options});
+ beforeStartActionStub1.callCount.should.be.eql(1);
+ beforeStartActionStub1.args[0][0].should.be.eql({options: s.options});
- should(beforeStartActionStub2.callCount).eql(1);
- should(beforeStartActionStub2.args[0][0]).be.eql({options: s.options, result: 1});
+ beforeStartActionStub2.callCount.should.be.eql(1);
+ beforeStartActionStub2.args[0][0].should.be.eql({options: s.options, result: 1});
- should(beforeStartActionStub3.callCount).eql(0);
+ beforeStartActionStub3.callCount.should.be.eql(0);
- should(err.message).eql('Error from beforeStart 2');
+ err.message.should.be.eql('Error from beforeStart 2');
}
});
@@ -426,25 +434,25 @@ describe('Scraper', () => {
const result = await s.runActions('beforeRequest', {requestOptions: {a: 1}});
- should(result).eql({requestOptions: {a: 1}});
+ result.should.be.eql({requestOptions: {a: 1}});
});
});
describe('export defaults', () => {
it('should export defaults', () => {
- should(defaultOptions).be.have.properties([
- 'subdirectories', 'sources', 'defaultFilename', 'prettifyUrls',
- 'request', 'requestConcurrency', 'ignoreErrors', 'urlFilter',
- 'maxDepth', 'maxRecursiveDepth'
+ defaultOptions.should.include.keys([
+ 'defaultFilename', 'prettifyUrls', 'sources', 'subdirectories',
+ 'request', 'requestConcurrency', 'urlFilter', 'recursive',
+ 'maxRecursiveDepth', 'maxDepth', 'ignoreErrors'
]);
});
});
describe('export plugins', () => {
it('should export default plugins', () => {
- should(plugins.SaveResourceToFileSystemPlugin).be.instanceOf(Function);
- should(plugins.GenerateFilenameByTypePlugin).be.instanceOf(Function);
- should(plugins.GenerateFilenameBySiteStructurePlugin).be.instanceOf(Function);
+ plugins.SaveResourceToFileSystemPlugin.should.be.instanceOf(Function);
+ plugins.GenerateFilenameByTypePlugin.should.be.instanceOf(Function);
+ plugins.GenerateFilenameBySiteStructurePlugin.should.be.instanceOf(Function);
});
});
@@ -458,7 +466,7 @@ describe('Scraper', () => {
await s.scrape();
- should(fs.existsSync(testDirname)).be.eql(true);
+ fs.existsSync(testDirname).should.be.eql(true);
});
it('should save resource to FS', async () => {
@@ -471,8 +479,8 @@ describe('Scraper', () => {
await s.scrape();
const filename = path.join(testDirname, 'index.html');
- should(fs.existsSync(filename)).be.eql(true);
- should(fs.readFileSync(filename).toString()).be.eql('some text');
+ fs.existsSync(filename).should.be.eql(true);
+ fs.readFileSync(filename).toString().should.be.eql('some text');
});
it('should remove directory on error', async () => {
@@ -488,11 +496,11 @@ describe('Scraper', () => {
try {
await s.scrape();
- should(true).be.eql(false);
+ false.should.be.true();
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.code).be.eql('ERR_NON_2XX_3XX_RESPONSE');
- should(fs.existsSync(testDirname)).be.eql(false);
+ err.should.be.instanceOf(Error);
+ err.code.should.be.eql('ERR_NON_2XX_3XX_RESPONSE');
+ fs.existsSync(testDirname).should.be.eql(false);
}
});
@@ -502,10 +510,10 @@ describe('Scraper', () => {
urls: 'http://example.com',
});
await s.scrape();
- should(false).eql(true);
+ false.should.be.true();
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.message).containEql('Incorrect directory');
+ err.should.be.instanceOf(Error);
+ err.message.should.include('Incorrect directory');
}
});
@@ -516,10 +524,10 @@ describe('Scraper', () => {
directory: ''
});
await s.scrape();
- should(false).eql(true);
+ false.should.be.true();
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.message).containEql('Incorrect directory');
+ err.should.be.instanceOf(Error);
+ err.message.should.include('Incorrect directory');
}
});
@@ -530,10 +538,10 @@ describe('Scraper', () => {
directory: {}
});
await s.scrape();
- should(false).eql(true);
+ false.should.be.true();
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.message).containEql('Incorrect directory');
+ err.should.be.instanceOf(Error);
+ err.message.should.include('Incorrect directory');
}
});
@@ -545,10 +553,10 @@ describe('Scraper', () => {
directory: testDirname
});
await s.scrape();
- should(false).eql(true);
+ false.should.be.true();
} catch (err) {
- should(err).be.instanceOf(Error);
- should(err.message).match(/Directory (.*?) exists/);
+ err.should.be.instanceOf(Error);
+ err.message.should.match(/Directory (.*?) exists/);
}
});
});
@@ -567,11 +575,11 @@ describe('Scraper', () => {
await s.scrape();
- should(s.options.plugins[0]).be.instanceOf(plugins.GenerateFilenameByTypePlugin);
+ s.options.plugins[0].should.be.instanceOf(plugins.GenerateFilenameByTypePlugin);
const filename = path.join(testDirname, 'index.html');
- should(fs.existsSync(filename)).be.eql(true);
- should(fs.readFileSync(filename).toString()).be.eql('some text');
+ fs.existsSync(filename).should.be.eql(true);
+ fs.readFileSync(filename).toString().should.be.eql('some text');
});
it('should use bySiteStructure plugin if filenameGenerator option is set', async () => {
@@ -584,11 +592,11 @@ describe('Scraper', () => {
await s.scrape();
- should(s.options.plugins[0]).be.instanceOf(plugins.GenerateFilenameBySiteStructurePlugin);
+ s.options.plugins[0].should.be.instanceOf(plugins.GenerateFilenameBySiteStructurePlugin);
const filename = path.join(testDirname, 'example.com/index.html');
- should(fs.existsSync(filename)).be.eql(true);
- should(fs.readFileSync(filename).toString()).be.eql('some text');
+ fs.existsSync(filename).should.be.eql(true);
+ fs.readFileSync(filename).toString().should.be.eql('some text');
});
it('should ignore filenameGenerator option if function passed', async () => {
@@ -598,7 +606,7 @@ describe('Scraper', () => {
filenameGenerator: () => {}
});
- should(s.options.plugins.length).be.eql(0);
+ s.options.plugins.length.should.be.eql(0);
});
});
});
diff --git a/test/unit/utils/normalized-url-map-test.js b/test/unit/utils/normalized-url-map-test.js
index 80544ae5..a81cc66f 100644
--- a/test/unit/utils/normalized-url-map-test.js
+++ b/test/unit/utils/normalized-url-map-test.js
@@ -1,30 +1,31 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+const should = chai.should();
import NormalizedUrlMap from '../../../lib/utils/normalized-url-map.js';
describe('NormalizedUrlMap', function () {
describe('#get', function() {
- it('should find nothing if no value with same url was set',function() {
+ it('should find nothing if no value with same url was set', function () {
const map = new NormalizedUrlMap();
- should(map.get('http://first-resource.com')).be.eql(undefined);
+ should.not.exist(map.get('http://first-resource.com'));
});
- it('should return value with same url', function() {
+ it('should return value with same url', function () {
const map = new NormalizedUrlMap();
const a = { test: 'hello' };
map.set('http://first-resource.com', a);
- should(map.get('http://first-resource.com')).be.eql(a);
- should(map.get('http://first-resource.com/')).be.eql(a);
- should(map.get('http://first-resource.com?')).be.eql(a);
-
+ map.get('http://first-resource.com').should.eql(a);
+ map.get('http://first-resource.com/').should.eql(a);
+ map.get('http://first-resource.com?').should.eql(a);
const b = { foo: 'bar' };
map.set('http://example.com?a=1&b=2&c=3', b);
- should(map.get('http://example.com/?a=1&c=3&b=2')).be.eql(b);
- should(map.get('http://example.com/?c=3&b=2&a=1&')).be.eql(b);
- should(map.get('http://example.com/?c=3&a=1&b=2')).be.eql(b);
- should(map.get('http://example.com/?b=2&a=1&c=3')).be.eql(b);
+ map.get('http://example.com/?a=1&c=3&b=2').should.eql(b);
+ map.get('http://example.com/?c=3&b=2&a=1&').should.eql(b);
+ map.get('http://example.com/?c=3&a=1&b=2').should.eql(b);
+ map.get('http://example.com/?b=2&a=1&c=3').should.eql(b);
});
});
});
diff --git a/test/unit/utils/utils-test.js b/test/unit/utils/utils-test.js
index 5a9a6ad3..62258aab 100644
--- a/test/unit/utils/utils-test.js
+++ b/test/unit/utils/utils-test.js
@@ -1,4 +1,6 @@
-import should from 'should';
+import * as chai from 'chai';
+chai.should();
+const should = chai.should();
import {
isUrl, getUrl, getUnixPath, getFilenameFromUrl,
getFilepathFromUrl, getHashFromUrl, getRelativePath,
@@ -10,43 +12,43 @@ import {
describe('Utils', function () {
describe('#isUrl(url)', function () {
it('should return true if url starts with "http[s]://"', function () {
- isUrl('http://google.com').should.be.true();
- isUrl('https://github.com').should.be.true();
+ isUrl('http://google.com').should.be.true;
+ isUrl('https://github.com').should.be.true;
});
it('should return true if url starts with "//"', function () {
- isUrl('//www.youtube.com').should.be.true();
+ isUrl('//www.youtube.com').should.be.true;
});
it('should return false if url starts neither with "http[s]://" nor "//"', function () {
- isUrl('http//www.youtube.com').should.be.false();
- isUrl('http:/www.youtube.com').should.be.false();
- isUrl('htt://www.youtube.com').should.be.false();
- isUrl('://www.youtube.com').should.be.false();
- isUrl('www.youtube.com').should.be.false();
+ isUrl('http//www.youtube.com').should.be.false;
+ isUrl('http:/www.youtube.com').should.be.false;
+ isUrl('htt://www.youtube.com').should.be.false;
+ isUrl('://www.youtube.com').should.be.false;
+ isUrl('www.youtube.com').should.be.false;
});
});
describe('#getUrl(url, path)', function () {
it('should return url + path if path is not url', function () {
- getUrl('http://google.com', '/path').should.be.equal('http://google.com/path');
- getUrl('http://google.com/qwe/qwe/qwe', '/path').should.be.equal('http://google.com/path');
- getUrl('http://google.com?kjrdrgek=dmskl', '/path').should.be.equal('http://google.com/path');
+ getUrl('http://google.com', '/path').should.equal('http://google.com/path');
+ getUrl('http://google.com/qwe/qwe/qwe', '/path').should.equal('http://google.com/path');
+ getUrl('http://google.com?kjrdrgek=dmskl', '/path').should.equal('http://google.com/path');
});
it('should return path if it is url', function () {
- getUrl('http://google.com', 'http://my.site.com/').should.be.equal('http://my.site.com/');
- getUrl('http://google.com/qwe/qwe/qwe', '//my.site.com').should.be.equal('http://my.site.com/');
+ getUrl('http://google.com', 'http://my.site.com/').should.equal('http://my.site.com/');
+ getUrl('http://google.com/qwe/qwe/qwe', '//my.site.com').should.equal('http://my.site.com/');
});
it('should use the protocol from the url, if the path is a protocol-less url', function () {
- getUrl('http://my.site.com', '//cdn.com/library.js').should.be.equal('http://cdn.com/library.js');
- getUrl('https://my.site.com', '//cdn.com/library.js').should.be.equal('https://cdn.com/library.js');
+ getUrl('http://my.site.com', '//cdn.com/library.js').should.equal('http://cdn.com/library.js');
+ getUrl('https://my.site.com', '//cdn.com/library.js').should.equal('https://cdn.com/library.js');
});
});
describe('#getUnixPath(path)', function () {
it('should convert to unix format for windows', function () {
- getUnixPath('D:\\Projects\\node-website-scraper').should.be.equal('D:/Projects/node-website-scraper');
+ getUnixPath('D:\\Projects\\node-website-scraper').should.equal('D:/Projects/node-website-scraper');
});
it('should return unconverted path for unix', function () {
- getUnixPath('/home/sophia/projects/node-website-scraper').should.be.equal('/home/sophia/projects/node-website-scraper');
+ getUnixPath('/home/sophia/projects/node-website-scraper').should.equal('/home/sophia/projects/node-website-scraper');
});
});
@@ -102,156 +104,155 @@ describe('Utils', function () {
describe('#getHashFromUrl', function () {
it('should return hash from url', function () {
- getHashFromUrl('#').should.be.equal('#');
- getHashFromUrl('#hash').should.be.equal('#hash');
- getHashFromUrl('page.html#hash').should.be.equal('#hash');
- getHashFromUrl('http://example.com/page.html#hash').should.be.equal('#hash');
+ getHashFromUrl('#').should.equal('#');
+ getHashFromUrl('#hash').should.equal('#hash');
+ getHashFromUrl('page.html#hash').should.equal('#hash');
+ getHashFromUrl('http://example.com/page.html#hash').should.equal('#hash');
});
it('should return empty string if url doesn\'t contain hash', function () {
- getHashFromUrl('').should.be.equal('');
- getHashFromUrl('page.html?a=b').should.be.equal('');
- getHashFromUrl('http://example.com/page.html?a=b').should.be.equal('');
+ getHashFromUrl('').should.equal('');
+ getHashFromUrl('page.html?a=b').should.equal('');
+ getHashFromUrl('http://example.com/page.html?a=b').should.equal('');
});
});
describe('#getRelativePath', function () {
it('should return relative path', function () {
- getRelativePath('css/1.css', 'img/1.png').should.be.equal('../img/1.png');
- getRelativePath('index.html', 'img/1.png').should.be.equal('img/1.png');
- getRelativePath('css/1.css', 'css/2.css').should.be.equal('2.css');
+ getRelativePath('css/1.css', 'img/1.png').should.equal('../img/1.png');
+ getRelativePath('index.html', 'img/1.png').should.equal('img/1.png');
+ getRelativePath('css/1.css', 'css/2.css').should.equal('2.css');
});
it('should escape path components with encodeURIComponent', function () {
- getRelativePath('index.html', 'a/css?family=Open+Sans:300,400,600,700&lang=en').should.be.equal('a/css%3Ffamily%3DOpen%2BSans%3A300%2C400%2C600%2C700%26lang%3Den');
+ getRelativePath('index.html', 'a/css?family=Open+Sans:300,400,600,700&lang=en').should.equal('a/css%3Ffamily%3DOpen%2BSans%3A300%2C400%2C600%2C700%26lang%3Den');
});
it('should also escape [\'()]', function () {
- getRelativePath('index.html', '\'single quote for html attrs\'').should.be.equal('%27single%20quote%20for%20html%20attrs%27');
- getRelativePath('index.html', '(parenthesizes for css url)').should.be.equal('%28parenthesizes%20for%20css%20url%29');
+ getRelativePath('index.html', '\'single quote for html attrs\'').should.equal('%27single%20quote%20for%20html%20attrs%27');
+ getRelativePath('index.html', '(parenthesizes for css url)').should.equal('%28parenthesizes%20for%20css%20url%29');
});
});
describe('#shortenFilename', function() {
it('should leave file with length < 255 as is', function() {
var f1 = new Array(25).fill('a').join('');
- should(f1.length).be.eql(25);
- should(shortenFilename(f1)).be.eql(f1);
+ f1.length.should.eql(25);
+ shortenFilename(f1).should.eql(f1);
var f2 = new Array(25).fill('a').join('') + '.txt';
- should(f2.length).be.eql(29);
- should(shortenFilename(f2)).be.eql(f2);
+ f2.length.should.eql(29);
+ shortenFilename(f2).should.eql(f2);
});
it('should shorten file with length = 255', function() {
var f1 = new Array(255).fill('a').join('');
- should(f1.length).be.eql(255);
- should(shortenFilename(f1).length).be.lessThan(255);
+ f1.length.should.eql(255);
+ shortenFilename(f1).length.should.be.lessThan(255);
});
it('should shorten file with length > 255', function() {
var f1 = new Array(1255).fill('a').join('');
- should(f1.length).be.eql(1255);
- should(shortenFilename(f1).length).be.lessThan(255);
+ f1.length.should.eql(1255);
+ shortenFilename(f1).length.should.be.lessThan(255);
});
it('should shorten file with length = 255 and keep extension', function() {
var f1 = new Array(251).fill('a').join('') + '.txt';
- should(f1.length).be.eql(255);
- should(shortenFilename(f1).length).be.lessThan(255);
- should(shortenFilename(f1).split('.')[1]).be.eql('txt');
+ f1.length.should.eql(255);
+ shortenFilename(f1).length.should.be.lessThan(255);
+ shortenFilename(f1).split('.')[1].should.eql('txt');
});
it('should shorten file with length > 255 and keep extension', function() {
var f1 = new Array(1251).fill('a').join('') + '.txt';
- should(f1.length).be.eql(1255);
- should(shortenFilename(f1).length).be.lessThan(255);
- should(shortenFilename(f1).split('.')[1]).be.eql('txt');
+ f1.length.should.eql(1255);
+ shortenFilename(f1).length.should.be.lessThan(255);
+ shortenFilename(f1).split('.')[1].should.eql('txt');
});
it('should shorten file with length > 255 to have basename length 20 chars', function() {
var f1 = new Array(500).fill('a').join('');
- should(f1.length).be.eql(500);
- should(shortenFilename(f1).split('.')[0].length).be.eql(20);
+ f1.length.should.eql(500);
+ shortenFilename(f1).split('.')[0].length.should.eql(20);
var f2 = new Array(500).fill('a').join('') + '.txt';
- should(f2.length).be.eql(504);
- should(shortenFilename(f2).split('.')[0].length).be.eql(20);
+ f2.length.should.eql(504);
+ shortenFilename(f2).split('.')[0].length.should.eql(20);
});
});
describe('#prettifyFilename', () => {
it('should delete default filename if filename === defaultFilename', () => {
- should(prettifyFilename('index.html', {defaultFilename: 'index.html'})).be.eql('');
+ prettifyFilename('index.html', {defaultFilename: 'index.html'}).should.eql('');
});
it('should delete default filename if filename ends with defaultFilename', () => {
- should(prettifyFilename('somepage/index.html', {defaultFilename: 'index.html'})).be.eql('somepage/');
+ prettifyFilename('somepage/index.html', {defaultFilename: 'index.html'}).should.eql('somepage/');
});
it('should not prettify if defaultFilename is part of filename', () => {
- should(prettifyFilename('somepageindex.html', {defaultFilename: 'index.html'})).be.eql('somepageindex.html');
+ prettifyFilename('somepageindex.html', {defaultFilename: 'index.html'}).should.eql('somepageindex.html');
});
});
describe('#isUriSchemaSupported', function() {
it('should return false for mailto:', function() {
- should(isUriSchemaSupported('mailto:test@test.com')).be.eql(false);
+ isUriSchemaSupported('mailto:test@test.com').should.eql(false);
});
it('should return false for javascript:', function() {
- should(isUriSchemaSupported('javascript:alert("Hi!")')).be.eql(false);
+ isUriSchemaSupported('javascript:alert("Hi!")').should.eql(false);
});
it('should return false for skype:', function() {
- should(isUriSchemaSupported('skype:skype_name?action')).be.eql(false);
+ isUriSchemaSupported('skype:skype_name?action').should.eql(false);
});
it('should return true for http:', function() {
- should(isUriSchemaSupported('http://example.com')).be.eql(true);
+ isUriSchemaSupported('http://example.com').should.eql(true);
});
it('should return true for https:', function() {
- should(isUriSchemaSupported('https://example.com')).be.eql(true);
+ isUriSchemaSupported('https://example.com').should.eql(true);
});
it('should return true for relative paths', function() {
- should(isUriSchemaSupported('index.html')).be.eql(true);
+ isUriSchemaSupported('index.html').should.eql(true);
});
});
describe('#urlsEqual', () => {
it('should return false for /path and /path/', function() {
- should(urlsEqual('http://example.com/path', 'http://example.com/path/')).be.eql(false);
+ urlsEqual('http://example.com/path', 'http://example.com/path/').should.eql(false);
});
});
describe('#normalizeUrl', () => {
it('should return original url if it is malformed', () => {
const malformedUrl = 'http://example.com/%%IMAGEURL%%/bar1q2blitz.png';
- should(normalizeUrl(malformedUrl)).be.eql(malformedUrl);
+ normalizeUrl(malformedUrl).should.eql(malformedUrl);
});
});
describe('#getCharsetFromCss', () => {
it('should return charset from the beginning of css (inside double quotes)', () => {
const cssText = '@charset "UTF-8"; ';
- should(getCharsetFromCss(cssText)).be.eql('utf-8');
+ getCharsetFromCss(cssText).should.eql('utf-8');
});
it('should return charset from the beginning of css (inside single quotes)', () => {
const cssText = `@charset 'UTF-8'; `;
- should(getCharsetFromCss(cssText)).be.eql('utf-8');
+ getCharsetFromCss(cssText).should.eql('utf-8');
});
it('should return null if no charset', () => {
- const cssText = `h1 {color: red};`;
- should(getCharsetFromCss(cssText)).be.eql(null);
+ should.equal(getCharsetFromCss(`h1 {color: red};`), null);
});
it('should return null if charset is not valid', () => {
- should(getCharsetFromCss('@charset "UTF-8"; ')).be.eql(null);
- should(getCharsetFromCss(' @charset "UTF-8"; ')).be.eql(null);
- should(getCharsetFromCss('@charset UTF-8;')).be.eql(null);
- should(getCharsetFromCss('h1 {color: red}; @charset "UTF-8";')).be.eql(null);
+ should.equal(getCharsetFromCss('@charset "UTF-8"; '), null);
+ should.equal(getCharsetFromCss(' @charset "UTF-8"; '), null);
+ should.equal(getCharsetFromCss('@charset UTF-8;'), null);
+ should.equal(getCharsetFromCss('h1 {color: red}; @charset "UTF-8";'), null);
});
});
});
diff --git a/test/utils/assertions.js b/test/utils/assertions.js
index c68a40a0..1b06fdba 100644
--- a/test/utils/assertions.js
+++ b/test/utils/assertions.js
@@ -1,10 +1,16 @@
import path from 'path';
-import should from 'should';
-should.Assertion.add('equalFileSystemPath', function (value, description) {
- value = path.normalize(value);
- if (process.platform == 'win32' && value.startsWith(path.sep)) {
- value = __dirname.split(path.sep)[0] + value;
- }
- this.params = { operator: 'to be', expected: value, message: description};
- this.obj.should.equal(value, description);
+import * as chai from 'chai';
+chai.should();
+chai.Assertion.addMethod('equalFileSystemPath', function (value, description) {
+ value = path.normalize(value);
+ if (process.platform == 'win32' && value.startsWith(path.sep)) {
+ value = __dirname.split(path.sep)[0] + value;
+ }
+ this.assert(
+ path.normalize(this._obj) === value,
+ description || `expected #{this} to equal file system path #{exp}`,
+ description || `expected #{this} to not equal file system path #{exp}`,
+ value,
+ this._obj
+ );
});