From 500775de6958535ef72a6cf88b36cbf65f8cb21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 24 Nov 2022 12:49:01 +0100 Subject: [PATCH] ci: Make end-to-end testing independent of development environments (no-changelog) (#4709) * use user-folder override consistently everywhere, including for the `.cache` folder * use consistent config for e2e tesing, skipping config loading from env and config files * simplify all the cypress commands, and run all e2e tests on master --- .github/workflows/ci-master.yml | 2 +- .github/workflows/ci-pull-requests.yml | 2 +- package.json | 10 ++-- .../src/UserManagement/email/NodeMailer.ts | 2 +- packages/cli/src/config/index.ts | 47 +++++++++++++++---- packages/core/src/UserSettings.ts | 32 ++++++------- 6 files changed, 57 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci-master.yml b/.github/workflows/ci-master.yml index 3b0e6d3ea6..a7c64be892 100644 --- a/.github/workflows/ci-master.yml +++ b/.github/workflows/ci-master.yml @@ -38,7 +38,7 @@ jobs: - name: Test E2E run: | pnpm cypress:install - pnpm test:e2e:ci:smoke + pnpm test:e2e:all - name: Lint env: diff --git a/.github/workflows/ci-pull-requests.yml b/.github/workflows/ci-pull-requests.yml index 433a58c976..130e1753bd 100644 --- a/.github/workflows/ci-pull-requests.yml +++ b/.github/workflows/ci-pull-requests.yml @@ -35,7 +35,7 @@ jobs: - name: Test E2E run: | pnpm cypress:install - pnpm test:e2e:ci:smoke + pnpm test:e2e:smoke - name: Fetch base branch for `git diff` run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} diff --git a/package.json b/package.json index e6fb0998da..2e582f0b89 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,9 @@ "webhook": "./packages/cli/bin/n8n webhook", "worker": "./packages/cli/bin/n8n worker", "cypress:install": "cypress install", - "test:e2e:db:clean": "rimraf ~/.n8n/cypress.sqlite", - "test:e2e:cypress:run": "cypress run", - "test:e2e": "pnpm test:e2e:db:clean && cross-env DB_SQLITE_DATABASE=cypress.sqlite N8N_DIAGNOSTICS_ENABLED=false start-server-and-test start http://localhost:5678/favicon.ico test:e2e:cypress:run", - "test:e2e:cypress:dev": "cypress open", - "test:e2e:dev": "pnpm test:e2e:db:clean && cross-env DB_SQLITE_DATABASE=cypress.sqlite N8N_DIAGNOSTICS_ENABLED=false CYPRESS_BASE_URL=http://localhost:8080 start-server-and-test dev http://localhost:8080/favicon.ico test:e2e:cypress:dev", - "test:e2e:cypress:ci:smoke": "cypress run --headless --spec \"cypress/e2e/0-smoke.cy.ts\"", - "test:e2e:ci:smoke": "pnpm test:e2e:db:clean && cross-env DB_SQLITE_DATABASE=cypress.sqlite N8N_DIAGNOSTICS_ENABLED=false start-server-and-test start http://localhost:5678/favicon.ico test:e2e:cypress:ci:smoke" + "test:e2e:dev": "cross-env E2E_TESTS=true CYPRESS_BASE_URL=http://localhost:8080 start-server-and-test dev http://localhost:8080/favicon.ico 'cypress open'", + "test:e2e:smoke": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress run --headless --spec \"cypress/e2e/0-smoke.cy.ts\"'", + "test:e2e:all": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress run'" }, "dependencies": { "n8n": "*" diff --git a/packages/cli/src/UserManagement/email/NodeMailer.ts b/packages/cli/src/UserManagement/email/NodeMailer.ts index e078157b70..7b4f8dcbc2 100644 --- a/packages/cli/src/UserManagement/email/NodeMailer.ts +++ b/packages/cli/src/UserManagement/email/NodeMailer.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { createTransport, Transporter } from 'nodemailer'; import { ErrorReporterProxy as ErrorReporter, LoggerProxy as Logger } from 'n8n-workflow'; -import * as config from '@/config'; +import config from '@/config'; import { MailData, SendEmailResult, UserManagementMailerImplementation } from './Interfaces'; export class NodeMailer implements UserManagementMailerImplementation { diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts index a994cd7429..80f632f0f8 100644 --- a/packages/cli/src/config/index.ts +++ b/packages/cli/src/config/index.ts @@ -1,28 +1,55 @@ +/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable no-console */ import convict from 'convict'; import dotenv from 'dotenv'; +import { tmpdir } from 'os'; +import { mkdtempSync } from 'fs'; +import { join } from 'path'; import { schema } from './schema'; -dotenv.config(); +const inE2ETests = process.env.E2E_TESTS === 'true'; + +if (inE2ETests) { + // Skip loading config from env variables in end-to-end tests + process.env = { + N8N_USER_FOLDER: mkdtempSync(join(tmpdir(), 'n8n-e2e-')), + N8N_DIAGNOSTICS_ENABLED: 'false', + N8N_PUBLIC_API_DISABLED: 'true', + EXTERNAL_FRONTEND_HOOKS_URLS: '', + N8N_PERSONALIZATION_ENABLED: 'false', + }; +} else { + dotenv.config(); +} const config = convict(schema); +if (inE2ETests) { + config.set('enterprise.features.sharing', true); + config.set('enterprise.workflowSharingEnabled', true); +} + config.getEnv = config.get; -// Overwrite default configuration with settings which got defined in -// optional configuration files -if (process.env.N8N_CONFIG_FILES !== undefined) { - const configFiles = process.env.N8N_CONFIG_FILES.split(','); - if (process.env.NODE_ENV !== 'test') { - console.log(`\nLoading configuration overwrites from:\n - ${configFiles.join('\n - ')}\n`); - } +if (!inE2ETests) { + // Overwrite default configuration with settings which got defined in + // optional configuration files + const { N8N_CONFIG_FILES, NODE_ENV } = process.env; + if (N8N_CONFIG_FILES !== undefined) { + const configFiles = N8N_CONFIG_FILES.split(','); + if (NODE_ENV !== 'test') { + console.log(`\nLoading configuration overwrites from:\n - ${configFiles.join('\n - ')}\n`); + } - config.loadFile(configFiles); + config.loadFile(configFiles); + } } config.validate({ allowed: 'strict', }); -export = config; +// eslint-disable-next-line import/no-default-export +export default config; +export type Config = typeof config; diff --git a/packages/core/src/UserSettings.ts b/packages/core/src/UserSettings.ts index 4ba0bcae59..cef8db649b 100644 --- a/packages/core/src/UserSettings.ts +++ b/packages/core/src/UserSettings.ts @@ -229,14 +229,7 @@ export function getUserSettingsPath(): string { * */ export function getUserN8nFolderPath(): string { - let userFolder; - if (process.env[USER_FOLDER_ENV_OVERWRITE] !== undefined) { - userFolder = process.env[USER_FOLDER_ENV_OVERWRITE]; - } else { - userFolder = getUserHome(); - } - - return path.join(userFolder, USER_SETTINGS_SUBFOLDER); + return path.join(getUserHome(), USER_SETTINGS_SUBFOLDER); } /** @@ -264,16 +257,19 @@ export function getUserN8nFolderDownloadedNodesPath(): string { * */ export function getUserHome(): string { - let variableName = 'HOME'; - if (process.platform === 'win32') { - variableName = 'USERPROFILE'; - } + if (process.env[USER_FOLDER_ENV_OVERWRITE] !== undefined) { + return process.env[USER_FOLDER_ENV_OVERWRITE]; + } else { + let variableName = 'HOME'; + if (process.platform === 'win32') { + variableName = 'USERPROFILE'; + } - if (process.env[variableName] === undefined) { - // If for some reason the variable does not exist - // fall back to current folder - return process.cwd(); + if (process.env[variableName] === undefined) { + // If for some reason the variable does not exist + // fall back to current folder + return process.cwd(); + } + return process.env[variableName] as string; } - - return process.env[variableName] as string; }