Skip to content

Commit d933280

Browse files
committed
test: ✅ 实现站点测试
1 parent 2334b2c commit d933280

14 files changed

Lines changed: 5069 additions & 1198 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ rollup.config-*.mjs
66
storybook-static
77
*storybook.log
88
.env
9+
.tmp
10+
test/__snapshots__
11+
test/xpi
12+
test/cookie.ts

.oxlintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"jest/no-hooks": "off",
108108
"jest/no-standalone-expect": "off",
109109
"jest/no-conditional-in-test": "off",
110+
"jest/valid-describe-callback": "off",
110111
"jest/consistent-test-it": [
111112
"error",
112113
{ "fn": "it", "withinDescribe": "it" }
@@ -152,6 +153,12 @@
152153
}
153154
]
154155
}
156+
},
157+
{
158+
"files": ["**/*.test.*"],
159+
"rules": {
160+
"no-console": "off"
161+
}
155162
}
156163
]
157164
}

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "run select spec",
9+
"type": "node",
10+
"request": "launch",
11+
"args": ["wdio.conf.ts"],
12+
"cwd": "${workspaceFolder}",
13+
"autoAttachChildProcesses": true,
14+
"program": "${workspaceRoot}/node_modules/@wdio/cli/bin/wdio.js",
15+
"console": "integratedTerminal",
16+
"skipFiles": [
17+
"${workspaceFolder}/node_modules/**/*.js",
18+
"${workspaceFolder}/lib/**/*.js",
19+
"<node_internals>/**/*.js"
20+
]
21+
}
22+
]
23+
}

docs/.other/Dev.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ while (id--) clearInterval(id);
8989
1. 打包代码到 dist
9090
2. 创建 dist 的文件服务器,用于在浏览器获取最新的脚本代码
9191
3. 使用 vite 加载 src\components\display.tsx 以便单独测试组件
92+
93+
## 浏览器测试
94+
95+
`test/xpi` 里的 xpi 文件会全部安装上,需要在里面放上 violentmonkey 和 uBlock 的 xpi 文件。
96+
97+
`test/cookie.ts` 用于存储通过 EditThisCookie 扩展导出的 cookie,测试时会自动检查当前站点名是否有对应的 cookie,有就加载上。
98+
99+
<!-- wdio 可以和 percy 集成,不过之前已经折腾好了 storybook + percy,感觉没必要这里再搞,所以就用 wdio 自己的视觉测试好了 -->
100+
101+
通过在测试文件中取消 `browser.saveScreen` 的注释,就可以将截图存至 `test/__snapshots__` 作为基准,之后用 `toMatchScreenSnapshot` 来对比检测。

eslint.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export default antfu(
9797
],
9898
},
9999
},
100+
{
101+
files: ['**/*.test.*'],
102+
rules: {
103+
'no-debugger': 'off',
104+
},
105+
},
100106
prettierConflicts,
101107
...oxlint.buildFromOxlintConfigFile('./.oxlintrc.json'),
102108
)

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"storybook": "storybook dev -p 6006",
2424
"build-storybook": "storybook build",
2525
"test-storybook": "test-storybook --maxWorkers=1 --testTimeout 60000",
26-
"percy": "percy exec -- pnpm test-storybook"
26+
"percy": "percy exec -- pnpm test-storybook",
27+
"wdio": "wdio run ./wdio.conf.ts"
2728
},
2829
"dependencies": {
2930
"@material-design-icons/svg": "^0.14.15",
@@ -47,7 +48,7 @@
4748
"water.css": "^2.1.1"
4849
},
4950
"devDependencies": {
50-
"@antfu/eslint-config": "^4.16.2",
51+
"@antfu/eslint-config": "latest",
5152
"@babel/core": "^7.28.0",
5253
"@babel/plugin-proposal-import-attributes-to-assertions": "^7.27.1",
5354
"@babel/plugin-transform-runtime": "^7.28.0",
@@ -69,12 +70,20 @@
6970
"@solidjs/router": "^0.15.3",
7071
"@storybook/test-runner": "^0.23.0",
7172
"@types/libarchive.js": "^1.3.4",
73+
"@types/mocha": "^10.0.10",
7274
"@types/node": "^24.0.10",
7375
"@types/shelljs": "^0.8.17",
7476
"@types/wicg-file-system-access": "^2023.10.6",
7577
"@types/wicg-web-app-launch": "^2023.1.4",
7678
"@typescript-eslint/parser": "^8.35.1",
7779
"@vueless/storybook-dark-mode": "^9.0.6",
80+
"@wdio/cli": "^9.18.4",
81+
"@wdio/concise-reporter": "^9.18.0",
82+
"@wdio/firefox-profile-service": "^9.16.2",
83+
"@wdio/globals": "^9.17.0",
84+
"@wdio/local-runner": "^9.18.4",
85+
"@wdio/mocha-framework": "^9.18.0",
86+
"@wdio/visual-service": "^9.0.0",
7887
"autoprefixer": "^10.4.21",
7988
"axios": "^1.10.0",
8089
"babel-preset-solid": "^1.9.6",
@@ -93,6 +102,7 @@
93102
"postcss-import": "^16.1.1",
94103
"postcss-nesting": "^13.0.2",
95104
"prettier": "^3.6.2",
105+
"radash": "^12.1.1",
96106
"release-it": "^19.0.3",
97107
"rfdc": "^1.4.1",
98108
"rollup": "^4.44.1",
@@ -121,9 +131,7 @@
121131
"vite-tsconfig-paths": "^5.1.4",
122132
"vitepress": "1.6.3",
123133
"vitest": "^3.2.4",
134+
"wdio-vscode-service": "^6.1.3",
124135
"xo": "^1.1.1"
125-
},
126-
"pnpm": {
127-
"neverBuiltDependencies": []
128136
}
129137
}

0 commit comments

Comments
 (0)