electron-locator.ts
1.65 KB
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
import * as fs from 'fs-extra';
import * as path from 'path';
import { expect } from 'chai';
import { spawnPromise } from 'spawn-rx';
import { locateElectronModule } from '../src/electron-locator';
function packageCommand(command: string, packageName: string): Promise<string> {
return spawnPromise('npm', [command, '--no-save', packageName], {
cwd: path.resolve(__dirname, '..'),
stdio: 'ignore',
});
}
const install: ((s: string) => Promise<void>) = packageCommand.bind(null, 'install');
const uninstall: ((s: string) => Promise<void>) = packageCommand.bind(null, 'uninstall');
const testElectronCanBeFound = (): void => {
it('should return a valid path', async () => {
const electronPath = await locateElectronModule();
expect(electronPath).to.be.a('string');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(await fs.pathExists(electronPath!)).to.be.equal(true);
});
};
describe('locateElectronModule', function() {
this.timeout(30 * 1000);
before(() => uninstall('electron'));
it('should return null when electron is not installed', async () => {
await fs.remove(path.resolve(__dirname, '..', 'node_modules', 'electron'));
expect(await locateElectronModule()).to.be.equal(null);
});
describe('with electron-prebuilt installed', async () => {
before(() => install('electron-prebuilt'));
testElectronCanBeFound();
after(() => uninstall('electron-prebuilt'));
});
describe('with electron installed', async () => {
before(() => install('electron@^5.0.13'));
testElectronCanBeFound();
after(() => uninstall('electron'));
});
after(() => install('electron@^5.0.13'));
});