ci(core): Extract local e2e run script (no-changelog) (#7551)

Github issue / Community forum post (link here to close automatically):

---------

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
OlegIvaniv 2023-10-30 11:18:51 +01:00 committed by GitHub
parent bfa28b9532
commit 3ab04e4f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 9 deletions

View file

@ -28,9 +28,9 @@
"worker": "./packages/cli/bin/n8n worker", "worker": "./packages/cli/bin/n8n worker",
"cypress:install": "cypress install", "cypress:install": "cypress install",
"cypress:open": "CYPRESS_BASE_URL=http://localhost:8080 cypress open", "cypress:open": "CYPRESS_BASE_URL=http://localhost:8080 cypress open",
"test:e2e:ui": "cross-env E2E_TESTS=true NODE_OPTIONS=--dns-result-order=ipv4first start-server-and-test start http://localhost:5678/favicon.ico 'cypress open'", "test:e2e:ui": "scripts/run-e2e.js ui",
"test:e2e:dev": "cross-env E2E_TESTS=true NODE_OPTIONS=--dns-result-order=ipv4first CYPRESS_BASE_URL=http://localhost:8080 start-server-and-test dev http://localhost:8080/favicon.ico 'cypress open'", "test:e2e:dev": "scripts/run-e2e.js dev",
"test:e2e:all": "cross-env E2E_TESTS=true NODE_OPTIONS=--dns-result-order=ipv4first start-server-and-test start http://localhost:5678/favicon.ico 'cypress run --headless'" "test:e2e:all": "scripts/run-e2e.js all"
}, },
"dependencies": { "dependencies": {
"n8n": "workspace:*" "n8n": "workspace:*"

View file

@ -1,19 +1,14 @@
import convict from 'convict'; import convict from 'convict';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
import { tmpdir } from 'os'; import { readFileSync } from 'fs';
import { mkdirSync, mkdtempSync, readFileSync } from 'fs';
import { join } from 'path';
import { setGlobalState } from 'n8n-workflow'; import { setGlobalState } from 'n8n-workflow';
import { schema } from './schema'; import { schema } from './schema';
import { inTest, inE2ETests } from '@/constants'; import { inTest, inE2ETests } from '@/constants';
if (inE2ETests) { if (inE2ETests) {
const testsDir = join(tmpdir(), 'n8n-e2e/');
mkdirSync(testsDir, { recursive: true });
// Skip loading config from env variables in end-to-end tests // Skip loading config from env variables in end-to-end tests
process.env = { process.env = {
E2E_TESTS: 'true', E2E_TESTS: 'true',
N8N_USER_FOLDER: mkdtempSync(testsDir),
EXECUTIONS_PROCESS: 'main', EXECUTIONS_PROCESS: 'main',
N8N_DIAGNOSTICS_ENABLED: 'false', N8N_DIAGNOSTICS_ENABLED: 'false',
N8N_PUBLIC_API_DISABLED: 'true', N8N_PUBLIC_API_DISABLED: 'true',

70
scripts/run-e2e.js Executable file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env node
const { spawn } = require('child_process');
const { mkdirSync, mkdtempSync } = require('fs');
const { tmpdir } = require('os');
const { join } = require('path');
function runTests(options) {
const testsDir = join(tmpdir(), 'n8n-e2e/');
mkdirSync(testsDir, { recursive: true });
const userFolder = mkdtempSync(testsDir);
process.env.N8N_USER_FOLDER = userFolder;
process.env.E2E_TESTS = 'true';
process.env.NODE_OPTIONS = '--dns-result-order=ipv4first';
if (options.customEnv) {
Object.keys(options.customEnv).forEach((key) => {
process.env[key] = options.customEnv[key];
});
}
const cmd = `start-server-and-test ${options.startCommand} ${options.url} '${options.testCommand}'`;
const testProcess = spawn(cmd, [], { stdio: 'inherit', shell: true });
// Listen for termination signals to properly kill the test process
process.on('SIGINT', () => {
testProcess.kill('SIGINT');
});
process.on('SIGTERM', () => {
testProcess.kill('SIGTERM');
});
testProcess.on('exit', (code) => {
process.exit(code);
});
}
const scenario = process.argv[2];
switch (scenario) {
case 'ui':
runTests({
startCommand: 'start',
url: 'http://localhost:5678/favicon.ico',
testCommand: 'cypress open',
});
break;
case 'dev':
runTests({
startCommand: 'dev',
url: 'http://localhost:8080/favicon.ico',
testCommand: 'cypress open',
customEnv: {
CYPRESS_BASE_URL: 'http://localhost:8080',
},
});
break;
case 'all':
runTests({
startCommand: 'start',
url: 'http://localhost:5678/favicon.ico',
testCommand: 'cypress run --headless',
});
break;
default:
console.error('Unknown scenario');
process.exit(1);
}