Skip to content

Commit

Permalink
fix: use faker instead of Math.random, simply playwright config
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Oct 1, 2024
1 parent 792b86a commit 52c5d3f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 29 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@commitlint/config-conventional": "^19.4.1",
"@commitlint/cz-commitlint": "^19.4.0",
"@eslint-react/eslint-plugin": "^1.14.0",
"@faker-js/faker": "^9.0.3",
"@next/bundle-analyzer": "^14.2.9",
"@next/eslint-plugin-next": "^14.2.9",
"@percy/cli": "1.29.3",
Expand Down
22 changes: 9 additions & 13 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ export default defineConfig({
testMatch: '*.@(spec|e2e).?(c|m)[jt]s?(x)',
// Timeout per test
timeout: 30 * 1000,
// Run tests in files in parallel on CI
fullyParallel: !!process.env.CI,
// Fail the build on CI if you accidentally left test.only in the source code.
forbidOnly: !!process.env.CI,
// Retry on CI only
retries: process.env.CI ? 2 : 0,
// Opt out of parallel tests on CI
workers: process.env.CI ? 1 : undefined,
// Limit the number of failures on CI to save resources
maxFailures: process.env.CI ? 10 : undefined,
// Reporter to use. See https://playwright.dev/docs/test-reporters
reporter: process.env.CI ? 'github' : 'list',

expect: {
// Set timeout for async expect matchers
timeout: 10 * 1000,
},

// Run your local dev server before starting the tests:
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
webServer: {
Expand All @@ -44,7 +41,10 @@ export default defineConfig({
baseURL,

// Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer
trace: 'on-first-retry',
trace: process.env.CI ? 'retain-on-failure' : undefined,

// Record videos when retrying the failed test.
video: process.env.CI ? 'retain-on-failure' : undefined,
},

projects: [
Expand All @@ -58,10 +58,6 @@ export default defineConfig({
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
]
: []),
],
Expand Down
3 changes: 3 additions & 0 deletions src/app/[locale]/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function AuthLayout(props: {
let signInUrl = '/sign-in';
let signUpUrl = '/sign-up';
let dashboardUrl = '/dashboard';
let afterSignOutUrl = '/';

if (props.params.locale === 'fr') {
clerkLocale = frFR;
Expand All @@ -20,6 +21,7 @@ export default function AuthLayout(props: {
signInUrl = `/${props.params.locale}${signInUrl}`;
signUpUrl = `/${props.params.locale}${signUpUrl}`;
dashboardUrl = `/${props.params.locale}${dashboardUrl}`;
afterSignOutUrl = `/${props.params.locale}${afterSignOutUrl}`;
}

return (
Expand All @@ -29,6 +31,7 @@ export default function AuthLayout(props: {
signUpUrl={signUpUrl}
signInFallbackRedirectUrl={dashboardUrl}
signUpFallbackRedirectUrl={dashboardUrl}
afterSignOutUrl={afterSignOutUrl}
>
{props.children}
</ClerkProvider>
Expand Down
2 changes: 0 additions & 2 deletions src/templates/BaseTemplate.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import messages from '@/locales/en.json';

import { BaseTemplate } from './BaseTemplate';

// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
const meta = {
title: 'Example/BaseTemplate',
component: BaseTemplate,
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
layout: 'fullscreen',
},
tags: ['autodocs'],
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/Counter.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert';

import { faker } from '@faker-js/faker';
import { expect, test } from '@playwright/test';

test.describe('Counter', () => {
Expand All @@ -26,7 +27,7 @@ test.describe('Counter', () => {
}) => {
// `x-e2e-random-id` is used for end-to-end testing to make isolated requests
// The default value is 0 when there is no `x-e2e-random-id` header
const e2eRandomId = Math.floor(Math.random() * 1000000000) + 1;
const e2eRandomId = faker.number.int({ max: 1000000 });
await page.setExtraHTTPHeaders({
'x-e2e-random-id': e2eRandomId.toString(),
});
Expand Down
22 changes: 12 additions & 10 deletions tests/e2e/I18n.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { expect, test } from '@playwright/test';

test.describe('I18n', () => {
test.describe('Static pages', () => {
test('should take screenshot of the homepage', async ({ page }) => {
test.describe('Language Switching', () => {
test('should switch language from English to French using dropdown and verify text on the homepage', async ({ page }) => {
await page.goto('/');

await expect(
page.getByRole('heading', { name: 'Boilerplate Code for Your Next.js Project with Tailwind CSS' }),
).toBeVisible();

await page.getByRole('link', { name: 'About' }).click();
await page.getByLabel('lang-switcher').selectOption('fr');

await expect(page.getByText('Welcome to our About page')).toBeVisible();
await expect(
page.getByRole('heading', { name: 'Code de démarrage pour Next.js avec Tailwind CSS' }),
).toBeVisible();
});

await page.getByRole('combobox', { name: 'lang-switcher' }).selectOption({ label: 'FR' });
test('should switch language from English to French using URL and verify text on the sign-in page', async ({ page }) => {
await page.goto('/sign-in');

await expect(page.getByText('Bienvenue sur notre page À propos')).toBeVisible();
await expect(page.getByText('Email address')).toBeVisible();

await page.getByRole('link', { name: 'Accueil' }).click();
await page.goto('/fr/sign-in');

await expect(
page.getByRole('heading', { name: 'Code de démarrage pour Next.js avec Tailwind CSS' }),
).toBeVisible();
await expect(page.getByText('Adresse e-mail')).toBeVisible();
});
});
});
2 changes: 1 addition & 1 deletion tests/e2e/Visual.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test.describe('Visual testing', () => {
await percySnapshot(page, 'Portfolio details');
});

test('i18n fr language', async ({ page }) => {
test('should take screenshot of the French homepage', async ({ page }) => {
await page.goto('/fr');

await expect(
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/Counter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { faker } from '@faker-js/faker';
import { expect, test } from '@playwright/test';

test.describe('Counter', () => {
Expand Down Expand Up @@ -43,7 +44,7 @@ test.describe('Counter', () => {
}) => {
// `x-e2e-random-id` is used for end-to-end testing to make isolated requests
// The default value is 0 when there is no `x-e2e-random-id` header
const e2eRandomId = Math.floor(Math.random() * 1000000000) + 1;
const e2eRandomId = faker.number.int({ max: 1000000 });

let counter = await request.put('/api/counter', {
data: {
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
}
]
},
"exclude": ["./out/**/*", "./node_modules/**/*", "**/*.spec.ts", "**/*.e2e.ts"],
"exclude": [
"./out/**/*",
"./node_modules/**/*",
"**/*.spec.ts",
"**/*.e2e.ts"
],
"include": [
"next-env.d.ts",
"**/*.ts",
Expand Down

0 comments on commit 52c5d3f

Please sign in to comment.