Skip to content

Commit b74def2

Browse files
committed
configuring the test fixture
1 parent a7916f7 commit b74def2

10 files changed

+51
-147
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
6+
"dev": "next dev --port 5432",
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",

playwright.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default defineConfig({
2424
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
2525
use: {
2626
/* Base URL to use in actions like `await page.goto('/')`. */
27-
// baseURL: 'http://127.0.0.1:3000',
27+
baseURL: "http://localhost:5432/",
2828

2929
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3030
trace: "on-first-retry",
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function App() {
2+
return <div>second test</div>;
3+
}

src/pages/another-test/second.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test, expect } from "@testing";
2+
3+
test.describe("the second test", () => {
4+
test("has correct content", async ({ page }) => {
5+
await expect(await page.innerText("body")).toContain("second test");
6+
});
7+
});

src/pages/api/hello.ts

-13
This file was deleted.

src/pages/example.page.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function App() {
2+
return <div>Hello world</div>;
3+
}

src/pages/example.spec.ts

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
import { test, expect } from "@playwright/test";
1+
import { test, expect } from "@testing";
22

3-
test("has title", async ({ page }) => {
4-
await page.goto("https://playwright.dev/");
5-
6-
// Expect a title "to contain" a substring.
7-
await expect(page).toHaveTitle(/Playwright/);
8-
});
9-
10-
test("get started link", async ({ page }) => {
11-
await page.goto("https://playwright.dev/");
12-
13-
// Click the get started link.
14-
await page.getByRole("link", { name: "Get started" }).click();
15-
16-
// Expects page to have a heading with the name of Installation.
17-
await expect(
18-
page.getByRole("heading", { name: "Installation" })
19-
).toBeVisible();
3+
test("Main example has corrent content", async ({ page }) => {
4+
await expect(await page.innerText("body")).toContain("Hello world");
205
});

src/pages/index.tsx

-114
This file was deleted.

test-fixtures.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {
2+
test as base,
3+
expect,
4+
PlaywrightTestArgs,
5+
PlaywrightTestOptions,
6+
Page,
7+
} from "@playwright/test";
8+
9+
export * from "@playwright/test";
10+
export { expect };
11+
12+
type TestExtras = {};
13+
14+
export const test = base.extend<
15+
PlaywrightTestArgs &
16+
PlaywrightTestOptions & {
17+
page: Page & TestExtras;
18+
}
19+
>({
20+
//@ts-ignore
21+
page: async ({ baseURL, page }, use, testInfo) => {
22+
const testFilePath = testInfo.titlePath[0];
23+
24+
const fileName = testFilePath.replace(".spec.ts", "");
25+
26+
const url = `${baseURL}${fileName}`;
27+
28+
await page.goto(url);
29+
30+
await use(page);
31+
},
32+
});

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"jsx": "preserve",
1414
"incremental": true,
1515
"paths": {
16+
"@testing": ["./test-fixtures"],
1617
"@/*": ["./src/*"]
1718
}
1819
},

0 commit comments

Comments
 (0)