bk-press 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/bkcodeai.json +30 -0
- package/lib/command/run.js +23 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/src/command/run.ts +28 -2
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bk-press
|
|
2
2
|
|
|
3
|
-
一个用于 Cypress 自动化测试的 CLI
|
|
3
|
+
一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化测试环境和并行运行自动化测试。
|
|
4
4
|
|
|
5
5
|
## 📋 目录
|
|
6
6
|
|
|
@@ -16,21 +16,21 @@
|
|
|
16
16
|
### 全局安装
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm install -g
|
|
19
|
+
npm install -g bk-press
|
|
20
20
|
# 或
|
|
21
|
-
yarn global add
|
|
21
|
+
yarn global add bk-press
|
|
22
22
|
# 或
|
|
23
|
-
pnpm add -g
|
|
23
|
+
pnpm add -g bk-press
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### 本地安装
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npm install
|
|
29
|
+
npm install bk-press
|
|
30
30
|
# 或
|
|
31
|
-
yarn add
|
|
31
|
+
yarn add bk-press
|
|
32
32
|
# 或
|
|
33
|
-
pnpm add
|
|
33
|
+
pnpm add bk-press
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## 快速开始
|
|
@@ -58,7 +58,7 @@ pnpm add bkpress
|
|
|
58
58
|
bkpress login
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
4.
|
|
61
|
+
4. **并行运行自动化测试**
|
|
62
62
|
```bash
|
|
63
63
|
bkpress run
|
|
64
64
|
```
|
|
@@ -153,7 +153,7 @@ bkpress init
|
|
|
153
153
|
bkpress login
|
|
154
154
|
# 在浏览器中完成登录,然后按回车
|
|
155
155
|
|
|
156
|
-
# 4.
|
|
156
|
+
# 4. 并行运行测试
|
|
157
157
|
bkpress run
|
|
158
158
|
```
|
|
159
159
|
|
package/bkcodeai.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"crignore_file_patterns": [
|
|
3
|
+
"out/",
|
|
4
|
+
"dist/",
|
|
5
|
+
"assets/",
|
|
6
|
+
"images/",
|
|
7
|
+
"package.json",
|
|
8
|
+
"package-lock.json",
|
|
9
|
+
"yarn.lock",
|
|
10
|
+
".env.*",
|
|
11
|
+
"*.env",
|
|
12
|
+
"*.map",
|
|
13
|
+
"*.yml",
|
|
14
|
+
"*.yaml",
|
|
15
|
+
"*.min.js",
|
|
16
|
+
"libs/",
|
|
17
|
+
"static/",
|
|
18
|
+
"doc/",
|
|
19
|
+
"docs/",
|
|
20
|
+
"*.mo",
|
|
21
|
+
"*.po",
|
|
22
|
+
"*.ini",
|
|
23
|
+
"*.toml",
|
|
24
|
+
"*.json",
|
|
25
|
+
"*.xml",
|
|
26
|
+
"*.lock",
|
|
27
|
+
"*.md",
|
|
28
|
+
"*.txt"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/lib/command/run.js
CHANGED
|
@@ -13,8 +13,10 @@ async function run() {
|
|
|
13
13
|
const cpuCount = os_1.default.cpus().length;
|
|
14
14
|
console.log("当前CPU核心数: ", cpuCount, ", 设置测试并发数: ", cpuCount);
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
16
|
-
(0, child_process_1.exec)(`start-server-and-test dev ${config.localUrl} 'cypress-parallel -s e2e -t ${cpuCount} -d cypress/e2e'`, {
|
|
16
|
+
const child = (0, child_process_1.exec)(`start-server-and-test dev ${config.localUrl} 'cypress-parallel -s e2e -t ${cpuCount} -d cypress/e2e'`, {
|
|
17
17
|
cwd: process.cwd(),
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
stdio: "inherit",
|
|
18
20
|
}, (error, stdout, stderr) => {
|
|
19
21
|
if (error) {
|
|
20
22
|
console.error("运行自动化测试失败:", error);
|
|
@@ -24,5 +26,25 @@ async function run() {
|
|
|
24
26
|
console.log("自动化测试运行成功!");
|
|
25
27
|
resolve(stdout);
|
|
26
28
|
});
|
|
29
|
+
child.stdout.setEncoding("utf8"); // 设置编码
|
|
30
|
+
child.stdout.on("data", (data) => {
|
|
31
|
+
// 通常不需要额外添加前缀,直接打印数据即可
|
|
32
|
+
process.stdout.write(data); // 使用 process.stdout.write 避免自动换行
|
|
33
|
+
});
|
|
34
|
+
child.stderr.setEncoding("utf8");
|
|
35
|
+
child.stderr.on("data", (data) => {
|
|
36
|
+
// 错误信息可以输出到标准错误流,方便区分
|
|
37
|
+
process.stderr.write(`STDERR: ${data}`);
|
|
38
|
+
});
|
|
39
|
+
child.on("error", (error) => {
|
|
40
|
+
reject(error);
|
|
41
|
+
console.error(`Failed to start subprocess: ${error}`);
|
|
42
|
+
});
|
|
43
|
+
child.on("close", (code) => {
|
|
44
|
+
if (code !== 0) {
|
|
45
|
+
reject(new Error(`命令执行失败,退出码: ${code}`));
|
|
46
|
+
}
|
|
47
|
+
resolve(1);
|
|
48
|
+
});
|
|
27
49
|
});
|
|
28
50
|
}
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const program = new commander_1.Command();
|
|
|
7
7
|
program
|
|
8
8
|
.name("bk-press")
|
|
9
9
|
.description("一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化和运行端到端测试")
|
|
10
|
-
.version("0.0.
|
|
10
|
+
.version("0.0.3");
|
|
11
11
|
program.command("init").action(command_1.init);
|
|
12
12
|
program.command("login").action(command_1.login);
|
|
13
13
|
// @ts-ignore
|
package/package.json
CHANGED
package/src/command/run.ts
CHANGED
|
@@ -8,12 +8,14 @@ export async function run() {
|
|
|
8
8
|
const cpuCount = os.cpus().length;
|
|
9
9
|
console.log("当前CPU核心数: ", cpuCount, ", 设置测试并发数: ", cpuCount);
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
|
-
exec(
|
|
11
|
+
const child = exec(
|
|
12
12
|
`start-server-and-test dev ${config.localUrl} 'cypress-parallel -s e2e -t ${cpuCount} -d cypress/e2e'`,
|
|
13
13
|
{
|
|
14
14
|
cwd: process.cwd(),
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
stdio: "inherit",
|
|
15
17
|
},
|
|
16
|
-
(error, stdout, stderr) => {
|
|
18
|
+
(error: any, stdout: any, stderr: any) => {
|
|
17
19
|
if (error) {
|
|
18
20
|
console.error("运行自动化测试失败:", error);
|
|
19
21
|
reject(stderr);
|
|
@@ -23,5 +25,29 @@ export async function run() {
|
|
|
23
25
|
resolve(stdout);
|
|
24
26
|
}
|
|
25
27
|
);
|
|
28
|
+
|
|
29
|
+
child.stdout!.setEncoding("utf8"); // 设置编码
|
|
30
|
+
child.stdout!.on("data", (data) => {
|
|
31
|
+
// 通常不需要额外添加前缀,直接打印数据即可
|
|
32
|
+
process.stdout.write(data); // 使用 process.stdout.write 避免自动换行
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
child.stderr!.setEncoding("utf8");
|
|
36
|
+
child.stderr!.on("data", (data) => {
|
|
37
|
+
// 错误信息可以输出到标准错误流,方便区分
|
|
38
|
+
process.stderr.write(`STDERR: ${data}`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
child.on("error", (error) => {
|
|
42
|
+
reject(error);
|
|
43
|
+
console.error(`Failed to start subprocess: ${error}`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
child.on("close", (code) => {
|
|
47
|
+
if (code !== 0) {
|
|
48
|
+
reject(new Error(`命令执行失败,退出码: ${code}`));
|
|
49
|
+
}
|
|
50
|
+
resolve(1);
|
|
51
|
+
});
|
|
26
52
|
});
|
|
27
53
|
}
|