Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Init Tests in dwa-starter-react-vite (#180)
Browse files Browse the repository at this point in the history
* Init Tests in dwa-starter-react-vite

* fix playwright baseurl

* fix test

* fix test
  • Loading branch information
leordev authored Oct 4, 2024
1 parent 06b19a9 commit 07271a9
Show file tree
Hide file tree
Showing 12 changed files with 1,603 additions and 9 deletions.
4 changes: 4 additions & 0 deletions javascript/dwa-starter-react-vite/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ temp
*.njsproj
*.sln
*.sw?
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
14 changes: 14 additions & 0 deletions javascript/dwa-starter-react-vite/.tbd-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "DWA Starter React Vite",
"tests": {
"pre": [
"npm install -g pnpm",
"pnpm install",
"pnpm build",
"pnpm playwright install --with-deps"
],
"commands": [
"pnpm test"
]
}
}
11 changes: 11 additions & 0 deletions javascript/dwa-starter-react-vite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ docker compose up -d
pnpm dev
```

### Running Tests

- Unit tests are located alongside the code in the `src` folder, suffixed with `.test.tsx`, ran by `vitest` and `react-testing-library` for components
- E2E tests are located in the `e2e` folder, ran by `playwright`

```sh
pnpm test # runs both unit and e2e tests
pnpm test:unit # runs only the unit tests
pnpm test:e2e # runs only the e2e tests
```

### Building App

```sh
Expand Down
16 changes: 16 additions & 0 deletions javascript/dwa-starter-react-vite/e2e/home.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test, expect } from "@playwright/test";

test("has title", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveTitle(/DWA Starter/);
});

test("has heading", async ({ page }) => {
await page.goto("/");
await expect(page.getByText("DWA Starter")).toBeVisible();
});

test("has connect cta", async ({ page }) => {
await page.goto("/");
await expect(page.getByText("Connect your DWA to get Started")).toBeVisible();
});
12 changes: 10 additions & 2 deletions javascript/dwa-starter-react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"test:unit": "vitest run",
"test:e2e": "playwright test",
"test": "pnpm test:unit && pnpm test:e2e"
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.1.1",
Expand All @@ -32,6 +35,9 @@
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@playwright/test": "^1.47.2",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@types/node": "^20.14.10",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
Expand All @@ -43,12 +49,14 @@
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.6",
"jsdom": "^25.0.1",
"postcss": "^8.4.39",
"tailwindcss": "^3.4.13",
"typescript": "^5.2.2",
"vite": "^5.4.8",
"vite-plugin-node-stdlib-browser": "^0.2.1",
"vite-plugin-pwa": "^0.20.5",
"vitest": "^2.1.2",
"workbox-core": "^7.1.0",
"workbox-precaching": "^7.1.0",
"workbox-routing": "^7.1.0",
Expand All @@ -64,4 +72,4 @@
"sharp": "0.32.6",
"sharp-ico": "0.1.5"
}
}
}
79 changes: 79 additions & 0 deletions javascript/dwa-starter-react-vite/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from "@playwright/test";

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: "./e2e",
/* Run tests in files in parallel */
fullyParallel: true,
/* 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,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://localhost:5173",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},

{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: process.env.CI ? "vite preview --port 5173" : "vite dev",
url: "http://localhost:5173",
reuseExistingServer: !process.env.CI,
},
});
Loading

0 comments on commit 07271a9

Please sign in to comment.