-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathimages.test.js
44 lines (34 loc) · 1.43 KB
/
images.test.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
const devices = require('zigbee-shepherd-converters').devices;
const chai = require('chai');
const fs = require('fs');
const path = require('path');
const sizeOf = require('image-size');
const imageBase = path.join(__dirname, '..', 'docs', 'images', 'devices');
const replaceByDash = [new RegExp('/', 'g'), new RegExp(':', 'g'), new RegExp(' ', 'g')];
describe('Device images', () => {
it('All devices should have an image in jpg format', () => {
const missing = [];
devices.forEach((d) => {
let image = d.model;
replaceByDash.forEach((r) => image = image.replace(r, '-'));
image = `${image}.jpg`;
if (!fs.existsSync(path.join(imageBase, image))) {
missing.push(image);
}
});
chai.assert.strictEqual(missing.length, 0, `Missing device images: ${missing.join(', ')}`);
});
it('All device images should have a dimension of 150x150', () => {
const invalid = [];
fs.readdirSync(imageBase).forEach((file) => {
if (!file.toLowerCase().endsWith('.jpg')) {
return;
}
const dimensions = sizeOf(path.join(imageBase, file));
if (dimensions.width != 150 || dimensions.height != 150) {
invalid.push(file);
}
});
chai.assert.strictEqual(invalid.length, 0, `Invalid device image dimensions: ${invalid.join(', ')}`);
});
});