-
Notifications
You must be signed in to change notification settings - Fork 136
/
install_spec.js
126 lines (114 loc) · 4.56 KB
/
install_spec.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Pre-run
import '@babel/polyfill';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiFs from 'chai-fs';
import { given } from 'mocha-testdata';
import path from 'path';
import { BrowserWindow, session } from 'electron';
// Actual Test Imports
import installExtension, { REACT_DEVELOPER_TOOLS } from '../src/';
import knownExtensions from './testdata/knownExtensions';
chai.use(chaiAsPromised);
chai.use(chaiFs);
chai.should();
describe('Extension Installer', () => {
describe('when given a valid extension ID', () => {
given(...knownExtensions).it('should resolve the extension successfully', async (item) => {
const result = await installExtension(item.id);
expect(result).to.equal(item.description);
});
describe('when attempting to install the same extension twice', () => {
it('should resolve the promise', (done) => {
installExtension(REACT_DEVELOPER_TOOLS)
.then(() => installExtension(REACT_DEVELOPER_TOOLS))
.then(() => done())
.catch(() => done('Failed to resolve'));
});
it('should upgraded the extension with forceDownload', (done) => {
const extensionName = 'React Developer Tools';
const oldVersion = '0.14.0';
// For Electron >=9.
if (session.defaultSession.removeExtension) {
session.defaultSession.removeExtension(extensionName);
} else {
BrowserWindow.removeDevToolsExtension(extensionName);
}
// For Electron >=9.
if (session.defaultSession.loadExtension) {
session.defaultSession
.loadExtension(path.join(__dirname, 'fixtures/simple_extension'))
.then((ext) => {
ext.name.should.be.equal(extensionName);
session.defaultSession
.getAllExtensions()
.find((e) => e.name === extensionName)
.version.should.be.equal(oldVersion);
installExtension(REACT_DEVELOPER_TOOLS, true)
.then(() => {
session.defaultSession
.getAllExtensions()
.find((e) => e.name === extensionName)
.version.should.not.be.equal(oldVersion);
done();
})
.catch((err) => done(err));
})
.catch((err) => done(err));
} else {
BrowserWindow.addDevToolsExtension(
path.join(__dirname, 'fixtures/simple_extension'),
).should.be.equal(extensionName);
BrowserWindow.getDevToolsExtensions()[extensionName].version.should.be.equal(oldVersion);
installExtension(REACT_DEVELOPER_TOOLS, true)
.then(() => {
BrowserWindow.getDevToolsExtensions()[extensionName].version.should.not.be.equal(
oldVersion,
);
done();
})
.catch((err) => done(err));
}
});
});
});
describe('when given an array of valid extensions', () => {
it('should resolve the promise and install all of them', (done) => {
installExtension(knownExtensions)
.then(() => {
// For Electron >=9.
if (session.defaultSession.getAllExtensions) {
const installed = session.defaultSession.getAllExtensions();
for (const extension of knownExtensions) {
installed.map((e) => e.name).should.include(extension.description);
const extensionId = installed.find((e) => e.name === extension.description).id;
session.defaultSession.removeExtension(extensionId);
}
} else {
const installed = BrowserWindow.getDevToolsExtensions();
for (const extension of knownExtensions) {
installed.should.have.property(extension.description);
BrowserWindow.removeDevToolsExtension(extension.description);
}
}
done();
})
.catch((err) => done(err));
});
});
describe('when given an invalid extension ID', () => {
it('should reject the promise', () => installExtension('YOLO SWAGGINGS').should.be.rejected);
});
afterEach((done) => {
// For Electron >=9.
if (session.defaultSession.getAllExtensions) {
session.defaultSession
.getAllExtensions()
.forEach((ext) => session.defaultSession.removeExtension(ext.id));
} else {
const exts = BrowserWindow.getDevToolsExtensions();
Object.keys(exts).forEach((ext) => BrowserWindow.removeDevToolsExtension(ext));
}
setTimeout(done, 200);
});
});