From 1e97ab718206663c4a9145be0fbd56b30522b06f Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 22 Feb 2017 17:56:24 +0100 Subject: [PATCH] test: snapshot friendly "ustom buildResources" test --- package.json | 2 +- packages/electron-builder/package.json | 2 +- test/out/__snapshots__/BuildTest.js.snap | 46 ++-------------------- test/src/BuildTest.ts | 49 +++++++++++------------- test/src/helpers/packTester.ts | 25 ++---------- test/src/helpers/runTests.ts | 1 + yarn.lock | 6 +-- 7 files changed, 36 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index 1276fce8a2e..b85bb9e7867 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/electron-builder/package.json b/packages/electron-builder/package.json index 62b59a1aa27..be1f8a17b13 100644 --- a/packages/electron-builder/package.json +++ b/packages/electron-builder/package.json @@ -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", diff --git a/test/out/__snapshots__/BuildTest.js.snap b/test/out/__snapshots__/BuildTest.js.snap index fc24216d067..0386358bc6a 100644 --- a/test/out/__snapshots__/BuildTest.js.snap +++ b/test/out/__snapshots__/BuildTest.js.snap @@ -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", ] diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index acf1717ef91..fd62cef1917 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -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 => { diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index c2d03666394..f141211944c 100755 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -216,30 +216,13 @@ async function packAndCheck(outDir: string, packagerOptions: PackagerOptions, ch } async function checkLinuxResult(outDir: string, packager: Packager, checkOptions: AssertPackOptions, artifacts: Array, arch: Arch, nameToTarget: Map) { - const appInfo = packager.appInfo - - function getExpected(): Array { - const result: Array = [] - 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") { @@ -324,13 +307,13 @@ async function checkMacResult(packager: Packager, packagerOptions: PackagerOptio } function getFileNames(list: Array): Array { - 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, nameToTarget: Map) { 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 diff --git a/test/src/helpers/runTests.ts b/test/src/helpers/runTests.ts index c52c3392705..94ac44844a3 100755 --- a/test/src/helpers/runTests.ts +++ b/test/src/helpers/runTests.ts @@ -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) diff --git a/yarn.lock b/yarn.lock index 9495e8a7f04..571da26ab99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"