Skip to content

Commit b7ca8da

Browse files
committed
feat: test environment
1 parent 4aeba3b commit b7ca8da

16 files changed

+46
-81
lines changed

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
"main": "packages/index.ts",
99
"type": "module",
1010
"scripts": {
11+
"dev": "rollup --config script/dev.js",
1112
"build": "rollup --config rollup.config.js",
12-
"build-dts": "tsc && prettier --write ./publish/src",
13-
"build-strict": "pnpm test-dev && pnpm build && pnpm test-pro",
14-
"start": "rollup --config script/start.js",
15-
"start-server": "rollup --watch --config script/server.js",
16-
"test-dev": "vitest --ui",
17-
"test-pro": "vitest --ui",
13+
"build-dts": "tsc && prettier --write ./publish/dist",
14+
"dev-server": "rollup --watch --config script/server.js",
15+
"test": "vitest",
1816
"prettier": "prettier --write ."
1917
},
2018
"engines": {

packages/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare const __DEV__: boolean
File renamed without changes.

test/automation/api/crawlData.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

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

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
118

129
async function testCrawlData() {
1310
const testCrawlApp = createCrawl({ log: false })

test/automation/api/crawlFile.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import process from 'node:process'
21
import path from 'node:path'
32
import { expect, test } from 'vitest'
43

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

7-
const args = process.argv.slice(3)
8-
const environment = args[0]
9-
10-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
11-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
6+
const createCrawl = (
7+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
8+
).createCrawl
129

1310
const urls: string[] = [
1411
'https://raw.githubusercontent.com/coder-hxl/airbnb-upload/master/area/4401.jpg',

test/automation/api/crawlHTML.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

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

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
118

129
async function testCrawlHTML() {
1310
const testCrawlApp = createCrawl({

test/automation/api/crawlPage.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

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

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
11-
12-
console.log(`${environment}:${targetPath}`, createCrawl)
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
138

149
async function testCrawlPage() {
1510
const testCrawlApp = createCrawl({

test/automation/arguments/fingerprint.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

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

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
118

129
async function fingerprint() {
1310
const testCrawlApp = createCrawl({ log: false })

test/automation/arguments/mode.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

4-
import * as XCrawl from 'x-crawl'
3+
import type * as XCrawl from 'x-crawl'
54

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
118

129
async function async() {
1310
const testCrawlApp = createCrawl({ log: false })

test/automation/arguments/proxy.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import process from 'node:process'
21
import { expect, test } from 'vitest'
32

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

6-
const args = process.argv.slice(3)
7-
const environment = args[0]
8-
9-
const targetPath = environment === 'pro' ? 'publish/' : 'packages/'
10-
const createCrawl = ((await import(targetPath)) as typeof XCrawl).createCrawl
5+
const createCrawl = (
6+
(await import(__DEV__ ? 'packages/' : 'publish/')) as typeof XCrawl
7+
).createCrawl
118

129
async function proxy() {
1310
const testCrawlApp = createCrawl({ log: false })

0 commit comments

Comments
 (0)