Skip to content

Commit 4414eee

Browse files
committed
Set up test n8n dir
1 parent 7e35897 commit 4414eee

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

packages/cli/test/benchmarks/init.ts

+32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1+
import { tmpdir } from 'node:os';
2+
import { join } from 'node:path';
3+
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
4+
15
import { Config } from '@oclif/core';
26
import { Start } from '@/commands/start';
37
import * as testDb from '../integration/shared/testDb';
8+
import Container from 'typedi';
9+
import { InstanceSettings } from 'n8n-core';
10+
11+
/** Set up a temp `.n8n` dir for benchmarks to use. */
12+
function n8nDir() {
13+
const baseDir = join(tmpdir(), 'n8n-benchmarks/');
14+
15+
mkdirSync(baseDir, { recursive: true });
16+
17+
const subDir = mkdtempSync(baseDir);
18+
const n8nDir = join(subDir, '.n8n');
19+
20+
mkdirSync(n8nDir);
21+
22+
writeFileSync(
23+
join(n8nDir, 'config'),
24+
JSON.stringify({ encryptionKey: 'temp_encryption_key', instanceId: '123' }),
25+
'utf-8',
26+
);
27+
28+
const instanceSettings = Container.get(InstanceSettings);
29+
instanceSettings.n8nFolder = n8nDir;
30+
Container.set(InstanceSettings, instanceSettings);
31+
32+
console.log('n8nDir', n8nDir);
33+
}
434

35+
/** Initialize an n8n main process for benchmarking. */
536
async function mainProcess() {
637
const args: string[] = [];
738
const _config = new Config({ root: __dirname });
@@ -13,6 +44,7 @@ async function mainProcess() {
1344
}
1445

1546
export const init = {
47+
n8nDir,
1648
database: testDb.init,
1749
mainProcess,
1850
};

packages/cli/test/benchmarks/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ async function main() {
99
const _bench = new Bench({ time: 0, iterations: 1 }); // @TEMP: Remove arg
1010
const bench = withCodSpeed(_bench);
1111

12+
process.env.NODE_ENV = 'test';
13+
1214
register(bench);
1315

1416
// await bench.warmup(); // @TODO: Restore

packages/cli/test/benchmarks/webhook.benchmark.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ export function webhook(bench: Bench) {
1212
beforeAll: async () => {
1313
console.log('beforeAll start');
1414

15-
await init.database();
15+
init.n8nDir();
16+
await init.database(); // @TODO: Test with Postgres
1617
await init.mainProcess();
1718

1819
console.log('beforeAll end');
1920
},
2021
afterAll: () => {
21-
// stop process // @TODO
22+
// @TODO stop main process gracefully
2223
},
2324
},
2425
);

packages/core/src/InstanceSettings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class InstanceSettings {
2121
private readonly userHome = this.getUserHome();
2222

2323
/** The path to the n8n folder in which all n8n related data gets saved */
24-
readonly n8nFolder = path.join(this.userHome, '.n8n');
24+
n8nFolder = path.join(this.userHome, '.n8n');
2525

2626
/** The path to the folder where all generated static assets are copied to */
2727
readonly staticCacheDir = path.join(this.userHome, '.cache/n8n/public');

0 commit comments

Comments
 (0)