mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Get rid of separate server for commits listing test
Use a fixture for that instead. This simplifies the test setup.
This commit is contained in:
+5
-15
@@ -82,21 +82,11 @@ const config: PlaywrightTestConfig = {
|
||||
},
|
||||
],
|
||||
|
||||
webServer: [
|
||||
{
|
||||
// Use preview server (pre-built app) for main server - much faster startup
|
||||
command: "npm run serve -- --strictPort --port 3001",
|
||||
port: 3001,
|
||||
},
|
||||
// Required by test tests/e2e/repo/commits.spec.ts "loading more commits, adds them to the commits list"
|
||||
// Keep dev server here since it needs custom runtime config
|
||||
{
|
||||
command: "npm run start -- --strictPort --port 3002",
|
||||
port: 3002,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
env: { COMMITS_PER_PAGE: "4" },
|
||||
},
|
||||
],
|
||||
webServer: {
|
||||
// Use preview server (pre-built app) for main server - much faster startup
|
||||
command: "npm run serve -- --strictPort --port 3001",
|
||||
port: 3001,
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
aliceMainCommitCount,
|
||||
aliceMainCommitMessage,
|
||||
bobMainCommitCount,
|
||||
commitsUrl,
|
||||
expect,
|
||||
gitOptions,
|
||||
shortAliceHead,
|
||||
@@ -89,12 +90,12 @@ test("peer and branch switching", async ({ page }) => {
|
||||
test("loading more commits, adds them to the commits list", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`http://localhost:3002${sourceBrowsingUrl}`);
|
||||
await page.goto(commitsUrl);
|
||||
await page.getByRole("button", { name: "Commits" }).click();
|
||||
await expect(page.locator("div > div > .teaser")).toHaveCount(4);
|
||||
await expect(page.locator("div > div > .teaser")).toHaveCount(30);
|
||||
|
||||
await page.getByRole("button", { name: "More" }).click();
|
||||
await expect(page.locator("div > div > .teaser")).toHaveCount(8);
|
||||
await expect(page.locator("div > div > .teaser")).toHaveCount(31);
|
||||
});
|
||||
|
||||
test("commit messages with double colon not converted into single colon", async ({
|
||||
|
||||
@@ -574,6 +574,49 @@ export async function createMarkdownFixture(peer: RadiclePeer) {
|
||||
);
|
||||
}
|
||||
|
||||
export async function createCommitsFixture(peer: RadiclePeer) {
|
||||
await Fs.mkdir(Path.join(tmpDir, "repos", "commits"));
|
||||
const { repoFolder } = await createRepo(peer, { name: "commits" });
|
||||
|
||||
// Create 30 more commits for a total of 31 using git fast-import for speed
|
||||
const baseDate = 1671125284; // Same as Alice's date
|
||||
const authorName = gitOptions["alice"].GIT_AUTHOR_NAME;
|
||||
const authorEmail = gitOptions["alice"].GIT_AUTHOR_EMAIL;
|
||||
|
||||
// Get the initial commit hash to use as parent
|
||||
const { stdout: initialCommit } = await peer.git(["rev-parse", "HEAD"], {
|
||||
cwd: repoFolder,
|
||||
});
|
||||
|
||||
// Build fast-import data stream
|
||||
let fastImportData = "";
|
||||
for (let i = 1; i <= 30; i++) {
|
||||
const commitDate = baseDate + i;
|
||||
const message = `Commit ${i}`;
|
||||
const parent = i === 1 ? initialCommit.trim() : `:${i - 1}`;
|
||||
fastImportData += `commit refs/heads/main
|
||||
mark :${i}
|
||||
author ${authorName} <${authorEmail}> ${commitDate} +0000
|
||||
committer ${authorName} <${authorEmail}> ${commitDate} +0000
|
||||
data ${message.length}
|
||||
${message}
|
||||
from ${parent}
|
||||
|
||||
`;
|
||||
}
|
||||
|
||||
// Write to temp file and pipe it to git fast-import
|
||||
const fastImportFile = Path.join(tmpDir, "repos", "commits-fast-import");
|
||||
await Fs.writeFile(fastImportFile, fastImportData);
|
||||
|
||||
await peer.spawn("bash", ["-c", `git fast-import --force < "${fastImportFile}"`], {
|
||||
cwd: repoFolder,
|
||||
});
|
||||
|
||||
await Fs.unlink(fastImportFile);
|
||||
await peer.git(["push", "rad"], { cwd: repoFolder });
|
||||
}
|
||||
|
||||
export const aliceMainHead = "7babd25a74eb3752ec24672b5edf0e7ecb4daf24";
|
||||
export const aliceMainCommitMessage =
|
||||
"Verify that crate::DoubleColon::should_work()";
|
||||
@@ -589,9 +632,11 @@ export const shortBobHead = formatCommit(bobHead);
|
||||
export const sourceBrowsingRid = "rad:z4BwwjPCFNVP27FwVbDFgwVwkjcir";
|
||||
export const cobRid = "rad:z3fpY7nttPPa6MBnAv2DccHzQJnqe";
|
||||
export const markdownRid = "rad:z2tchH2Ti4LxRKdssPQYs6VHE5rsg";
|
||||
export const commitsRid = "rad:z2ysBeUDZnHejYvaToxYopZiUA3oy";
|
||||
export const sourceBrowsingUrl = `/nodes/localhost/${sourceBrowsingRid}`;
|
||||
export const cobUrl = `/nodes/localhost/${cobRid}`;
|
||||
export const markdownUrl = `/nodes/localhost/${markdownRid}`;
|
||||
export const commitsUrl = `/nodes/localhost/${commitsRid}`;
|
||||
export const shortNodeRemote = "z6MktU…1xB22S";
|
||||
export const gitOptions = {
|
||||
alice: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import {
|
||||
defaultConfig,
|
||||
createCobsFixture,
|
||||
createCommitsFixture,
|
||||
createMarkdownFixture,
|
||||
createSourceBrowsingFixture,
|
||||
gitOptions,
|
||||
@@ -53,12 +54,16 @@ export default async function globalSetup(): Promise<() => void> {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Build the app once before running tests to avoid compilation
|
||||
// overhead on each worker.
|
||||
console.log("Building the app for tests...");
|
||||
const { execa: exec } = await import("execa");
|
||||
await exec("npm", ["run", "build"], { stdio: "inherit" });
|
||||
console.log("Build complete");
|
||||
if (!process.env.SKIP_BUILD) {
|
||||
// Build the app once before running tests to avoid compilation
|
||||
// overhead on each worker.
|
||||
console.log("Building the app for tests...");
|
||||
const { execa: exec } = await import("execa");
|
||||
await exec("npm", ["run", "build"], { stdio: "inherit" });
|
||||
console.log("Build complete");
|
||||
} else {
|
||||
console.log("Skipping build. Set SKIP_BUILD to skip this");
|
||||
}
|
||||
|
||||
if (!process.env.SKIP_FIXTURE_CREATION) {
|
||||
console.log(
|
||||
@@ -108,6 +113,8 @@ export default async function globalSetup(): Promise<() => void> {
|
||||
await createMarkdownFixture(palm);
|
||||
console.log("Creating cobs fixture");
|
||||
await createCobsFixture(peerManager, palm);
|
||||
console.log("Creating commits fixture");
|
||||
await createCommitsFixture(palm);
|
||||
console.log("All fixtures created");
|
||||
} catch (error) {
|
||||
console.log("");
|
||||
|
||||
Reference in New Issue
Block a user