Skip to content

Commit

Permalink
test: asarUnpack unpacks parent directory when file is specified elec…
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 2, 2017
1 parent fe137fc commit a602210
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
53 changes: 25 additions & 28 deletions test/src/globTest.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
import { outputFile, symlink } from "fs-extra-p"
import { assertPack, modifyPackageJson, app } from "./helpers/packTester"
import { outputFile, symlink, writeFile } from "fs-extra-p"
import { assertPack, modifyPackageJson, app, PackedContext } from "./helpers/packTester"
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { Platform, DIR_TARGET } from "electron-builder"
import { statFile } from "asar-electron-builder"

function createFiles(appDir: string) {
return BluebirdPromise.all([
outputFile(path.join(appDir, "assets", "file"), "data"),
outputFile(path.join(appDir, "b2", "file"), "data"),
outputFile(path.join(appDir, "do-not-unpack-dir", "file.json"), "{}")
.then(() => writeFile(path.join(appDir, "do-not-unpack-dir", "must-be-not-unpacked"), "{}")),
])
}

test.ifDevOrLinuxCi("unpackDir one", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
asarUnpack: ["assets", "b2"],
asarUnpack: ["assets", "b2", "do-not-unpack-dir/file.json"],
}
}, {
projectDirCreated: projectDir => {
return BluebirdPromise.all([
outputFile(path.join(projectDir, "assets", "file"), "data"),
outputFile(path.join(projectDir, "b2", "file"), "data"),
])
},
packed: context => {
return BluebirdPromise.all([
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "assets")).isDirectory(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "b2")).isDirectory(),
])
},
projectDirCreated: createFiles,
packed: assertDirs,
}))

function assertDirs(context: PackedContext) {
return BluebirdPromise.all([
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "assets")).isDirectory(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "b2")).isDirectory(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "do-not-unpack-dir", "file.json")).isFile(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "do-not-unpack-dir", "must-be-not-unpacked")).doesNotExist(),
])
}
test.ifDevOrLinuxCi("unpackDir", () => {
return assertPack("test-app", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
asarUnpack: ["assets", "b2"],
asarUnpack: ["assets", "b2", "do-not-unpack-dir/file.json"],
}
}, {
projectDirCreated: projectDir => {
return BluebirdPromise.all([
outputFile(path.join(projectDir, "app", "assets", "file"), "data"),
outputFile(path.join(projectDir, "app", "b2", "file"), "data"),
])
},
packed: context => {
return BluebirdPromise.all([
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "assets")).isDirectory(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "b2")).isDirectory(),
])
},
projectDirCreated: projectDir => createFiles(path.join(projectDir, "app")),
packed: assertDirs,
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface AssertPackOptions {
readonly npmInstallBefore?: boolean
}

interface PackedContext {
export interface PackedContext {
readonly projectDir: string,
readonly outDir: string

Expand Down

0 comments on commit a602210

Please sign in to comment.