Skip to content

Commit 4aeba3b

Browse files
committed
feat: switch to vitest as a testing framework
1 parent 660043f commit 4aeba3b

16 files changed

+101
-246
lines changed

jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@
33
"name": "x-crawl",
44
"version": "10.0.0",
55
"author": "coderHXL",
6-
"description": "x-crawl is a flexible Node.js multifunctional crawler library.",
6+
"description": "x-crawl is a flexible Node.js AI-assisted crawler library.",
77
"license": "MIT",
8-
"keywords": [
9-
"nodejs",
10-
"typescript",
11-
"javascript",
12-
"crawl",
13-
"crawler",
14-
"spider",
15-
"fingerprint",
16-
"flexible",
17-
"multifunction"
18-
],
198
"main": "packages/index.ts",
209
"type": "module",
2110
"scripts": {
@@ -24,39 +13,55 @@
2413
"build-strict": "pnpm test-dev && pnpm build && pnpm test-pro",
2514
"start": "rollup --config script/start.js",
2615
"start-server": "rollup --watch --config script/server.js",
27-
"test-dev": "jest test/environment/test.ts dev",
28-
"test-pro": "jest test/environment/test.ts pro",
29-
"test-crawlPage": "jest test/environment/api/crawlPage.test.ts dev",
30-
"test-crawlData": "jest test/environment/api/crawlData.test.ts dev",
31-
"test-crawlFile": "jest test/environment/api/crawlFile.test.ts dev",
16+
"test-dev": "vitest --ui",
17+
"test-pro": "vitest --ui",
3218
"prettier": "prettier --write ."
3319
},
3420
"engines": {
3521
"node": ">=18.0.0"
3622
},
3723
"dependencies": {
38-
"chalk": "4.1.2",
24+
"chalk": "5.3.0",
3925
"https-proxy-agent": "^7.0.4",
4026
"openai": "^4.31.0",
27+
"ora": "^8.0.1",
4128
"puppeteer": "22.5.0",
4229
"x-crawl": "link:"
4330
},
4431
"devDependencies": {
4532
"@babel/core": "^7.24.0",
4633
"@babel/preset-env": "^7.24.0",
47-
"@jest/globals": "^29.3.1",
4834
"@rollup/plugin-babel": "^6.0.4",
4935
"@rollup/plugin-run": "^3.0.2",
5036
"@rollup/plugin-terser": "^0.4.4",
5137
"@types/node": "^20.11.28",
5238
"@typescript-eslint/eslint-plugin": "^7.2.0",
5339
"@typescript-eslint/parser": "^7.2.0",
40+
"@vitest/coverage-v8": "^1.4.0",
41+
"@vitest/ui": "^1.4.0",
5442
"eslint": "^8.57.0",
55-
"jest": "^29.3.1",
5643
"prettier": "^3.2.5",
5744
"rollup": "^4.13.0",
5845
"rollup-plugin-typescript2": "^0.36.0",
59-
"ts-jest": "^29.1.2",
60-
"typescript": "5.4.3"
61-
}
46+
"typescript": "5.4.3",
47+
"vitest": "^1.4.0"
48+
},
49+
"keywords": [
50+
"x-crawl",
51+
"nodejs",
52+
"typescript",
53+
"ts",
54+
"javascript",
55+
"crawl",
56+
"crawler",
57+
"spider",
58+
"ai",
59+
"ai assisted",
60+
"ai crawl",
61+
"flexible",
62+
"control page",
63+
"rotate agents",
64+
"fingerprint",
65+
"multifunction"
66+
]
6267
}
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function testCrawlData() {
16-
const testCrawlApp = createCrawl()
13+
const testCrawlApp = createCrawl({ log: false })
1714

1815
const res = await testCrawlApp.crawlData({
1916
targets: [
@@ -26,6 +23,5 @@ async function testCrawlData() {
2623
}
2724

2825
test('crawlData', async () => {
29-
console.log(chalk.bgGreen('================ crawlData ================'))
3026
await expect(testCrawlData()).resolves.toBe(true)
3127
})

test/environment/api/crawlFile.test.ts renamed to test/automation/api/crawlFile.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import process from 'node:process'
22
import path from 'node:path'
3-
import { expect, test, jest } from '@jest/globals'
4-
import chalk from 'chalk'
3+
import { expect, test } from 'vitest'
54

65
import type * as XCrawl from 'x-crawl'
76

87
const args = process.argv.slice(3)
98
const environment = args[0]
109

1110
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
12-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
13-
14-
jest.setTimeout(60000)
11+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1512

1613
const urls: string[] = [
1714
'https://raw.githubusercontent.com/coder-hxl/airbnb-upload/master/area/4401.jpg',
@@ -22,6 +19,7 @@ const storeDirs = path.resolve(__dirname, './upload')
2219

2320
async function testCrawlFile() {
2421
const testCrawlApp = createCrawl({
22+
log: false,
2523
proxy: { urls: ['http://localhost:14892'] }
2624
})
2725

@@ -37,6 +35,5 @@ async function testCrawlFile() {
3735
}
3836

3937
test('crawlFile', async () => {
40-
console.log(chalk.bgGreen('================ crawlFile ================'))
4138
await expect(testCrawlFile()).resolves.toBe(true)
4239
})

test/environment/api/crawlHTML.test.ts renamed to test/automation/api/crawlHTML.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function testCrawlHTML() {
1613
const testCrawlApp = createCrawl({
14+
log: false,
1715
proxy: { urls: ['http://localhost:14892'] }
1816
})
1917

@@ -28,6 +26,5 @@ async function testCrawlHTML() {
2826
}
2927

3028
test('crawlHTML', async () => {
31-
console.log(chalk.bgGreen('================ crawlHTML ================'))
3229
await expect(testCrawlHTML()).resolves.toBe(true)
3330
})

test/environment/api/crawlPage.test.ts renamed to test/automation/api/crawlPage.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1211

13-
jest.setTimeout(60000)
12+
console.log(`${environment}:${targetPath}`, createCrawl)
1413

1514
async function testCrawlPage() {
1615
const testCrawlApp = createCrawl({
16+
log: false,
1717
proxy: { urls: ['http://localhost:14892'] }
1818
})
1919

@@ -30,6 +30,5 @@ async function testCrawlPage() {
3030
}
3131

3232
test('crawlPage', async () => {
33-
console.log(chalk.bgGreen('================ crawlPage ================'))
3433
await expect(testCrawlPage()).resolves.toBe(true)
3534
})

test/environment/arguments/fingerprint.test.ts renamed to test/automation/arguments/fingerprint.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function fingerprint() {
16-
const testCrawlApp = createCrawl()
13+
const testCrawlApp = createCrawl({ log: false })
1714

1815
const res = await testCrawlApp.crawlPage({
1916
targets: [
@@ -78,6 +75,5 @@ async function fingerprint() {
7875
}
7976

8077
test('fingerprint', async () => {
81-
console.log(chalk.bgGreen('================ fingerprint ================'))
8278
await expect(fingerprint()).resolves.toBe(true)
8379
})
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function async() {
16-
const testCrawlApp = createCrawl()
13+
const testCrawlApp = createCrawl({ log: false })
1714

1815
const res = await testCrawlApp.crawlData([
1916
'http://localhost:8888/data',
@@ -24,7 +21,7 @@ async function async() {
2421
}
2522

2623
async function sync() {
27-
const testCrawlApp = createCrawl({ mode: 'sync' })
24+
const testCrawlApp = createCrawl({ log: false, mode: 'sync' })
2825

2926
const res = await testCrawlApp.crawlData([
3027
'http://localhost:8888/data',
@@ -35,11 +32,9 @@ async function sync() {
3532
}
3633

3734
test('mode - async', async () => {
38-
console.log(chalk.bgGreen('================ mode - async ================'))
3935
await expect(async()).resolves.toBe(true)
4036
})
4137

4238
test('mode - sync', async () => {
43-
console.log(chalk.bgGreen('================ mode - sync ================'))
4439
await expect(sync()).resolves.toBe(true)
4540
})

test/environment/arguments/proxy.test.ts renamed to test/automation/arguments/proxy.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function proxy() {
16-
const testCrawlApp = createCrawl()
13+
const testCrawlApp = createCrawl({ log: false })
1714

1815
const res = await testCrawlApp.crawlPage({
1916
targets: ['https://', 'http://localhost:8888/html'],
@@ -34,6 +31,5 @@ async function proxy() {
3431
}
3532

3633
test('proxy', async () => {
37-
console.log(chalk.bgGreen('================ proxy ================'))
3834
await expect(proxy()).resolves.toBe(true)
3935
})
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import process from 'node:process'
2-
import { expect, test, jest } from '@jest/globals'
3-
import chalk from 'chalk'
2+
import { expect, test } from 'vitest'
43

54
import type * as XCrawl from 'x-crawl'
65

76
const args = process.argv.slice(3)
87
const environment = args[0]
98

109
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = (require(targetPath) as typeof XCrawl).createCrawl
12-
13-
jest.setTimeout(60000)
10+
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
1411

1512
async function errorCollect() {
16-
const testCrawlApp = createCrawl({ maxRetry: 2 })
13+
const testCrawlApp = createCrawl({ log: false, maxRetry: 2 })
1714

1815
const res = await testCrawlApp.crawlPage(['https://', 'https://', 'https://'])
1916

@@ -28,6 +25,5 @@ async function errorCollect() {
2825
}
2926

3027
test('errorCollect', async () => {
31-
console.log(chalk.bgGreen('================ errorCollect ================'))
3228
await expect(errorCollect()).resolves.toBe(true)
3329
})

0 commit comments

Comments
 (0)