-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
test.js
74 lines (65 loc) · 1.85 KB
/
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
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
const test = require('ava')
const { path: tempPathSync } = require('temp')
const { existsSync, unlinkSync } = require('fs')
const screenshot = require('./')
test.before(async () => {
return screenshot.listDisplays().then(displays => {
console.log('Displays:', JSON.stringify(displays, null, 2), '\n')
})
})
test('screenshot', t => {
t.plan(1)
return screenshot().then(img => {
t.truthy(Buffer.isBuffer(img))
})
})
function checkDisplays (t, displays) {
t.truthy(Array.isArray(displays))
displays.forEach(disp => {
t.truthy(disp.name)
t.truthy(disp.id !== undefined)
})
}
test('screenshot each display', t => {
if (screenshot.availableDisplays) {
return screenshot.availableDisplays().then(displays => {
checkDisplays(t, displays)
displays.forEach(display => {
screenshot(display.id)
})
})
} else {
t.pass()
}
})
test('screenshot to a file', t => {
t.plan(1)
const tmpName = tempPathSync({ suffix: '.jpg' })
return screenshot({ filename: tmpName }).then(() => {
t.truthy(existsSync(tmpName))
unlinkSync(tmpName)
})
})
test('screenshot specific screen to a file', t => {
t.plan(1)
const tmpName = tempPathSync({ suffix: '.jpg' })
return screenshot({ filename: tmpName, screen: 0 }).then(() => {
t.truthy(existsSync(tmpName))
unlinkSync(tmpName)
})
})
test('screenshot to a file with a space', t => {
// https://github.com/bencevans/screenshot-desktop/issues/12
t.plan(1)
const tmpName = tempPathSync({ suffix: '.jpg' })
return screenshot({ filename: tmpName }).then(() => {
t.truthy(existsSync(tmpName))
unlinkSync(tmpName)
})
})
test('parse display output', t => {
if (screenshot.EXAMPLE_DISPLAYS_OUTPUT && screenshot.parseDisplaysOutput) {
const disps = screenshot.parseDisplaysOutput(screenshot.EXAMPLE_DISPLAYS_OUTPUT)
checkDisplays(t, disps)
}
})