/
e2e-per-user.ts
128 lines (111 loc) · 5.52 KB
/
e2e-per-user.ts
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
127
128
import expect from 'expect.js';
import * as fs from 'fs-extra';
import path from 'path';
import { getWindowsCompliantVersion } from '../../lib/utils/version-util';
import { expectSameFolderContent } from './common';
import { getProcessPath, kill, launch, runs } from './utils/app-process';
import { checkInstall, getInstallPaths, install, uninstall, uninstallViaPowershell } from './utils/installer';
import { createMsiPackage, defaultMsiOptions, HARNESS_APP_DIR, OUT_DIR } from './utils/msi-packager';
import { getRegistryKeyValue } from './utils/registry';
import { sleep } from './utils/util';
interface TestConfig {
arch: 'x86' | 'x64';
defaultInstallMode: 'perUser' | 'perMachine';
}
interface InstallConfig {
installMode?: 'perUser' | 'perMachine';
effectiveMode: 'perUser' | 'perMachine';
}
const msiPath = path.join(OUT_DIR, 'HelloWix.msi');
const autoLaunchMsiOptions = {
...defaultMsiOptions,
features: {
autoUpdate: false,
autoLaunch: true
}
};
describe.only('MSI perUser install', () => {
before(async () => {
if (await checkInstall(`${defaultMsiOptions.name} (Machine - MSI)`)) {
await uninstallViaPowershell(`${defaultMsiOptions.name} (Machine - MSI)`);
}
fs.rmdirSync(getInstallPaths({ ...defaultMsiOptions, arch: 'x86'}).appRootFolder, { recursive: true });
fs.rmdirSync(getInstallPaths({ ...defaultMsiOptions, arch: 'x86'}, 'perUser').appRootFolder, { recursive: true });
fs.rmdirSync(getInstallPaths({ ...defaultMsiOptions, arch: 'x64'}).appRootFolder, { recursive: true });
});
const testConfigs: TestConfig[] = [
{arch: 'x86', defaultInstallMode: 'perUser'},
{arch: 'x86', defaultInstallMode: 'perMachine'},
{arch: 'x64', defaultInstallMode: 'perUser'},
{arch: 'x64', defaultInstallMode: 'perMachine'},
];
testConfigs.forEach((testConfig) => {
describe((`arch:${testConfig.arch}, defaultInstallMode:${testConfig.defaultInstallMode}`), () => {
const msiOptions = {
...autoLaunchMsiOptions,
...testConfig
};
it(`packages (${testConfig.arch})`, async () => {
await createMsiPackage(msiOptions);
});
const installConfigs: InstallConfig[] = [
{ installMode: undefined, effectiveMode: testConfig.defaultInstallMode },
{ installMode: 'perUser', effectiveMode: 'perUser' },
{ installMode: 'perMachine', effectiveMode: 'perMachine' },
];
installConfigs.forEach((installConfig) => {
describe((`installMode:${installConfig.installMode !== undefined ?
installConfig.installMode : 'default' }`), () => {
let autoLaunchRegistryKeyValue = '';
const msiPaths123beta = getInstallPaths(msiOptions, installConfig.effectiveMode);
it(`installs (${testConfig.arch})`, async () => {
await install(msiPath, 2, undefined, installConfig.installMode);
const version = getWindowsCompliantVersion(msiOptions.version);
const nameSuffix = installConfig.effectiveMode === 'perUser' ? 'User' : 'Machine';
expect(await checkInstall(`${msiOptions.name} (${nameSuffix})`, msiOptions.version)).ok();
expect(await checkInstall(`${msiOptions.name} (${nameSuffix} - MSI)`, version)).ok();
});
it(`has all files in program files (${testConfig.arch})`, () => {
expect(fs.pathExistsSync(msiPaths123beta.stubExe)).ok();
expect(fs.pathExistsSync(msiPaths123beta.appFolder)).ok();
expectSameFolderContent(HARNESS_APP_DIR, msiPaths123beta.appFolder);
});
it(`has shortcuts (${testConfig.arch})`, () => {
expect(fs.pathExistsSync(msiPaths123beta.startMenuShortcut)).ok();
expect(fs.pathExistsSync(msiPaths123beta.desktopShortcut)).ok();
});
it(`has auto-launch registry key (${testConfig.arch})`, async () => {
autoLaunchRegistryKeyValue = await getRegistryKeyValue(msiPaths123beta.registryRunKey,
msiPaths123beta.appUserModelId);
expect(autoLaunchRegistryKeyValue).to.be(`"${msiPaths123beta.stubExe}"`);
entryPoints[3].path = autoLaunchRegistryKeyValue;
});
const entryPoints = [
{ name: 'stubExe', path: msiPaths123beta.stubExe },
{ name: 'start menu shortcut', path: msiPaths123beta.startMenuShortcut },
{ name: 'desktop shortcut', path: msiPaths123beta.desktopShortcut },
{ name: 'auto-launch key', path: autoLaunchRegistryKeyValue },
];
entryPoints.forEach(async (entryPoint) => {
it(`runs the correct binary via ${entryPoint.name}`, async () => {
await launch(entryPoint.path);
expect(await runs(msiOptions.exe)).ok();
await sleep(1000);
expect(await getProcessPath(msiOptions.exe)).to.be(msiPaths123beta.appExe);
await kill(msiOptions.exe);
});
});
it(`uninstalls (${testConfig.arch})`, async () => {
await uninstall(msiPath);
const nameSuffix = installConfig.effectiveMode === 'perUser' ? 'User' : 'Machine';
expect(await checkInstall(`${msiOptions.name} (${nameSuffix})`)).not.ok();
expect(await checkInstall(`${msiOptions.name} (${nameSuffix} - MSI)`)).not.ok();
expect(fs.pathExistsSync(msiPaths123beta.appRootFolder)).not.ok();
expect(fs.pathExistsSync(msiPaths123beta.startMenuShortcut)).not.ok();
expect(fs.pathExistsSync(msiPaths123beta.desktopShortcut)).not.ok();
});
});
});
});
});
});