diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index a77b518f642..33ceace5c24 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -1,5 +1,5 @@ import test from "./helpers/avaEx" -import { assertPack } from "./helpers/packTester" +import { assertPack, modifyPackageJson } from "./helpers/packTester" import { move, writeJson, readJson } from "fs-extra-p" import { Promise as BluebirdPromise } from "bluebird" import * as path from "path" @@ -24,15 +24,13 @@ test("custom app dir", async () => { await assertPack("test-app-one", getPossiblePlatforms(), { // speed up tests, we don't need check every arch arch: process.arch - }, true, async (projectDir) => { - const file = path.join(projectDir, "package.json") - const data = await readJson(file) - data.directories = { - buildResources: "custom" - } - - return await BluebirdPromise.all([ - writeJson(file, data), + }, true, (projectDir) => { + return BluebirdPromise.all([ + modifyPackageJson(projectDir, data => { + data.directories = { + buildResources: "custom" + } + }), move(path.join(projectDir, "build"), path.join(projectDir, "custom")) ]) }) @@ -42,12 +40,10 @@ test("productName with space", async () => { await assertPack("test-app-one", getPossiblePlatforms(), { // speed up tests, we don't need check every arch arch: process.arch - }, true, async (projectDir) => { - const file = path.join(projectDir, "package.json") - const data = await readJson(file) - data.productName = "Test App" - - return await writeJson(file, data) + }, true, (projectDir) => { + return modifyPackageJson(projectDir, data => { + data.productName = "Test App" + }) }) }) diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index d9af7632f52..4c5467e668d 100644 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -1,4 +1,4 @@ -import { copy, emptyDir, remove } from "fs-extra-p" +import { copy, emptyDir, remove, writeJson, readJson } from "fs-extra-p" import * as assertThat from "should/as-function" import * as path from "path" import { parse as parsePlist } from "plist" @@ -164,4 +164,11 @@ async function getContents(path: string, productName: string) { .map(it => it.length === 0 ? null : it.substring(it.indexOf(".") + 1)) .filter(it => it != null && !(it.startsWith(`/opt/${productName}/locales/`) || it.startsWith(`/opt/${productName}/libgcrypt`))) ) +} + +export async function modifyPackageJson(projectDir: string, task: (data: any) => void): Promise { + const file = path.join(projectDir, "package.json") + const data = await readJson(file) + task(data) + return await writeJson(file, data) } \ No newline at end of file