Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Platform, Arch } from "electron-builder"
import { assertPack, app, copyTestAsset } from "../helpers/packTester"
import * as path from "path"
import { archFromString } from "electron-builder-core"
import { safeLoad } from "js-yaml"
import { readFile } from "fs-extra-p";
import { doTest, expectUpdateMetadata } from "../helpers/winHelper"
const nsisTarget = Platform.WINDOWS.createTarget(["nsis"])
test.ifNotCiMac("boring, MUI_HEADER", () => {
let installerHeaderPath: string | null = null
return assertPack("test-app-one", {
targets: nsisTarget,
config: {
nsis: {
oneClick: false,
}
},
effectiveOptionComputed: async(it) => {
const defines = it[0]
expect(defines.MUI_HEADERIMAGE).toBeNull()
expect(defines.MUI_HEADERIMAGE_BITMAP).toEqual(installerHeaderPath)
expect(defines.MUI_HEADERIMAGE_RIGHT).toBeNull()
// speedup, do not build - another MUI_HEADER test will test build
process.exit(1);
}
// We are handling asar'ing and rebuilding in the normal run/build flow so we do not
// want electron-rebuild to do that.
settings.builderOptions.asar = false;
settings.builderOptions.npmRebuild = true;
let arch = this.$.env.options.ia32 ? 'ia32' : 'x64';
arch = this.$.env.options.allArchs ? 'all' : arch;
const targets = [];
if (this.$.env.options.win) {
targets.push(Platform.WINDOWS);
}
if (this.$.env.options.linux) {
targets.push(Platform.LINUX);
}
if (this.$.env.options.mac) {
targets.push(Platform.MAC);
}
if (targets.length === 0) {
if (this.$.env.os.isWindows) {
targets.push(Platform.WINDOWS);
} else if (this.$.env.os.isLinux) {
targets.push(Platform.LINUX);
} else {
targets.push(Platform.MAC);
}
c: for (const [platform, archToType] of packagerOptions.targets!!) {
for (const [arch, targets] of computeArchToTargetNamesMap(archToType, {platformSpecificBuildOptions: (packagerOptions as any)[platform.buildConfigurationKey] || {}, defaultTarget: []} as any, platform)) {
if (targets.length === 1 && targets[0] === DIR_TARGET) {
continue c
}
const nameToTarget = platformToTargets.get(platform)!!
if (platform === Platform.MAC) {
const packedAppDir = path.join(outDir, nameToTarget.has("mas-dev") ? "mas-dev" : (nameToTarget.has("mas") ? "mas" : "mac"), `${packager.appInfo.productFilename}.app`)
await checkMacResult(packager, packagerOptions, checkOptions, packedAppDir)
}
else if (platform === Platform.LINUX) {
await checkLinuxResult(outDir, packager, arch, nameToTarget)
}
else if (platform === Platform.WINDOWS) {
await checkWindowsResult(packager, checkOptions, artifacts.get(platform)!!, nameToTarget)
}
}
}
return {packager, outDir}
}
export async function expectUpdateMetadata(context: PackedContext, arch: Arch = Arch.ia32, requireCodeSign: boolean = false): Promise {
const data = safeLoad(await fs.readFile(path.join(context.getResources(Platform.WINDOWS, arch), "app-update.yml"), "utf-8")) as any
if (requireCodeSign) {
expect(data.publisherName).toEqual(["Foo, Inc"])
delete data.publisherName
}
expect(data).toMatchSnapshot()
}