From 9dfcda0d90d8fce0aaee3b56aa3bcba899cdebec Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Thu, 18 Jul 2024 19:45:54 +0800 Subject: [PATCH] get file list by 7z --- test/src/helpers/packTester.ts | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index 92688490d48..c9b717e320d 100644 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -376,6 +376,28 @@ async function checkMacResult(packager: Packager, packagerOptions: PackagerOptio } } +async function listNupkgContents(nupkgPath: string) { + const { exec } = require("child_process") + const util = require("util") + const execPromise = util.promisify(exec) + try { + const { stdout, stderr } = await execPromise(`7z l -slt "${nupkgPath}"`) + if (stderr) { + console.error("7z command error:", stderr) + } + + const files = stdout + .split("\n") + .filter((line: string) => line.startsWith("Path = ")) + .map((line: string) => line.replace("Path = ", "").trim()) + .filter((path: string) => path !== "") + + return files + } catch (err) { + throw new Error(`run 7z fail `) + } +} + async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOptions, artifacts: Array, nameToTarget: Map) { const appInfo = packager.appInfo let squirrel = false @@ -390,13 +412,10 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp } const packageFile = artifacts.find(it => it.file.endsWith("-full.nupkg"))!.file - const unZipper = new DecompressZip(packageFile) - const fileDescriptors = await unZipper.getFiles() - - // we test app-update.yml separately, don't want to complicate general assert (yes, it is not good that we write app-update.yml for squirrel.windows if we build nsis and squirrel.windows in parallel, but as squirrel.windows is deprecated, it is ok) + const rawFiles: string[] = await listNupkgContents(packageFile) const files = pathSorter( - fileDescriptors - .map(it => toSystemIndependentPath(it.path)) + rawFiles + .map(it => toSystemIndependentPath(it)) .filter( it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp") && !it.endsWith("app-update.yml") && !it.includes("/inspector/") @@ -406,6 +425,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp expect(files).toMatchSnapshot() if (checkOptions == null) { + const unZipper = new DecompressZip(packageFile) + const fileDescriptors = await unZipper.getFiles() await unZipper.extractFile(fileDescriptors.filter(it => it.path === "TestApp.nuspec")[0], { path: path.dirname(packageFile), })