Skip to content

Commit

Permalink
get file list by 7z
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp committed Jul 18, 2024
1 parent 5170902 commit 9dfcda0
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArtifactCreated>, nameToTarget: Map<string, Target>) {
const appInfo = packager.appInfo
let squirrel = false
Expand All @@ -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/")
Expand All @@ -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),
})
Expand Down

0 comments on commit 9dfcda0

Please sign in to comment.