Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected] [email protected]
17
*/
18
19
describe('Image', function() {
20
var ImageLoader = require('../lib/loader/ImageLoader');
21
var ResourceMap = require('../lib/ResourceMap');
22
var path = require('path');
23
var loadResouce = require('../lib/test_helpers/loadResource');
24
var waitsForCallback = require('../lib/test_helpers/waitsForCallback');
25
26
it('should match package.json paths', function() {
27
var loader = new ImageLoader();
28
expect(loader.matchPath('x.png')).toBe(true);
29
expect(loader.matchPath('x.jpg')).toBe(true);
30
expect(loader.matchPath('a/x.gif')).toBe(true);
31
expect(loader.matchPath('a/1.js')).toBe(false);
32
});
33
34
var testData = path.join(__dirname, '..', '__test_data__', 'Image');
35
36
it('should find the size of the picture', function() {
37
var loader = new ImageLoader();
38
loadResouce(
39
loader,
40
path.join(testData, 'a.jpg'),
41
null,
42
function(errors, resource) {
43
expect(resource.width).toBe(900);
44
expect(resource.height).toBe(596);
45
});
46
});
47
48
it('should calculate network size when asked', function() {
49
var loader = new ImageLoader();
50
loadResouce(
51
loader,
52
path.join(testData, 'a.jpg'),
53
null,
54
function(errors, r) {
55
expect(r.networkSize).toBe(127381);
56
});
57
});
58
59
it('should return form postProcess with 0 resources', function() {
60
var loader = new ImageLoader();
61
var map = new ResourceMap();
62
waitsForCallback(
63
function(callback) {
64
loader.postProcess(map, [], function() {
65
callback();
66
});
67
},
68
function(messages) {
69
expect(messages).not.toBe(null);
70
}
71
);
72
});
73
});
74
75