-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
common.js
61 lines (51 loc) · 1.69 KB
/
common.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
const fs = require('fs')
const path = require('path')
const EventEmitter = require('events')
const sinon = require('sinon')
const paths = {}
const urls = {}
const mocks = {}
paths.root = path.join(__dirname, '..')
paths.build = path.join(path.join(paths.root, 'build'))
paths.bin = path.join(paths.root, 'bin', 'orca.js')
paths.readme = path.join(paths.root, 'README.md')
paths.pkg = path.join(paths.root, 'package.json')
paths.glob = path.join(paths.root, 'src', 'util', '*')
urls.dummy = 'http://dummy.url'
urls.plotlyGraphMock = 'https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/20.json'
try {
mocks.figure = JSON.parse(fs.readFileSync(path.join(paths.build, 'test-mock.json'), 'utf-8'))
mocks.svg = fs.readFileSync(path.join(paths.build, 'test-mock.svg'), 'utf-8')
mocks.pdf = fs.readFileSync(path.join(paths.build, 'test-mock.pdf'))
} catch (e) {}
function createMockWindow (opts = {}) {
const win = new EventEmitter()
const webContents = new EventEmitter()
webContents.executeJavaScript = sinon.stub()
webContents.printToPDF = sinon.stub()
webContents.sendInputEvent = sinon.stub()
webContents.session = sinon.stub()
webContents.session.clearStorageData = sinon.stub()
Object.assign(win, opts, {
webContents: webContents,
loadURL: sinon.stub().callsFake(() => {
webContents.emit('did-finish-load')
}),
close: sinon.stub().callsFake(() => {
win.emit('closed')
})
})
return win
}
function stubProp (obj, key, newVal) {
const oldVal = obj[key]
obj[key] = newVal
return () => { obj[key] = oldVal }
}
module.exports = {
paths: paths,
urls: urls,
mocks: mocks,
createMockWindow: createMockWindow,
stubProp: stubProp
}