Skip to content

Commit b457eb8

Browse files
committed
feat(tests): add weather service and API mocking with Playwright
1 parent 6916ca4 commit b457eb8

File tree

13 files changed

+762
-19
lines changed

13 files changed

+762
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ dist
6969
# Envrc file
7070
.envrc
7171
generated/sdk
72+
playwright-report
73+
test-results

moleculer.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const config: BrokerOptions = {
3939

4040
// Enable/disable logging or use custom logger. More info: https://moleculer.services/docs/0.14/logging.html
4141
// Available logger types: "Console", "File", "Pino", "Winston", "Bunyan", "debug", "Log4js", "Datadog"
42-
logger: {
42+
logger: [{
4343
// Note: Change to Console if you want to see the logger output
4444
type: "Pino",
4545
options: {
@@ -50,10 +50,10 @@ const config: BrokerOptions = {
5050
},
5151
},
5252
},
53-
},
54-
// Default log level for built-in console logger. It can be overwritten in logger options above.
55-
// Available values: trace, debug, info, warn, error, fatal
56-
logLevel: "info",
53+
}, {
54+
type: "Console",
55+
}],
56+
5757

5858
// Define transporter.
5959
// More info: https://moleculer.services/docs/0.14/networking.html

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "moleculer-typescript-template",
33
"version": "0.3.0",
44
"description": "My Moleculer-based microservices project",
5-
"keywords": ["microservices", "moleculer", "moleculer typescript template"],
5+
"keywords": [
6+
"microservices",
7+
"moleculer",
8+
"moleculer typescript template"
9+
],
610
"license": "MIT",
711
"author": "Huynh Duc Dung",
812
"scripts": {
@@ -13,9 +17,9 @@
1317
"start": "npx tsx ./server.ts",
1418
"cli": "NODE_OPTIONS='--import tsx' moleculer-connect --env --config moleculer.config.ts --transporter NATS",
1519
"ci": "biome ci .",
16-
"test:ci": "vitest --watch",
17-
"test": "vitest --run",
18-
"test:coverage": "vitest --coverage",
20+
"test:ci": "vitest --watch --exclude 'tests/**'",
21+
"test": "vitest --run --exclude 'tests/**'",
22+
"test:coverage": "vitest --coverage --exclude 'tests/**'",
1923
"test:ui": "vitest --ui",
2024
"build": "tsup --env.NODE_ENV production",
2125
"format": "biome format . --write",
@@ -30,7 +34,10 @@
3034
"generate:action": "hygen action new --name",
3135
"generate:swagger": "npx tsx cli.ts",
3236
"generate:sdk": "openapi-ts",
33-
"typecheck": "npm run generate:sdk && tsc -b"
37+
"typecheck": "npm run generate:sdk && tsc -b",
38+
"test:e2e": "playwright test",
39+
"test:e2e:ui": "playwright test --ui",
40+
"test:e2e:debug": "DEBUG=pw:* playwright test --debug"
3441
},
3542
"dependencies": {
3643
"@asteasolutions/zod-to-openapi": "7.3.0",
@@ -51,6 +58,7 @@
5158
"@biomejs/biome": "1.9.4",
5259
"@flydotio/dockerfile": "0.6.1",
5360
"@hey-api/openapi-ts": "0.61.2",
61+
"@playwright/test": "^1.49.1",
5462
"@types/express": "5.0.0",
5563
"@types/jest": "29.5.14",
5664
"@types/lodash": "4.17.14",
@@ -67,6 +75,7 @@
6775
"moleculer-connect": "0.2.2",
6876
"moleculer-io": "2.2.0",
6977
"moleculer-repl": "0.7.4",
78+
"msw": "2.1.0",
7079
"npm-run-all2": "7.0.2",
7180
"pino-pretty": "13.0.0",
7281
"sort-package-json": "2.12.0",
@@ -82,4 +91,4 @@
8291
"engines": {
8392
"node": ">= 18.17.x"
8493
}
85-
}
94+
}

playwright.config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
export default defineConfig({
4+
testDir: "./tests",
5+
fullyParallel: true,
6+
forbidOnly: !!process.env.CI,
7+
retries: process.env.CI ? 2 : 0,
8+
workers: process.env.CI ? 1 : undefined,
9+
reporter: "html",
10+
use: {
11+
baseURL: "http://localhost:4567",
12+
trace: "on-first-retry",
13+
},
14+
15+
projects: [
16+
{
17+
name: "chromium",
18+
use: { ...devices["Desktop Chrome"] },
19+
},
20+
{
21+
name: "firefox",
22+
use: { ...devices["Desktop Firefox"] },
23+
},
24+
{
25+
name: "webkit",
26+
use: { ...devices["Desktop Safari"] },
27+
},
28+
],
29+
30+
webServer: {
31+
command: "npm run dev",
32+
url: "http://localhost:4567",
33+
reuseExistingServer: !process.env.CI,
34+
},
35+
});

0 commit comments

Comments
 (0)