Skip to content

Commit

Permalink
Avoid throwing errors in the testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Nov 27, 2019
1 parent a1f0599 commit eccbb47
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 17 deletions.
8 changes: 6 additions & 2 deletions packages/api/core/src/api/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import requireSearch from '../util/require-search';
import packager from './package';

class MakerImpl extends MakerBase<any> {
name = 'impl';
name = 'impl';

defaultPlatforms = [];
defaultPlatforms = [];

requiredExternalBinaries = [];
}

export interface MakeOptions {
Expand Down Expand Up @@ -132,6 +134,8 @@ export default async ({
].join(''));
}

maker.ensureExternalBinariesExist();

makers[targetId] = maker;
targetId += 1;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/api/core/test/slow/api_spec_slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {
.filter((makerPath) => {
const MakerClass = require(makerPath).default;
const maker = new MakerClass();
return maker.isSupportedOnCurrentPlatform() === good;
return maker.isSupportedOnCurrentPlatform() === good
&& maker.externalBinariesExist() === good;
})
.map((makerPath) => () => ({
name: makerPath,
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/appx/src/MakerAppX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export default class MakerAppX extends MakerBase<MakerAppXConfig> {

defaultPlatforms: ForgePlatform[] = ['win32'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return process.platform === 'win32';
}
Expand Down
15 changes: 9 additions & 6 deletions packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default abstract class Maker<C> implements IForgeMaker {

public abstract defaultPlatforms: ForgePlatform[];

public abstract requiredExternalBinaries: string[] = [];

__isElectronForgeMaker!: true;

constructor(
Expand Down Expand Up @@ -131,18 +133,19 @@ export default abstract class Maker<C> implements IForgeMaker {
/**
* Checks if the specified binaries exist, which are required for the maker to be used.
*/
externalBinariesExist(binaries: string[]): boolean {
return binaries.every((binary) => which.sync(binary, { nothrow: true }) !== null);
externalBinariesExist(): boolean {
return this.requiredExternalBinaries.every(
(binary) => which.sync(binary, { nothrow: true }) !== null,
);
}

/**
* Throws an error if any of the binaries don't exist.
*/
ensureExternalBinariesExist(binaries: string[]): boolean {
if (this.externalBinariesExist(binaries)) {
return true;
ensureExternalBinariesExist() {
if (!this.externalBinariesExist()) {
throw new Error(`Cannot make for ${this.name}, the following external binaries need to be installed: ${this.requiredExternalBinaries.join(', ')}`);
}
throw new Error(`Cannot make for ${this.name}, the following external binaries need to be installed: ${binaries.join(', ')}`);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/base/test/ensure-output_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MakerImpl extends MakerBase<{}> {
name = 'test';

defaultPlatforms = [];

requiredExternalBinaries = [];
}

describe('ensure-output', () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/maker/base/test/support_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ class MakerImpl extends MakerBase<{}> {
name = 'test';

defaultPlatforms = [];

requiredExternalBinaries = ['bash', 'nonexistent'];
}

describe('ensureExternalBinariesExist', () => {
const maker = new MakerImpl({}, []);

it('returns true when all binaries exist', () => {
expect(maker.ensureExternalBinariesExist(['node'])).to.equal(true);
});

it('throws an error when one of the binaries does not exist', () => {
expect(() => maker.ensureExternalBinariesExist(['bash', 'nonexistent'])).to.throw(/the following external binaries need to be installed: bash, nonexistent/);
expect(() => maker.ensureExternalBinariesExist()).to.throw(/the following external binaries need to be installed: bash, nonexistent/);
});
});
4 changes: 3 additions & 1 deletion packages/maker/deb/src/MakerDeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default class MakerDeb extends MakerBase<MakerDebConfig> {

defaultPlatforms: ForgePlatform[] = ['linux'];

requiredExternalBinaries: string[] = ['dpkg', 'fakeroot'];

isSupportedOnCurrentPlatform() {
return this.isInstalled('electron-installer-debian') && this.ensureExternalBinariesExist(['dpkg', 'fakeroot']);
return this.isInstalled('electron-installer-debian');
}

async make({
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/dmg/src/MakerDMG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default class MakerDMG extends MakerBase<MakerDMGConfig> {

defaultPlatforms: ForgePlatform[] = ['darwin', 'mas'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return process.platform === 'darwin';
}
Expand Down
4 changes: 3 additions & 1 deletion packages/maker/flatpak/src/MakerFlatpak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export default class MakerFlatpak extends MakerBase<MakerFlatpakConfig> {

defaultPlatforms: ForgePlatform[] = ['linux'];

requiredExternalBinaries: string[] = ['flatpak-builder'];

isSupportedOnCurrentPlatform() {
return this.isInstalled('@malept/electron-installer-flatpak') && this.ensureExternalBinariesExist(['flatpak-builder']);
return this.isInstalled('@malept/electron-installer-flatpak');
}

async make({
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/pkg/src/MakerPKG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default class MakerDMG extends MakerBase<MakerPKGConfig> {

defaultPlatforms: ForgePlatform[] = ['darwin', 'mas'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return process.platform === 'darwin';
}
Expand Down
4 changes: 3 additions & 1 deletion packages/maker/rpm/src/MakerRpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export default class MakerRpm extends MakerBase<MakerRpmConfig> {

defaultPlatforms: ForgePlatform[] = ['linux'];

requiredExternalBinaries: string[] = ['rpmbuild'];

isSupportedOnCurrentPlatform() {
return this.isInstalled('electron-installer-redhat') && this.ensureExternalBinariesExist(['rpmbuild']);
return this.isInstalled('electron-installer-redhat');
}

async make({
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/snap/src/MakerSnap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default class MakerSnap extends MakerBase<MakerSnapConfig> {

defaultPlatforms: ForgePlatform[] = ['linux'];

requiredExternalBinaries: string[] = ['snapcraft'];

isSupportedOnCurrentPlatform() {
return process.platform === 'linux';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/squirrel/src/MakerSquirrel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default class MakerSquirrel extends MakerBase<MakerSquirrelConfig> {

defaultPlatforms: ForgePlatform[] = ['win32'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return this.isInstalled('electron-winstaller') && !process.env.DISABLE_SQUIRREL_TEST;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/wix/src/MakerWix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class MakerWix extends MakerBase<MakerWixConfig> {

defaultPlatforms: ForgePlatform[] = ['win32'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return process.platform === 'win32';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/maker/zip/src/MakerZIP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default class MakerZIP extends MakerBase<MakerZIPConfig> {

defaultPlatforms: ForgePlatform[] = ['darwin', 'mas', 'win32', 'linux'];

requiredExternalBinaries: string[] = [];

isSupportedOnCurrentPlatform() {
return true;
}
Expand Down

0 comments on commit eccbb47

Please sign in to comment.