Skip to content

Commit

Permalink
actually set lzo as default & add tests (#2)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ppd authored Dec 6, 2021
1 parent 0bddd6d commit 23aef11
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions packages/app-builder-lib/templates/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
base: core18
grade: stable
confinement: strict
compression: lzo
parts:
launch-scripts:
plugin: dump
Expand Down
41 changes: 41 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
})
)

0 comments on commit 23aef11

Please sign in to comment.