-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwptTests.js
49 lines (46 loc) · 2.48 KB
/
wptTests.js
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
41
42
43
44
45
46
47
48
49
/**
* Created by yaniv on 5/3/17.
*/
'use strict';
const chai = require('chai');
const assert = chai.assert;
const wtpParser = require('../wtp/wtpResultsParser');
const fs = require('fs');
describe('Parse WPT result', () => {
describe('Get image array', () => {
it('Retrieve the Images array from the WPT result', () => {
let resultJson = JSON.parse(fs.readFileSync('./test/resources/test1.json'));
let images = wtpParser.parseTestResults(resultJson);
assert.equal(images.imageList.length, 28, 'There should be 28 images in the list');
});
it('Retrieve the Images array from the WPT result when the images are not JSON-encoded (as happens for iPhone user agent)', () => {
let resultJson = JSON.parse(fs.readFileSync('./test/resources/test1.json'));
resultJson.data.median.firstView.Images = JSON.parse(resultJson.data.median.firstView.Images);
let images = wtpParser.parseTestResults(resultJson);
assert.equal(images.imageList.length, 28, 'There should be 28 images in the list');
});
it('Image list length', () => {
let resultJsonLong = JSON.parse(fs.readFileSync('./test/resources/test1.json'));
let images = wtpParser.parseTestResults(resultJsonLong);
assert.equal(images.imageList.length, 28 , 'There should be 28 images in the list');
});
});
it('Filter image by resolution', () => {
let resultJson = JSON.parse(fs.readFileSync('./test/resources/test1.json'));
let list = JSON.parse(resultJson.data.median.firstView.Images);
list[0].naturalWidth = 200;
resultJson.data.median.firstView.Images = JSON.stringify(list);
let images = wtpParser.parseTestResults(resultJson);
assert.equal(images.imageList.length, 28, 'There should be 28 images in the list');
});
it('Check for result keys', () => {
let resultJson = JSON.parse(fs.readFileSync('./test/resources/test1.json'));
let results = wtpParser.parseTestResults(resultJson);
assert.isArray(results.imageList, 'Image list is not an array');
assert.isNumber(results.dpr, 'dpr is not a number');
assert.equal(results.metaData.headers.length, 2, 'We should have 2 headers');
assert.isString(results.metaData.url, 'There should be a url');
assert.isString(results.metaData.screenShot, 'There should be a screenshot');
assert.isObject(results.metaData.viewportSize, 'ViewportSize is not an object');
})
});