forked from fingerprintjs/fingerprintjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfonts.test.ts
78 lines (67 loc) · 1.94 KB
/
fonts.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
import {
getBrowserMajorVersion,
isAndroid,
isChromium,
isGecko,
isMacOS,
isMobile,
isWebKit,
isWindows,
} from '../../tests/utils'
import getFonts from './fonts'
describe('Sources', () => {
describe('fonts', () => {
it('returns expected fonts', async () => {
const result = await getFonts()
// macOS (Firefox, Chromium, Safari)
if (isMacOS()) {
containsExpectedFonts(['Arial Unicode MS', 'Gill Sans', 'Helvetica Neue', 'Menlo'], result)
return
}
// iOS (Safari)
if (isWebKit() && isMobile()) {
containsExpectedFonts(['Gill Sans', 'Helvetica Neue', 'Menlo'], result)
return
}
if (isWindows()) {
if (isGecko()) {
containsExpectedFonts(
// 'Segoe UI Light' not in the list because it seems to be sometimes missing when automated on BrowserStack
['Calibri', 'Franklin Gothic', 'HELV', 'MS UI Gothic', 'Marlett', 'Small Fonts'],
result,
)
return
}
if (isChromium()) {
containsExpectedFonts(['Calibri', 'Franklin Gothic', 'MS UI Gothic', 'Marlett', 'Segoe UI Light'], result)
return
}
}
if (isAndroid()) {
if (isGecko()) {
expect(result.length).toBe(0)
return
}
if (isChromium()) {
containsExpectedFonts(['sans-serif-thin'], result)
return
}
}
expect(result.length).toBeGreaterThan(0)
})
it('return stable values', async () => {
// The result is unstable in Firefox 89 on BrowserStack Automate
if (isGecko() && getBrowserMajorVersion() === 89) {
return
}
const first = await getFonts()
const second = await getFonts()
expect(second).toEqual(first)
})
})
})
function containsExpectedFonts(expected: string[], actual: string[]) {
for (const font of expected) {
expect(actual).toContain(font)
}
}