Skip to content

Commit

Permalink
test: isolate Playwright tests (#102)
Browse files Browse the repository at this point in the history
* test: isolate Playwright tests

* ci: try multiple workers

* feat: attempt persisted, shared repository

* test: implement own prismic client

* test: remove slice machine from e2e projects

* test: create storage state file on start

* test: remove console.log

* test: isolate xsrf token

* test: fix preview tests

* test: refactor

* test: add teardown

* chore: use workspaces

* ci: fix installation
  • Loading branch information
angeloashmore authored Dec 19, 2024
1 parent 3228dc0 commit 89366dc
Show file tree
Hide file tree
Showing 45 changed files with 1,221 additions and 6,194 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.node == 22
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- run: npm ci --prefix e2e-projects/app-router
- run: npm ci --prefix e2e-projects/pages-router
- run: npm run e2e
env:
PLAYWRIGHT_PRISMIC_USERNAME: ${{ secrets.PLAYWRIGHT_PRISMIC_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ coverage
/playwright-report/
/blob-report/
/playwright/.cache/
/tests/.storage-state.json
4 changes: 2 additions & 2 deletions e2e-projects/app-router/app/PrismicNextImage/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PrismicNextImage } from "@prismicio/next";
import { isFilled } from "@prismicio/client";
import { PrismicNextImage } from "@prismicio/next";
import assert from "assert";

import { createClient } from "@/prismicio";

export default async function Page() {
const client = createClient();
const client = await createClient();
const { data: tests } = await client.getSingle("image_test");

assert(
Expand Down
3 changes: 2 additions & 1 deletion e2e-projects/app-router/app/PrismicNextLink/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Link from "next/link";
import { isFilled } from "@prismicio/client";
import { PrismicNextLink } from "@prismicio/next";
import assert from "assert";

import { createClient } from "@/prismicio";

export default async function Page() {
const client = createClient();
const client = await createClient();
const { data: tests } = await client.getSingle("link_test");
assert(isFilled.contentRelationship(tests.document) && tests.document.url);
const doc = await client.getByID(tests.document.id);
Expand Down
13 changes: 4 additions & 9 deletions e2e-projects/app-router/app/[uid]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { PrismicPreview } from "@prismicio/next";
import { NotFoundError } from "@prismicio/client";
import { notFound } from "next/navigation";

import { createClient, repositoryName } from "@/prismicio";
import { createClient } from "@/prismicio";

export default async function Page({
params,
Expand All @@ -11,16 +9,13 @@ export default async function Page({
}) {
const { uid } = await params;

const client = createClient();
const page = await client.getByUID("page", uid).catch((error) => {
if (error instanceof NotFoundError) notFound();
throw error;
});
const client = await createClient();
const page = await client.getByUID("page", uid);

return (
<>
<div data-testid="payload">{page.data.payload}</div>
<PrismicPreview repositoryName={repositoryName} />
<PrismicPreview repositoryName={client.repositoryName} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { exitPreview } from "@prismicio/next";

/** This endpoint exits a preview session. */
export function GET() {
return exitPreview();
}
5 changes: 3 additions & 2 deletions e2e-projects/app-router/app/api/custom-preview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { redirectToPreviewURL } from "@prismicio/next";

import { createClient } from "@/prismicio";

/** This endpoint handles previews that are launched from the Page Builder. */
export async function GET(request: NextRequest) {
const client = createClient();
const client = await createClient({
routes: [{ type: "page", path: "/:uid" }],
});

return await redirectToPreviewURL({ client, request });
}
1 change: 0 additions & 1 deletion e2e-projects/app-router/app/api/exit-preview/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { exitPreview } from "@prismicio/next";

/** This endpoint exits a preview session. */
export function GET() {
return exitPreview();
}
5 changes: 3 additions & 2 deletions e2e-projects/app-router/app/api/preview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { redirectToPreviewURL } from "@prismicio/next";

import { createClient } from "@/prismicio";

/** This endpoint handles previews that are launched from the Page Builder. */
export async function GET(request: NextRequest) {
const client = createClient();
const client = await createClient({
routes: [{ type: "page", path: "/:uid" }],
});

return await redirectToPreviewURL({ client, request });
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { NotFoundError } from "@prismicio/client";
import { PrismicPreview } from "@prismicio/next";
import { notFound } from "next/navigation";

import { createClient, repositoryName } from "@/prismicio";
import { createClient } from "@/prismicio";

export default async function Page({
params,
Expand All @@ -11,20 +9,14 @@ export default async function Page({
}) {
const { uid } = await params;

const client = createClient();
const page = await client.getByUID("page", uid).catch((error) => {
if (error instanceof NotFoundError) {
console.log(error.url);
notFound();
}
throw error;
});
const client = await createClient();
const page = await client.getByUID("page", uid);

return (
<>
<div data-testid="payload">{page.data.payload}</div>
<PrismicPreview
repositoryName={repositoryName}
repositoryName={client.repositoryName}
updatePreviewURL="/api/custom-preview"
exitPreviewURL="/api/custom-exit-preview"
/>
Expand Down
51 changes: 0 additions & 51 deletions e2e-projects/app-router/customtypes/image_test/index.json

This file was deleted.

81 changes: 0 additions & 81 deletions e2e-projects/app-router/customtypes/link_test/index.json

This file was deleted.

28 changes: 0 additions & 28 deletions e2e-projects/app-router/customtypes/page/index.json

This file was deleted.

Loading

0 comments on commit 89366dc

Please sign in to comment.