From 23aef110e0fd9367d92bfa225b6f792a36941256 Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Mon, 6 Dec 2021 18:59:16 +0100 Subject: [PATCH] actually set lzo as default & add tests (#2) * make lzo the compression default in snap options * add lzo compression to snapcraft template * construct compression arg from descriptor * add tests for snap compression option --- .../src/options/SnapOptions.ts | 3 +- packages/app-builder-lib/src/targets/snap.ts | 7 ++-- .../templates/snap/snapcraft.yaml | 1 + test/src/linux/snapTest.ts | 41 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index 41692536756..3d1d6658e49 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -127,7 +127,8 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { readonly title?: string | null /** - * Sets the compression type for the snap. Can be xz or lzo. Defaults to xz when not specified. + * Sets the compression type for the snap. Can be xz or lzo. Defaults to lzo when not specified. + * @default lzo */ readonly compression?: "xz" | "lzo" | null } diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index e6e0dbc99b3..b170db4a8b5 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -208,6 +208,10 @@ export default class SnapTarget extends Target { } } + if (snap.compression != null) { + args.push("--compression", snap.compression) + } + if (packager.packagerOptions.effectiveOptionComputed != null && (await packager.packagerOptions.effectiveOptionComputed({ snap, desktopFile, args }))) { return } @@ -223,9 +227,6 @@ export default class SnapTarget extends Target { args.push("--template-url", `electron4:${snapArch}`) } - if (options.compression != null) { - args.push("--compression", options.compression) - } await executeAppBuilder(args) await packager.info.callArtifactBuildCompleted({ diff --git a/packages/app-builder-lib/templates/snap/snapcraft.yaml b/packages/app-builder-lib/templates/snap/snapcraft.yaml index 08ed9604b8e..bfbc6142686 100644 --- a/packages/app-builder-lib/templates/snap/snapcraft.yaml +++ b/packages/app-builder-lib/templates/snap/snapcraft.yaml @@ -1,6 +1,7 @@ base: core18 grade: stable confinement: strict +compression: lzo parts: launch-scripts: plugin: dump diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 9853964bef4..48fd03014d7 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -255,3 +255,44 @@ test.ifAll.ifDevOrLinuxCi( }, }) ) + +test.ifDevOrLinuxCi( + "default compression", + app({ + targets: snapTarget, + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + }, + effectiveOptionComputed: async ({ snap, args }) => { + expect(snap).toMatchSnapshot() + expect(snap.compression).toEqual("lzo") + expect(args).toEqual(expect.arrayContaining(["--compression", "lzo"])) + return true + }, + }) +) + +test.ifDevOrLinuxCi( + "compression option", + app({ + targets: snapTarget, + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + snap: { + compression: "xz" + } + }, + effectiveOptionComputed: async ({ snap, args }) => { + expect(snap).toMatchSnapshot() + expect(snap.compression).toEqual("xz") + expect(args).toEqual(expect.arrayContaining(["--compression", "xz"])) + return true + }, + }) +)