blob: f5610a23f214feb0038daae7bab78f830b153c96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
var cheerio = require('cheerio');
var tmp = require('tmp');
var path = require('path');
var URL = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png';
describe('fetchRemoteImages', function() {
var dir;
var fetchRemoteImages = require('../fetchRemoteImages');
beforeEach(function() {
dir = tmp.dirSync();
});
pit('should download image file', function() {
var $ = cheerio.load('<img src="' + URL + '" />');
return fetchRemoteImages(dir.name, 'index.html', $)
.then(function() {
var $img = $('img');
var src = $img.attr('src');
expect(dir.name).toHaveFile(src);
});
});
pit('should download image file and replace with relative path', function() {
var $ = cheerio.load('<img src="' + URL + '" />');
return fetchRemoteImages(dir.name, 'test/index.html', $)
.then(function() {
var $img = $('img');
var src = $img.attr('src');
expect(dir.name).toHaveFile(path.join('test', src));
});
});
});
|