diff --git a/README.md b/README.md index debd071..65c6d38 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ NEXTAUTH_URL=http://localhost:3000 ### Running tests -You can run tests locally with _npm run test:e2e_ +Run _npm init playwright@latest_ then copy over _drizzle.config.ts_ to your repository. + +Now you can run tests locally with _npm run test:e2e_ ### Assumptions that tests make @@ -63,23 +65,23 @@ Tests are making several assumptions on your UI: Eg. the below tests assumes that the url of the creation form is _/blogs/new_, form controls have the labels and eg. the creation button has test id _create-blog-button_: ```js -test("logged in user can create a blog", async ({ page }) => { - await loginUser(page, "testuser", "testpass123") +test('logged in user can create a blog', async ({ page }) => { + await loginUser(page, 'testuser', 'testpass123') - await page.goto("/blogs/new") - await page.getByLabel("Title", { exact: true }).fill("Test Blog") - await page.getByLabel("Author", { exact: true }).fill("Test Author") - await page.getByLabel("URL", { exact: true }).fill("http://testblog.com") - await page.getByTestId("create-blog-button").click() + await page.goto('/blogs/new') + await page.getByLabel('Title', { exact: true }).fill('Test Blog') + await page.getByLabel('Author', { exact: true }).fill('Test Author') + await page.getByLabel('URL', { exact: true }).fill('http://testblog.com') + await page.getByTestId('create-blog-button').click() // Should redirect to blogs page - await expect(page).toHaveURL("/blogs") + await expect(page).toHaveURL('/blogs') // Should show success notification - await expect(page.getByTestId("notification")).toBeVisible() + await expect(page.getByTestId('notification')).toBeVisible() // Blog should appear in the list - await expect(page.getByTestId("blogs-list")).toContainText("Test Blog") + await expect(page.getByTestId('blogs-list')).toContainText('Test Blog') }) ``` diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..7f41034 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,18 @@ +export default defineConfig({ + testDir: './tests', + fullyParallel: false, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 0, + workers: 1, + reporter: 'html', + use: { + baseURL: 'http://localhost:3000', + trace: 'on-first-retry', + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +})