From fd4809d8ad4d09075864ed0fd0e6d15f687ca52b Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 8 Jan 2024 10:29:41 +0800 Subject: [PATCH] fix: e2e with build --- .env.e2e.example | 18 ++++++++-------- packages/core/cli/src/commands/e2e.js | 21 +++++++++++++++++-- packages/core/cli/src/commands/p-test.js | 10 +++++++-- .../server/src/gateway/ipc-socket-server.ts | 7 +++++++ storage/.gitignore | 3 ++- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/.env.e2e.example b/.env.e2e.example index fc8a8f20a..d2626dcc2 100644 --- a/.env.e2e.example +++ b/.env.e2e.example @@ -13,7 +13,7 @@ VERDACCIO_PORT=10104 APP_ENV=development APP_PORT=20000 APP_KEY=test-key-e2e -SOCKET_PATH=storage/gateway-e2e.sock +SOCKET_PATH=storage/e2e/gateway.sock __E2E__=true # 启用 mock-collections 插件 @@ -26,18 +26,18 @@ PROXY_TARGET_URL= LOGGER_TRANSPORT= LOGGER_LEVEL= -LOGGER_BASE_PATH=storage/logs-e2e +LOGGER_BASE_PATH=storage/e2e/logs ################# DATABASE ################# -DB_DIALECT=sqlite -DB_STORAGE=storage/db/nocobase-e2e.sqlite +DB_DIALECT=postgres +DB_STORAGE=storage/e2e/db/nocobase.sqlite DB_TABLE_PREFIX= -# DB_HOST=localhost -# DB_PORT=5432 -# DB_DATABASE=nocobase-e2e -# DB_USER=nocobase -# DB_PASSWORD=nocobase +DB_HOST=localhost +DB_PORT=5432 +DB_DATABASE=nocobase-e2e +DB_USER=nocobase +DB_PASSWORD=nocobase # DB_LOGGING=on # DB_UNDERSCORED=false diff --git a/packages/core/cli/src/commands/e2e.js b/packages/core/cli/src/commands/e2e.js index f6637943e..4e54f613e 100644 --- a/packages/core/cli/src/commands/e2e.js +++ b/packages/core/cli/src/commands/e2e.js @@ -149,7 +149,13 @@ module.exports = (cli) => { .allowUnknownOption() .option('--url [url]') .option('--skip-reporter') + .option('--build') .action(async (options) => { + process.env.__E2E__ = true; + if (options.build) { + process.env.APP_ENV = 'production'; + await run('yarn', ['build']); + } if (options.skipReporter) { process.env.PLAYWRIGHT_SKIP_REPORTER = true; } @@ -184,8 +190,13 @@ module.exports = (cli) => { e2e .command('start-app') .option('--production') + .option('--build') .option('--port [port]') .action(async (options) => { + process.env.__E2E__ = true; + if (options.build) { + await run('yarn', ['build']); + } if (options.production) { process.env.APP_ENV = 'production'; } @@ -206,8 +217,14 @@ module.exports = (cli) => { e2e .command('p-test') .option('--stop-on-error') + .option('--build') .option('--concurrency [concurrency]', '', os.cpus().length) - .action(async (opts) => { - await pTest(opts); + .action(async (options) => { + process.env.__E2E__ = true; + if (options.build) { + process.env.APP_ENV = 'production'; + await run('yarn', ['build']); + } + await pTest(options); }); }; diff --git a/packages/core/cli/src/commands/p-test.js b/packages/core/cli/src/commands/p-test.js index 2f1ddd843..ce1b8a36d 100644 --- a/packages/core/cli/src/commands/p-test.js +++ b/packages/core/cli/src/commands/p-test.js @@ -47,14 +47,20 @@ async function runApp(dir, index = 0) { APP_ENV: 'production', APP_PORT: 20000 + index, DB_DATABASE: `nocobase${index}`, - SOCKET_PATH: `storage/gateway-e2e-${index}.sock`, - PM2_HOME: resolve(process.cwd(), `storage/.pm2-${index}`), + SOCKET_PATH: `storage/e2e/gateway-e2e-${index}.sock`, + PM2_HOME: resolve(process.cwd(), `storage/e2e/.pm2-${index}`), PLAYWRIGHT_AUTH_FILE: resolve(process.cwd(), `storage/playwright/.auth/admin-${index}.json`), }, }); } exports.pTest = async (options) => { + const dir = resolve(process.cwd(), 'storage/e2e'); + + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } + const files = glob.sync('packages/**/__e2e__/**/*.test.ts', { root: process.cwd(), }); diff --git a/packages/core/server/src/gateway/ipc-socket-server.ts b/packages/core/server/src/gateway/ipc-socket-server.ts index b41c73ab6..678288de7 100644 --- a/packages/core/server/src/gateway/ipc-socket-server.ts +++ b/packages/core/server/src/gateway/ipc-socket-server.ts @@ -1,5 +1,6 @@ import net from 'net'; import fs from 'fs'; +import path from 'path'; import { AppSupervisor } from '../app-supervisor'; import { writeJSON } from './ipc-socket-client'; import { randomUUID } from 'crypto'; @@ -17,6 +18,12 @@ export class IPCSocketServer { fs.unlinkSync(socketPath); } + const dir = path.dirname(socketPath); + + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + } + const socketServer = net.createServer((c) => { console.log('client connected'); diff --git a/storage/.gitignore b/storage/.gitignore index f07f9574d..3f29fa2b2 100644 --- a/storage/.gitignore +++ b/storage/.gitignore @@ -1,3 +1,4 @@ .pm2 tmp -app.watch.ts \ No newline at end of file +app.watch.ts +/e2e \ No newline at end of file