Skip to content

Commit 7e7f2ef

Browse files
authored
Merge pull request #34 from lgldlk/feature/playright_test
添加 Playwright 测试用例
2 parents 9de28b3 + 7ab8aa6 commit 7e7f2ef

38 files changed

+721
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"rollup": "^3.29.4",
6161
"tsx": "^4.7.2",
6262
"turbo": "^1.13.2",
63-
"typescript": "^5.4.5"
63+
"typescript": "^5.4.5",
64+
"@playwright/test": "^1.48.2"
6465
}
6566
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
/test-results/
3+
/playwright-report/
4+
/blob-report/
5+
/playwright/.cache/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect, test } from '@playwright/test'
2+
import { getTransformUrl, testRedirectRemoval } from '../utils/common'
3+
4+
test('51cto blog redirect removal', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://blog.51cto.com/transfer?https://cloud.tencent.com/product/hai',
9+
'https://cloud.tencent.com/product/hai',
10+
{
11+
originalUrlWaitUntil: 'load',
12+
},
13+
)
14+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect, test } from '@playwright/test'
2+
import { getTransformUrl, testRedirectRemoval } from '../utils/common'
3+
4+
test('ACG盒子链接重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://www.acgbox.link/go/?url=https%3A%2F%2Ffe-mm.com',
9+
'https://fe-mm.com/',
10+
{
11+
originalUrlWaitUntil: 'load',
12+
},
13+
)
14+
})
15+
16+
test('ACG盒子 transform', async ({ page, context }) => {
17+
const href = await getTransformUrl(page, context, 'https://www.acgbox.link/h/58.html', {
18+
selectDomPath:
19+
'#content > div.row.site-content.py-4.py-md-5.mb-xl-5.mb-0.mx-xxxl-n5 > div.col.mt-4.mt-sm-0 > div > div > div.site-go.mt-3 > span > a',
20+
})
21+
expect(href).toBe('https://www.pixiv.net/')
22+
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from '@playwright/test'
2+
import { getTransformUrl, testRedirectRemoval } from '../utils/common'
3+
4+
test('爱发电链接重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://afdian.com/link?target=https%3A%2F%2Ffe-mm.com',
9+
'https://fe-mm.com/',
10+
)
11+
})
12+
13+
test('爱发电 transform', async ({ page, context }) => {
14+
const href = await getTransformUrl(page, context, 'https://afdian.com/a/evanyou', {
15+
selectDomPath:
16+
'div.wrapper.app-view > div.vm-page > section.page-content-w100 > div > div.content-left.max-width-320 > div.gl-card.mq-0-1 > pre > a',
17+
})
18+
expect(href).toBe('https://cn.vuejs.org/sponsor/')
19+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from '@playwright/test'
2+
import { getTransformUrl, testRedirectRemoval } from '../utils/common'
3+
4+
test('百度贴吧重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://tieba.baidu.com/mo/q/checkurl?url=https%3A%2F%2Ffe-mm.com',
9+
'https://fe-mm.com/',
10+
)
11+
})
12+
test('百度搜索 transform', async ({ page, context }) => {
13+
const href = await getTransformUrl(page, context, 'https://www.baidu.com/s?wd=mmPlayer', {
14+
selectDomPath: '#content_left a',
15+
})
16+
expect(href).not.toMatch(/^https\:\/\/www\.baidu\.comm/)
17+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test } from '@playwright/test'
2+
import { testRedirectRemoval } from '../utils/common'
3+
4+
test('哔哩哔哩游戏WIKI链接重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://game.bilibili.com/linkfilter/?url=https%3A%2F%2Ffe-mm.com',
9+
'https://fe-mm.com/',
10+
)
11+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test, { expect } from '@playwright/test'
2+
import { getTransformUrl } from '../utils/common'
3+
4+
test('Bing 搜索', async ({ page, context }) => {
5+
const href = await getTransformUrl(page, context, 'https://www.bing.com/search?q=mmPlayer', {
6+
selectDomPath: '#b_results > li.b_algo.b_vtl_deeplinks > h2 > a',
7+
})
8+
expect(href).not.toMatch(/^https\:\/\/www\.bing\.comm/)
9+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from '@playwright/test'
2+
import { getTransformUrl, testRedirectRemoval } from '../utils/common'
3+
4+
test('书签地球链接重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://www.bookmarkearth.cn/view/a61cf21a93d711edb9f55254005bdbf9',
9+
'https://netease-music.fe-mm.com/#/music/playlist',
10+
)
11+
})
12+
13+
test('书签地球 transform', async ({ page, context }) => {
14+
const href = await getTransformUrl(
15+
page,
16+
context,
17+
'https://www.bookmarkearth.cn/detail/221486638f5f4c2aa9139d08bd1bcfd2',
18+
{
19+
selectDomPath:
20+
'#container > div > div.content-point > ul > li > ul > li:nth-child(1) > ul > li > a:nth-child(1)',
21+
noWait: true,
22+
},
23+
)
24+
expect(href).not.toMatch(/^https\:\/\/www\.bookmarkearth\.comm/)
25+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test } from '@playwright/test'
2+
import { testRedirectRemoval } from '../utils/common'
3+
4+
test('酷安链接重定向移除', async ({ page, context }) => {
5+
await testRedirectRemoval(
6+
page,
7+
context,
8+
'https://www.coolapk.com/link?url=https%3A%2F%2Ffe-mm.com',
9+
'https://fe-mm.com/',
10+
)
11+
})

0 commit comments

Comments
 (0)