mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
desktop: add build retrying when running tests
This commit is contained in:
@@ -18,13 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import { cp, mkdir, readFile, rm, rmdir, writeFile } from "fs/promises";
|
import { cp, mkdir, readFile, rm, writeFile } from "fs/promises";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import path, { join, resolve } from "path";
|
import path, { join, resolve } from "path";
|
||||||
import { _electron as electron } from "playwright";
|
import { _electron as electron } from "playwright";
|
||||||
import slugify from "slugify";
|
import slugify from "slugify";
|
||||||
import { test as vitestTest, TestContext } from "vitest";
|
import { test as vitestTest, TestContext } from "vitest";
|
||||||
import { patchBetterSQLite3 } from "../scripts/patch-better-sqlite3.mjs";
|
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
@@ -71,8 +70,8 @@ export async function testCleanup(context: TestContext) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
await ctx.app.close();
|
await ctx.app.close();
|
||||||
await rmdir(ctx.userDataDir, { recursive: true });
|
await rm(ctx.userDataDir, { force: true, recursive: true });
|
||||||
await rmdir(ctx.outputDir, { recursive: true });
|
await rm(ctx.outputDir, { force: true, recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildAndLaunchApp(options?: TestOptions): Promise<AppContext> {
|
async function buildAndLaunchApp(options?: TestOptions): Promise<AppContext> {
|
||||||
@@ -139,6 +138,7 @@ async function launchApp(executablePath: string, packageName: string) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let MAX_RETRIES = 3;
|
||||||
async function buildApp({
|
async function buildApp({
|
||||||
version,
|
version,
|
||||||
outputDir
|
outputDir
|
||||||
@@ -159,7 +159,7 @@ async function buildApp({
|
|||||||
"--publish=never"
|
"--publish=never"
|
||||||
];
|
];
|
||||||
if (version) args.push(`--c.extraMetadata.version=${version}`);
|
if (version) args.push(`--c.extraMetadata.version=${version}`);
|
||||||
|
try {
|
||||||
execSync(`npx ${args.join(" ")}`, {
|
execSync(`npx ${args.join(" ")}`, {
|
||||||
stdio: IS_DEBUG ? "inherit" : "ignore",
|
stdio: IS_DEBUG ? "inherit" : "ignore",
|
||||||
env: {
|
env: {
|
||||||
@@ -170,6 +170,12 @@ async function buildApp({
|
|||||||
NN_OUTPUT_DIR: sourceDir
|
NN_OUTPUT_DIR: sourceDir
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (--MAX_RETRIES) {
|
||||||
|
console.log("retrying...");
|
||||||
|
return await buildApp({ outputDir, version });
|
||||||
|
} else throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return process.platform === "win32"
|
return process.platform === "win32"
|
||||||
? await copyBuildWindows(sourceDir, outputDir, productName, version)
|
? await copyBuildWindows(sourceDir, outputDir, productName, version)
|
||||||
@@ -193,7 +199,12 @@ async function copyBuildLinux(
|
|||||||
"resources",
|
"resources",
|
||||||
version
|
version
|
||||||
);
|
);
|
||||||
return resolve(__dirname, "..", appDir, productName);
|
return resolve(
|
||||||
|
__dirname,
|
||||||
|
"..",
|
||||||
|
appDir,
|
||||||
|
productName.toLowerCase().replace(/\s+/g, "-")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyBuildWindows(
|
async function copyBuildWindows(
|
||||||
|
|||||||
Reference in New Issue
Block a user