@nocobase/cli 0.18.0-alpha.1 → 0.18.0-alpha.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "0.18.0-alpha.1",
3
+ "version": "0.18.0-alpha.8",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,7 @@
8
8
  "nocobase": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/app": "0.18.0-alpha.1",
11
+ "@nocobase/app": "0.18.0-alpha.8",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
@@ -17,18 +17,19 @@
17
17
  "execa": "^5.1.1",
18
18
  "fast-glob": "^3.3.1",
19
19
  "fs-extra": "^11.1.1",
20
+ "p-all": "3.0.0",
20
21
  "pm2": "^5.2.0",
21
22
  "portfinder": "^1.0.28",
22
23
  "serve": "^13.0.2",
23
24
  "tsx": "^4.6.2"
24
25
  },
25
26
  "devDependencies": {
26
- "@nocobase/devtools": "0.18.0-alpha.1"
27
+ "@nocobase/devtools": "0.18.0-alpha.8"
27
28
  },
28
29
  "repository": {
29
30
  "type": "git",
30
31
  "url": "git+https://github.com/nocobase/nocobase.git",
31
32
  "directory": "packages/core/cli"
32
33
  },
33
- "gitHead": "0f5f1c0a37dc397a9dc4c8eec0c4ec20fd8107b0"
34
+ "gitHead": "727d42f6f14e5f863831da3dbf3255ba1165b567"
34
35
  }
@@ -2,6 +2,7 @@ const { Command } = require('commander');
2
2
  const { run, isPortReachable } = require('../util');
3
3
  const { execSync } = require('node:child_process');
4
4
  const axios = require('axios');
5
+ const { pTest } = require('./p-test');
5
6
 
6
7
  /**
7
8
  * 检查服务是否启动成功
@@ -200,4 +201,12 @@ module.exports = (cli) => {
200
201
  e2e.command('install-deps').action(async () => {
201
202
  await run('npx', ['playwright', 'install', '--with-deps']);
202
203
  });
204
+
205
+ e2e
206
+ .command('p-test')
207
+ .option('--stop-on-error')
208
+ .option('--concurrency [concurrency]', '', 3)
209
+ .action(async (opts) => {
210
+ await pTest(opts);
211
+ });
203
212
  };
@@ -0,0 +1,68 @@
1
+ const execa = require('execa');
2
+ const { resolve, dirname } = require('path');
3
+ const pAll = require('p-all');
4
+ const dotenv = require('dotenv');
5
+ const fs = require('fs');
6
+ const { Client } = require('pg');
7
+ const glob = require('glob');
8
+
9
+ let ENV_FILE = resolve(process.cwd(), '.env.e2e');
10
+
11
+ if (!fs.existsSync(ENV_FILE)) {
12
+ ENV_FILE = resolve(process.cwd(), '.env.e2e.example');
13
+ }
14
+
15
+ const data = fs.readFileSync(ENV_FILE, 'utf-8');
16
+ const config = {
17
+ ...dotenv.parse(data),
18
+ ...process.env,
19
+ };
20
+
21
+ async function runApp(index = 1, dir) {
22
+ const database = `nocobase${index}`;
23
+ const client = new Client({
24
+ host: config['DB_HOST'],
25
+ port: Number(config['DB_PORT']),
26
+ user: config['DB_USER'],
27
+ password: config['DB_PASSWORD'],
28
+ database: 'postgres',
29
+ });
30
+ await client.connect();
31
+ await client.query(`DROP DATABASE IF EXISTS "${database}"`);
32
+ await client.query(`CREATE DATABASE "${database}";`);
33
+ await client.end();
34
+ return execa('yarn', ['nocobase', 'e2e', 'test', dir, '-x', '--skip-reporter'], {
35
+ shell: true,
36
+ stdio: 'inherit',
37
+ env: {
38
+ ...config,
39
+ CI: true,
40
+ __E2E__: true,
41
+ APP_BASE_URL: undefined,
42
+ LOGGER_LEVEL: 'error',
43
+ APP_ENV: 'production',
44
+ APP_PORT: 20000 + index,
45
+ DB_DATABASE: `nocobase${index}`,
46
+ SOCKET_PATH: `storage/gateway-e2e-${index}.sock`,
47
+ PM2_HOME: resolve(process.cwd(), `storage/.pm2-${index}`),
48
+ PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`),
49
+ },
50
+ });
51
+ }
52
+
53
+ exports.pTest = async (options) => {
54
+ const files = glob.sync('packages/**/__e2e__/**/*.test.ts', {
55
+ root: process.cwd(),
56
+ });
57
+ const fileSet = new Set();
58
+
59
+ for (const file of files) {
60
+ fileSet.add(dirname(file));
61
+ }
62
+
63
+ const commands = [...fileSet.values()].map((v, i) => {
64
+ return () => runApp(i + 1, v);
65
+ });
66
+
67
+ await pAll(commands, { concurrency: 3, stopOnError: false, ...options });
68
+ };
package/src/util.js CHANGED
@@ -57,6 +57,10 @@ exports.nodeCheck = () => {
57
57
  };
58
58
 
59
59
  exports.run = (command, args, options = {}) => {
60
+ if (command === 'tsx') {
61
+ command = 'node';
62
+ args = ['./node_modules/tsx/dist/cli.mjs'].concat(args || []);
63
+ }
60
64
  return execa(command, args, {
61
65
  shell: true,
62
66
  stdio: 'inherit',
@@ -213,6 +217,9 @@ exports.genTsConfigPaths = function genTsConfigPaths() {
213
217
  paths[`${packageJsonName}/server`] = [`${relativePath}/src/server`];
214
218
  paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
215
219
  }
220
+ if (packageJsonName === '@nocobase/plugin-workflow-test') {
221
+ paths[`${packageJsonName}/e2e`] = [`${relativePath}/src/e2e`];
222
+ }
216
223
  });
217
224
 
218
225
  const tsConfigJsonPath = join(cwd, './tsconfig.paths.json');
@@ -268,7 +275,7 @@ exports.initEnv = function initEnv() {
268
275
  }
269
276
  }
270
277
 
271
- if (process.argv[2] === 'e2e') {
278
+ if (!process.env.APP_ENV_PATH && process.argv[2] === 'e2e') {
272
279
  // 用于存放 playwright 自动生成的相关的文件
273
280
  generatePlaywrightPath();
274
281
  if (!fs.existsSync('.env.e2e') && fs.existsSync('.env.e2e.example')) {