/
assets.test.ts
84 lines (75 loc) · 2.6 KB
/
assets.test.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import fs from 'fs'
import path from 'path'
import { promisify } from 'util'
const sizeOfImage = promisify(require('image-size'))
describe('assets', () => {
describe('tokens', () => {
const ASSETS_DIRECTORY = './assets/tokens'
const REQUIRED_ASSET_HEIGHT = 256
const REQUIRED_ASSET_WIDTH = 256
const REQUIRED_ASSET_TYPE = 'png'
// TODO: update assets so we can remove the need for this exception list
const ASSETS_SIZE_EXCEPTIONS = new Set([
'ABR.png',
'ARI.png',
'CELO.png',
'FTM.png',
'IMMO.png',
'NTMX.png',
'PACT.png',
'UBE.png',
'cEUR.png',
'cREAL.png',
'cRecy.png',
'cUSD.png',
'mCELO.png',
'mCELOxOLD.png',
'mcEUR.png',
'mcEURxOLD.png',
'mcUSD.png',
'mcUSDxOLD.png',
'mcREAL.png',
'stabilUSD.png',
])
const assetPaths = fs
.readdirSync(ASSETS_DIRECTORY)
.map((assetFilename) => path.join(ASSETS_DIRECTORY, assetFilename))
it.each(assetPaths)('%s is the required size', async (assetPath) => {
const { height, width } = await sizeOfImage(assetPath)
if (ASSETS_SIZE_EXCEPTIONS.has(path.basename(assetPath))) {
// Just check it's a square
/* eslint-disable jest/no-conditional-expect */
expect(height).toBeGreaterThan(0)
expect(height).toBe(width)
/* eslint-enable jest/no-conditional-expect */
return
}
expect(height).toBe(REQUIRED_ASSET_HEIGHT)
expect(width).toBe(REQUIRED_ASSET_WIDTH)
})
it.each(assetPaths)('%s is the required type', async (assetPath) => {
const { type: assetType } = await sizeOfImage(assetPath)
expect(assetType).toBe(REQUIRED_ASSET_TYPE)
})
})
describe('addresses', () => {
const ASSETS_DIRECTORY = './assets/addresses'
const REQUIRED_ASSET_HEIGHT = 256
const REQUIRED_ASSET_WIDTH = 256
const REQUIRED_ASSET_TYPE = /(png|jpg)/
const assetPaths = fs
.readdirSync(ASSETS_DIRECTORY)
.map((assetFilename) => path.join(ASSETS_DIRECTORY, assetFilename))
// TODO: update assets so they can pass these requirements
// eslint-disable-next-line jest/no-disabled-tests
it.skip.each(assetPaths)('%s is the required size', async (assetPath) => {
const { height, width } = await sizeOfImage(assetPath)
expect(height).toBe(REQUIRED_ASSET_HEIGHT)
expect(width).toBe(REQUIRED_ASSET_WIDTH)
})
it.each(assetPaths)('%s is the required type', async (assetPath) => {
const { type: assetType } = await sizeOfImage(assetPath)
expect(assetType).toMatch(REQUIRED_ASSET_TYPE)
})
})
})