bk-press 0.0.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # bk-press
2
2
 
3
- 一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化和运行自动化测试。
3
+ 一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化测试环境和并行运行自动化测试。
4
4
 
5
5
  ## 📋 目录
6
6
 
@@ -58,7 +58,7 @@ pnpm add bk-press
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
+ }
@@ -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.1");
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bk-press",
3
- "version": "0.0.2",
4
- "description": "A CLI for cypress automation testing",
3
+ "version": "0.0.3",
4
+ "description": "一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化测试环境和并行运行自动化测试",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
7
7
  "bkpress": "./lib/index.js"
@@ -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
  }
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ program
10
10
  .description(
11
11
  "一个用于 Cypress 自动化测试的 CLI 工具,帮助快速初始化和运行端到端测试"
12
12
  )
13
- .version("0.0.1");
13
+ .version("0.0.3");
14
14
 
15
15
  program.command("init").action(init);
16
16
  program.command("login").action(login);