Skip to content

Commit

Permalink
fix: e2e with build
Browse files Browse the repository at this point in the history
  • Loading branch information
chenos committed Jan 8, 2024
1 parent 3c87755 commit fd4809d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
18 changes: 9 additions & 9 deletions .env.e2e.example
Original file line number Diff line number Diff line change
Expand Up @@ -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 插件
Expand All @@ -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

Expand Down
21 changes: 19 additions & 2 deletions packages/core/cli/src/commands/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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';
}
Expand All @@ -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);
});
};
10 changes: 8 additions & 2 deletions packages/core/cli/src/commands/p-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
7 changes: 7 additions & 0 deletions packages/core/server/src/gateway/ipc-socket-server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');

Expand Down
3 changes: 2 additions & 1 deletion storage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.pm2
tmp
app.watch.ts
app.watch.ts
/e2e

0 comments on commit fd4809d

Please sign in to comment.