Skip to content

Commit 9e223fb

Browse files
authored
chore(smoke-tests): Refactor installers to take buildInfo directly (#6714)
Refactor installers to take buildInfo
1 parent 59f3023 commit 9e223fb

File tree

14 files changed

+90
-50
lines changed

14 files changed

+90
-50
lines changed

packages/compass-smoke-tests/src/build-info.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export type PackageDetails = {
145145
kind: PackageKind;
146146
filename: string;
147147
autoUpdatable: boolean;
148-
appName: string;
149148
} & (
150149
| {
151150
kind: 'windows_setup' | 'windows_msi' | 'windows_zip';
@@ -182,7 +181,6 @@ export function getPackageDetails(
182181
kind,
183182
buildInfo,
184183
filename: buildInfo[`${kind}_filename`],
185-
appName: buildInfo.installerOptions.name,
186184
autoUpdatable: kind === 'windows_setup',
187185
};
188186
} else if (kind === 'osx_dmg' || kind === 'osx_zip') {
@@ -191,7 +189,6 @@ export function getPackageDetails(
191189
kind,
192190
buildInfo,
193191
filename: buildInfo[`${kind}_filename`],
194-
appName: buildInfo.installerOptions.title,
195192
autoUpdatable: true,
196193
};
197194
} else if (kind === 'linux_deb' || kind === 'linux_tar') {
@@ -200,7 +197,6 @@ export function getPackageDetails(
200197
kind,
201198
buildInfo,
202199
filename: buildInfo[`${kind}_filename`],
203-
appName: buildInfo.productName,
204200
autoUpdatable: false,
205201
};
206202
} else if (kind === 'linux_rpm' || kind === 'rhel_tar') {
@@ -209,7 +205,6 @@ export function getPackageDetails(
209205
kind,
210206
buildInfo,
211207
filename: buildInfo[`${kind}_filename`],
212-
appName: buildInfo.productName,
213208
autoUpdatable: false,
214209
};
215210
} else {

packages/compass-smoke-tests/src/installers/linux-deb.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import { execute } from '../execute';
77
import * as apt from './apt';
88

99
export function installLinuxDeb({
10-
appName,
10+
kind,
1111
filepath,
12+
buildInfo,
1213
}: InstallablePackage): InstalledAppInfo {
14+
assert.equal(kind, 'linux_deb');
15+
const appName = buildInfo.productName;
1316
const packageName = apt.getPackageName(filepath);
1417
const installPath = `/usr/lib/${packageName}`;
1518
const appPath = path.resolve(installPath, appName);
@@ -47,6 +50,7 @@ export function installLinuxDeb({
4750
execute('xvfb-run', [appPath, '--version']);
4851

4952
return {
53+
appName,
5054
appPath: installPath,
5155
uninstall,
5256
};

packages/compass-smoke-tests/src/installers/linux-rpm.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export function isInstalled(packageName: string) {
3737
}
3838

3939
export function installLinuxRpm({
40-
appName,
40+
kind,
4141
filepath,
42+
buildInfo,
4243
}: InstallablePackage): InstalledAppInfo {
44+
assert.equal(kind, 'linux_rpm');
45+
const appName = buildInfo.productName;
4346
const packageName = getPackageName(filepath);
4447
const installPath = `/usr/lib/${packageName}`;
4548
const appPath = path.resolve(installPath, appName);
@@ -75,6 +78,7 @@ export function installLinuxRpm({
7578
execute('xvfb-run', [appPath, '--version']);
7679

7780
return {
81+
appName,
7882
appPath: installPath,
7983
uninstall,
8084
};

packages/compass-smoke-tests/src/installers/linux-tar.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
import assert from 'node:assert/strict';
12
import path from 'node:path';
23

34
import type { InstalledAppInfo, InstallablePackage } from './types';
45
import { execute } from '../execute';
56

67
export function installLinuxTar({
7-
appName,
8+
kind,
89
filepath,
9-
destinationPath,
10+
sandboxPath,
11+
buildInfo,
1012
}: InstallablePackage): InstalledAppInfo {
13+
assert.equal(kind, 'linux_tar');
14+
const appName = buildInfo.productName;
1115
const appFilename = `${appName}-linux-x64`;
12-
const appPath = path.resolve(destinationPath, appFilename);
16+
const appPath = path.resolve(sandboxPath, appFilename);
1317

14-
execute('tar', ['-xzvf', filepath, '-C', destinationPath]);
18+
execute('tar', ['-xzvf', filepath, '-C', sandboxPath]);
1519

1620
// Check that the executable will run without being quarantined or similar
1721
execute('xvfb-run', [path.resolve(appPath, appName), '--version']);
1822

1923
return {
24+
appName,
2025
appPath,
2126
uninstall: async function () {
2227
/* TODO */

packages/compass-smoke-tests/src/installers/mac-dmg.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import path from 'node:path';
23
import fs from 'node:fs';
34
import {
@@ -9,15 +10,22 @@ import type { InstalledAppInfo, InstallablePackage } from './types';
910
import { execute } from '../execute';
1011

1112
export function installMacDMG({
12-
appName,
13+
kind,
1314
filepath,
14-
destinationPath,
15+
sandboxPath,
16+
buildInfo,
1517
}: InstallablePackage): InstalledAppInfo {
16-
const appFilename = `${appName}.app`;
17-
const appPath = path.resolve(destinationPath, appFilename);
18-
const volumePath = `/Volumes/${appName}`;
18+
assert.equal(kind, 'osx_dmg');
19+
const appName = buildInfo.productName;
20+
const appFilename = `${buildInfo.productName}.app`;
21+
const appPath = path.resolve(sandboxPath, appFilename);
22+
const volumePath = path.resolve(
23+
sandboxPath,
24+
buildInfo.installerOptions.title
25+
);
1926

20-
execute('hdiutil', ['attach', filepath]);
27+
execute('hdiutil', ['attach', '-mountroot', sandboxPath, filepath]);
28+
assert(fs.existsSync(volumePath), `Expected a mount: ${volumePath}`);
2129

2230
try {
2331
fs.cpSync(path.resolve(volumePath, appFilename), appPath, {
@@ -33,6 +41,7 @@ export function installMacDMG({
3341
assertFileNotQuarantined(appPath);
3442

3543
return {
44+
appName,
3645
appPath: appPath,
3746
uninstall: async function () {
3847
/* TODO */

packages/compass-smoke-tests/src/installers/mac-zip.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import path from 'node:path';
23
import {
34
assertFileNotQuarantined,
@@ -7,20 +8,24 @@ import type { InstalledAppInfo, InstallablePackage } from './types';
78
import { execute } from '../execute';
89

910
export function installMacZIP({
10-
appName,
11+
kind,
1112
filepath,
12-
destinationPath,
13+
sandboxPath,
14+
buildInfo,
1315
}: InstallablePackage): InstalledAppInfo {
16+
assert.equal(kind, 'osx_zip');
17+
const appName = buildInfo.productName;
1418
const appFilename = `${appName}.app`;
15-
const appPath = path.resolve(destinationPath, appFilename);
19+
const appPath = path.resolve(sandboxPath, appFilename);
1620

17-
execute('ditto', ['-xk', filepath, destinationPath]);
21+
execute('ditto', ['-xk', filepath, sandboxPath]);
1822

1923
removeApplicationSupportForApp(appName);
2024

2125
assertFileNotQuarantined(appPath);
2226

2327
return {
28+
appName,
2429
appPath: appPath,
2530
uninstall: async function () {
2631
/* TODO */
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { TestSubject } from '../test-subject';
2+
13
export type Installer = (pkg: InstallablePackage) => Promise<InstalledAppInfo>;
24

35
export type Package = {
@@ -8,13 +10,12 @@ export type Package = {
810
installer: Installer;
911
};
1012

11-
export type InstallablePackage = {
12-
appName: string;
13-
filepath: string;
14-
destinationPath: string;
13+
export type InstallablePackage = TestSubject & {
14+
sandboxPath: string;
1515
};
1616

1717
export type InstalledAppInfo = {
1818
appPath: string;
19+
appName: string;
1920
uninstall: () => void | Promise<void>;
2021
};

packages/compass-smoke-tests/src/installers/windows-msi.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'node:assert/strict';
12
import path from 'node:path';
23
import createDebug from 'debug';
34

@@ -9,11 +10,14 @@ const debug = createDebug('compass:smoketests:windows-msi');
910
// See https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec
1011

1112
export function installWindowsMSI({
12-
appName,
13+
kind,
1314
filepath,
14-
destinationPath,
15+
sandboxPath,
16+
buildInfo,
1517
}: InstallablePackage): InstalledAppInfo {
16-
const installDirectory = path.resolve(destinationPath, appName);
18+
assert.equal(kind, 'windows_msi');
19+
const appName = buildInfo.installerOptions.name;
20+
const installDirectory = path.resolve(sandboxPath, appName);
1721
const appPath = path.resolve(installDirectory, `${appName}.exe`);
1822

1923
function uninstall() {
@@ -46,6 +50,7 @@ export function installWindowsMSI({
4650
execute(appPath, ['--version']);
4751

4852
return {
53+
appName,
4954
appPath: installDirectory,
5055
uninstall,
5156
};

packages/compass-smoke-tests/src/installers/windows-setup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'node:path';
21
import assert from 'node:assert/strict';
2+
import path from 'node:path';
33
import fs from 'node:fs';
44
import cp from 'node:child_process';
55
import createDebug from 'debug';
@@ -21,9 +21,13 @@ type UninstallOptions = {
2121
* Install using the Windows installer.
2222
*/
2323
export function installWindowsSetup({
24-
appName,
24+
kind,
2525
filepath,
26+
buildInfo,
2627
}: InstallablePackage): InstalledAppInfo {
28+
assert.equal(kind, 'windows_setup');
29+
const appName = buildInfo.installerOptions.name;
30+
2731
function queryRegistry() {
2832
return windowsRegistry.query(
2933
`HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${appName}`
@@ -80,6 +84,7 @@ export function installWindowsSetup({
8084
execute(appExecutablePath, ['--version']);
8185

8286
return {
87+
appName,
8388
appPath,
8489
uninstall,
8590
};

packages/compass-smoke-tests/src/installers/windows-zip.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
import assert from 'node:assert/strict';
12
import path from 'node:path';
23

34
import type { InstalledAppInfo, InstallablePackage } from './types';
45
import { execute } from '../execute';
56

67
export function installWindowsZIP({
7-
appName,
8+
kind,
89
filepath,
9-
destinationPath,
10+
sandboxPath,
11+
buildInfo,
1012
}: InstallablePackage): InstalledAppInfo {
11-
const appPath = path.resolve(destinationPath, `${appName}.exe`);
13+
assert.equal(kind, 'windows_zip');
14+
const appName = buildInfo.installerOptions.name;
15+
const appPath = path.resolve(sandboxPath, `${appName}.exe`);
1216

13-
execute('unzip', [filepath, '-d', destinationPath]);
17+
execute('unzip', [filepath, '-d', sandboxPath]);
1418

1519
// see if the executable will run without being quarantined or similar
1620
execute(appPath, ['--version']);
1721

1822
return {
19-
appPath: destinationPath,
23+
appName,
24+
appPath: sandboxPath,
2025
uninstall: async function () {
2126
/* TODO */
2227
},

0 commit comments

Comments
 (0)