forked from electron/update-electron-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
81 lines (72 loc) 路 2.02 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
75
76
77
78
79
80
81
const updater = require('.')
const repo = 'some-owner/some-repo'
const os = require('os')
const tmpdir = os.tmpdir()
const fs = require('fs')
const path = require('path')
const electron = {
app: {
getVersion: () => { return '1.2.3' },
isReady: () => { return true },
on: (eventName) => { /* no-op */ },
getAppPath: () => { return tmpdir }
},
autoUpdater: {
checkForUpdates: () => { /* no-op */ },
on: (eventName) => { /* no-op */ },
setFeedURL: () => { /* no-op */ }
},
dialog: {
showMessageBox: () => { /* no-op */ }
}
}
test('exports a function', () => {
expect(typeof updater).toBe('function')
})
describe('repository', () => {
fs.writeFileSync(
path.join(tmpdir, 'package.json'),
JSON.stringify({})
)
test('is required', () => {
expect(() => {
updater({electron})
}).toThrowError('repo not found. Add repository string to your app\'s package.json file')
})
test('from opts', () => {
updater({electron, repo: 'foo/bar'})
})
test('from package.json', () => {
fs.writeFileSync(
path.join(tmpdir, 'package.json'),
JSON.stringify({repository: 'foo/bar'})
)
updater({electron})
})
})
describe('host', () => {
test('must a valid HTTPS URL', () => {
expect(() => {
updater({repo, electron, host: 'http://example.com'})
}).toThrowError('host must be a valid HTTPS URL')
})
})
describe('logger', () => {
test('must be an object defining a `log` function', () => {
expect(() => {
updater({repo, electron, logger: 'yep'})
}).toThrowError('logger.log is not a function')
})
})
describe('updateInterval', () => {
test('must be 5 minutes or more', () => {
expect(() => {
updater({repo, electron, updateInterval: '20 seconds'})
}).toThrowError('updateInterval must be `5 minutes` or more')
})
test('must be a string', () => {
expect(() => {
updater({repo, electron, updateInterval: 3000})
}).toThrowError('updateInterval must be a human-friendly string interval like `20 minutes`')
})
})