Skip to content

Commit 2ae807d

Browse files
authored
Merge pull request #52 from CreoWis/issue-39-e2e-capabilities
Issue 39: E2E capabilities added
2 parents 3f2dbd1 + 7f97053 commit 2ae807d

File tree

7 files changed

+191
-21
lines changed

7 files changed

+191
-21
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ yarn-error.log*
6666

6767
# typescript
6868
*.tsbuildinfo
69-
next-env.d.ts
69+
next-env.d.ts
70+
71+
# Playwright
72+
/test-results/
73+
/playwright-report/
74+
/blob-report/
75+
/playwright/.cache/

README.md

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<a href="https://github.com/CreoWis/next-js-launchpad/blob/master/LICENSE" target="blank"><img src="https://img.shields.io/github/license/CreoWis/next-js-launchpad?style=flat-square" alt="License" /></a>
2+
23
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4+
35
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
6+
47
<!-- ALL-CONTRIBUTORS-BADGE:END -->
58
<a href="https://github.com/CreoWis/next-js-launchpad/fork" target="blank">
69
<img src="https://img.shields.io/github/forks/CreoWis/next-js-launchpad?style=flat-square" alt="next-js-launchpad forks"/>
@@ -37,59 +40,67 @@ Say goodbye to setup headaches and hello to consistent code quality. Elevate you
3740
- **Prettier Plugin Sort Imports**: Organize import declarations alphabetically within groups, which can help improve readability when working on larger projects.
3841
- **Husky**: Ensure code quality and prevent bad commits with pre-commit hooks powered by Husky.
3942
- **Docker Support**: Complete Docker configuration.
40-
```bash
41-
- Start the application using this Docker command:
42-
43-
docker-compose up
44-
45-
The command will:
46-
1. Build the application container
47-
2. Install all dependencies
48-
3. Start the development server
49-
4. Make the application available on localhost
50-
```
51-
52-
- **Internationalization (i18n)**: Built-in support for multiple languages using next-intl, making it easy to create multilingual applications with locale-specific routing and translations.
53-
## Getting Started
43+
44+
```bash
45+
- Start the application using this Docker command:
46+
47+
docker-compose up
48+
49+
The command will:
50+
1. Build the application container
51+
2. Install all dependencies
52+
3. Start the development server
53+
4. Make the application available on localhost
54+
```
55+
56+
- **Internationalization (i18n)**: Built-in support for multiple languages using next-intl, making it easy to create multilingual applications with locale-specific routing and translations.
57+
58+
## Getting Started
59+
5460
> Usage
5561
5662
```bash
5763
npx create-next-app -e https://github.com/CreoWis/next-js-launchpad
5864
```
59-
65+
6066
## Internationalization (i18n)
67+
6168
NextJsLaunchpad comes with built-in internationalization support using next-intl. This integration provides:
6269

6370
- Route-based locale handling with `/[locale]/` directory structure
6471
- Easy-to-use translation hooks with `useTranslations` in server and client components.
6572

6673
Translation files are located in:
74+
6775
```bash
6876
content/
6977
├── en.json
7078
├── fr.json
7179
└── [other-locales].json
72-
```
80+
```
81+
7382
#### How to add a new language support:
7483

7584
To add a new language, we have to add the language JSON file to the content directory, which is in the root directory, that is our first step.
7685

7786
After that, we have to add the newly added language to the locales array in the navigation.ts file. Below is the content of the navigation.ts file, where we need to add the newly added language to the locales array:
87+
7888
```bash
7989
import {defineRouting} from 'next-intl/routing';
8090
import {createNavigation} from 'next-intl/navigation';
8191

8292
export const routing = defineRouting({
8393
// A list of all locales that are supported
8494
locales: ['en', 'fr', 'newLanguage'], // Add the new language code here
85-
95+
8696
// Used when no locale matches
8797
defaultLocale: 'en'
8898
});
8999

90100
export const {Link, redirect, usePathname, useRouter, getPathname} =
91101
createNavigation(routing);
92102
```
103+
93104
#### Using Strings from Language Files
94105

95106
To use strings from a language file in both **client and server** components, use the `useTranslations` hook.
@@ -101,6 +112,7 @@ To use strings from a language file in both **client and server** components, us
101112
```javascript
102113
import { useTranslations } from 'next-intl';
103114
```
115+
104116
2. **Initialize useTranslations with a section:**
105117
```javascript
106118
const t = useTranslations('Home');
@@ -110,7 +122,38 @@ To use strings from a language file in both **client and server** components, us
110122
```javascript
111123
<h1>{t('welcomeMessage')}</h1>
112124
```
113-
125+
126+
## Playwright E2E Testing
127+
128+
NextJsLaunchpad includes Playwright for robust end-to-end testing. This integration provides:
129+
130+
- **Headless and UI Testing**: Run tests in both headless mode for automation and UI mode for debugging.
131+
- **Cross-Browser Compatibility**: Test on Chromium, Firefox, and WebKit.
132+
- **API and Component Testing**: Supports API calls and frontend component interactions.
133+
134+
### Running Playwright Tests
135+
136+
To execute Playwright tests, use:
137+
138+
```shell
139+
npm run playwright
140+
```
141+
142+
### Playwright Configuration
143+
144+
Test settings are defined in:
145+
146+
```plaintext
147+
/playwright.config.ts
148+
```
149+
150+
### Test Files
151+
152+
Playwright tests are located in:
153+
154+
```plaintext
155+
/__tests__/e2e/
156+
```
114157

115158
<!-- Project should be public for the above command to work -->
116159

@@ -263,4 +306,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
263306

264307
<!-- ALL-CONTRIBUTORS-LIST:END -->
265308

266-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
309+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

__tests__/.gitkeep

Whitespace-only changes.

__tests__/e2e/example.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test, { expect } from '@playwright/test';
2+
3+
test('has title', async ({ page }) => {
4+
await page.goto('https://www.creowis.com/');
5+
await expect(page).toHaveTitle('CreoWis Technologies Private Limited');
6+
});
7+
8+
test('should ensure that blog page link navigates correctly', async ({
9+
page,
10+
}) => {
11+
await page.goto('https://www.creowis.com/');
12+
await page.getByRole('link', { name: 'Blog' }).click();
13+
await expect(page.getByRole('heading', { name: 'Blogs' })).toBeVisible();
14+
});

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"prepare": "husky install",
1212
"prettier:check": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
1313
"lint:check": "eslint --ignore-path .eslintignore --ext .js,.ts .",
14-
"lint-prettier": "npm run lint:check && npm run prettier:check"
14+
"lint-prettier": "npm run lint:check && npm run prettier:check",
15+
"playwright": "npx playwright install && npx playwright install-deps && npx playwright test"
1516
},
1617
"lint-staged": {
1718
"src/**/*.{js,jsx,ts,tsx}": "npm run lint-prettier"
@@ -24,6 +25,7 @@
2425
},
2526
"devDependencies": {
2627
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
28+
"@playwright/test": "^1.50.1",
2729
"@types/node": "^20.11.19",
2830
"@types/react": "19.0.7",
2931
"@types/react-dom": "19.0.3",

playwright.config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './__tests__/e2e',
5+
/* Run tests in files in parallel */
6+
fullyParallel: true,
7+
/* Fail the build on CI if you accidentally left test.only in the source code. */
8+
forbidOnly: !!process.env.CI,
9+
/* Retry on CI only */
10+
retries: process.env.CI ? 2 : 0,
11+
/* Opt out of parallel tests on CI. */
12+
workers: process.env.CI ? 1 : undefined,
13+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
14+
reporter: 'html',
15+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
16+
use: {
17+
/* Base URL to use in actions like `await page.goto('/')`. */
18+
// baseURL: 'http://127.0.0.1:3000',
19+
20+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
21+
trace: 'on-first-retry',
22+
},
23+
24+
/* Configure projects for major browsers */
25+
projects: [
26+
{
27+
name: 'chromium',
28+
use: { ...devices['Desktop Chrome'] },
29+
},
30+
31+
{
32+
name: 'firefox',
33+
use: { ...devices['Desktop Firefox'] },
34+
},
35+
36+
{
37+
name: 'webkit',
38+
use: { ...devices['Desktop Safari'] },
39+
},
40+
],
41+
});

0 commit comments

Comments
 (0)