Skip to content

Commit

Permalink
test: snapshot friendly "ustom buildResources" test
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 22, 2017
1 parent d65f8c3 commit 1e97ab7
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 95 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"7zip-bin": "^2.0.4",
"ajv": "^5.0.2-beta",
"ajv-keywords": "^1.5.1",
"ajv-keywords": "^2.0.1-beta.0",
"archiver": "^1.3.0",
"asar-electron-builder": "^0.13.5",
"aws-sdk": "^2.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"ajv": "^5.0.2-beta",
"ajv-keywords": "^1.5.1",
"ajv-keywords": "^2.0.1-beta.0",
"7zip-bin": "^2.0.4",
"asar-electron-builder": "^0.13.5",
"bluebird-lst": "^1.0.1",
Expand Down
46 changes: 4 additions & 42 deletions test/out/__snapshots__/BuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -238,57 +238,19 @@ Object {
}
`;
exports[`custom buildResources dir 1`] = `
exports[`custom buildResources and output dirs: linux 1`] = `
Array [
Object {
"file": "latest-mac.json",
},
Object {
"file": "Test App ßW-1.1.0.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
Object {
"file": "Test App ßW-1.1.0-mac.zip",
"safeArtifactName": "TestApp-1.1.0-mac.zip",
},
]
`;
exports[`custom buildResources dir 2`] = `
Array [
"Test App ßW Setup 1.1.0.exe",
]
`;
exports[`custom buildResources dir 3`] = `
Array [
"TestApp-Setup-1.1.0.exe",
]
`;
exports[`custom output dir 1`] = `
Array [
Object {
"file": "latest-mac.json",
},
Object {
"file": "Test App ßW-1.1.0.dmg",
"safeArtifactName": "TestApp-1.1.0.dmg",
},
Object {
"file": "Test App ßW-1.1.0-mac.zip",
"safeArtifactName": "TestApp-1.1.0-mac.zip",
},
"TestApp-1.1.0-x86_64.AppImage",
]
`;
exports[`custom output dir 2`] = `
exports[`custom buildResources and output dirs: win 1`] = `
Array [
"Test App ßW Setup 1.1.0.exe",
]
`;
exports[`custom output dir 3`] = `
exports[`custom buildResources and output dirs: win 2`] = `
Array [
"TestApp-Setup-1.1.0.exe",
]
Expand Down
49 changes: 22 additions & 27 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,29 @@ test("cli", async () => {
expect(parseExtraMetadata("--em.foo=bar"))
})

// only dir - avoid DMG
test("custom buildResources dir", app({
targets: getPossiblePlatforms(),
config: {
directories: {
buildResources: "custom"
}
},
}, {
projectDirCreated: projectDir => BluebirdPromise.all([
move(path.join(projectDir, "build"), path.join(projectDir, "custom"))
])
}))
function createBuildResourcesTest(platform: Platform) {
return app({
// only dir - avoid DMG
targets: platform.createTarget(platform === Platform.MAC ? DIR_TARGET : null),
config: {
directories: {
buildResources: "custom",
output: "customDist",
// https://github.com/electron-userland/electron-builder/issues/601
app: ".",
}
},
}, {
packed: async context => {
await assertThat(path.join(context.projectDir, "customDist")).isDirectory()
},
projectDirCreated: projectDir => move(path.join(projectDir, "build"), path.join(projectDir, "custom"))
})
}

test("custom output dir", app({
targets: getPossiblePlatforms(),
config: {
directories: {
output: "customDist",
// https://github.com/electron-userland/electron-builder/issues/601
app: ".",
}
},
}, {
packed: async context => {
await assertThat(path.join(context.projectDir, "customDist")).isDirectory()
}
}))
test.ifNotWindows("custom buildResources and output dirs: mac", createBuildResourcesTest(Platform.MAC))
test.ifNotCiMac("custom buildResources and output dirs: win", createBuildResourcesTest(Platform.WINDOWS))
test.ifNotWindows("custom buildResources and output dirs: linux", createBuildResourcesTest(Platform.LINUX))

test("build in the app package.json", appTwoThrows(allPlatforms(), {
projectDirCreated: it => modifyPackageJson(it, data => {
Expand Down
25 changes: 4 additions & 21 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,30 +216,13 @@ async function packAndCheck(outDir: string, packagerOptions: PackagerOptions, ch
}

async function checkLinuxResult(outDir: string, packager: Packager, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>, arch: Arch, nameToTarget: Map<String, Target>) {
const appInfo = packager.appInfo

function getExpected(): Array<string> {
const result: Array<string> = []
for (const target of nameToTarget.keys()) {
if (target === "appimage") {
result.push(`${appInfo.name}-${appInfo.version}-${arch === Arch.x64 ? "x86_64" : Arch[arch]}.AppImage`)
}
else if (target === "deb" || target === "snap") {
result.push(`${appInfo.name}_${appInfo.version}_${arch === Arch.x64 ? "amd64" : Arch[arch]}.${target}`)
}
else {
result.push(`TestApp-${appInfo.version}.${target}`)
}
}
return result
}

assertThat(getFileNames(artifacts)).containsAll(getExpected())
expect(getFileNames(artifacts)).toMatchSnapshot()

if (!nameToTarget.has("deb")) {
return
}

const appInfo = packager.appInfo
const productFilename = appInfo.productFilename
const expectedContents = pathSorter(expectedLinuxContents.map(it => {
if (it === "/opt/TestApp/TestApp") {
Expand Down Expand Up @@ -324,13 +307,13 @@ async function checkMacResult(packager: Packager, packagerOptions: PackagerOptio
}

function getFileNames(list: Array<ArtifactCreated>): Array<string> {
return list.map(it => path.basename(it.file))
return list.map(it => path.basename(it.file)).sort()
}

async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>, nameToTarget: Map<String, Target>) {
const appInfo = packager.appInfo

expect(getFileNames(artifacts).sort()).toMatchSnapshot()
expect(getFileNames(artifacts)).toMatchSnapshot()
expect(artifacts.map(it => it.safeArtifactName).filter(it => it != null).sort()).toMatchSnapshot()

let squirrel = false
Expand Down
1 change: 1 addition & 0 deletions test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ async function runTests() {
}, rootDir, (result: any) => {
const code = !result || result.success ? 0 : 1
removeSync(TEST_DIR)
console.log(`Failed, exit code ${code}`)
process.exitCode = code
process.on("exit", () => {
return process.exit(code)
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ acorn@^4.0.4:
version "4.0.11"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"

ajv-keywords@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"
ajv-keywords@^2.0.1-beta.0:
version "2.0.1-beta.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.0.1-beta.0.tgz#aa242a131ae362b8bf72ff9ad07b24d0918cdfab"

ajv@^5.0.2-beta:
version "5.0.2-beta.0"
Expand Down

0 comments on commit 1e97ab7

Please sign in to comment.