test: Split up unit and integration tests for CI (#21438)

This commit is contained in:
Declan Carroll
2025-10-31 17:59:44 +00:00
committed by GitHub
parent 210f7c7eca
commit f9ae948f15
10 changed files with 90 additions and 10 deletions

View File

@@ -27,10 +27,10 @@ env:
jobs:
unit-test-backend:
name: Backend
name: Backend Unit Tests
runs-on: blacksmith-4vcpu-ubuntu-2204
env:
COVERAGE_ENABLED: ${{ inputs.collectCoverage }}
COVERAGE_ENABLED: ${{ inputs.collectCoverage }} # Coverage collected when true
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
@@ -41,20 +41,54 @@ jobs:
with:
node-version: ${{ inputs.nodeVersion }}
- name: Test
run: pnpm test:ci:backend
- name: Test Unit
run: pnpm test:ci:backend:unit
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: backend-unit
- name: Upload coverage to Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: backend
flags: backend-unit
name: backend-unit
integration-test-backend:
name: Backend Integration Tests
runs-on: blacksmith-4vcpu-ubuntu-2204
env:
COVERAGE_ENABLED: ${{ inputs.collectCoverage }} # Coverage collected when true
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ inputs.ref }}
- name: Build
uses: n8n-io/n8n/.github/actions/setup-nodejs-blacksmith@f5fbbbe0a28a886451c886cac6b49192a39b0eea # v1.104.1
with:
node-version: ${{ inputs.nodeVersion }}
- name: Test Integration
run: pnpm test:ci:backend:integration
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: backend-integration
- name: Upload coverage to Codecov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: backend-integration
name: backend-integration
unit-test-frontend:
name: Frontend (${{ matrix.shard }}/2)
@@ -97,9 +131,9 @@ jobs:
unit-test:
name: Unit tests
runs-on: ubuntu-latest
needs: [unit-test-backend, unit-test-frontend]
needs: [unit-test-backend, integration-test-backend, unit-test-frontend]
if: always()
steps:
- name: Fail if tests failed
if: needs.unit-test-backend.result == 'failure' || needs.unit-test-frontend.result == 'failure'
if: needs.unit-test-backend.result == 'failure' || needs.integration-test-backend.result == 'failure' || needs.unit-test-frontend.result == 'failure'
run: exit 1

View File

@@ -42,6 +42,8 @@
"test:ci": "turbo run test --continue --concurrency=1",
"test:ci:frontend": "turbo run test --continue --filter='./packages/frontend/**'",
"test:ci:backend": "turbo run test --continue --concurrency=1 --filter='!./packages/frontend/**'",
"test:ci:backend:unit": "turbo run test:unit --continue --filter='!./packages/frontend/**'",
"test:ci:backend:integration": "turbo run test:integration --continue --concurrency=1 --filter='!./packages/frontend/**'",
"test:affected": "turbo run test --affected --concurrency=1",
"test:with:docker": "pnpm --filter=n8n-playwright test:container:standard",
"test:show:report": "pnpm --filter=n8n-playwright exec playwright show-report",

View File

@@ -1,7 +1,10 @@
import { defineConfig } from 'eslint/config';
import { defineConfig, globalIgnores } from 'eslint/config';
import { nodeConfig } from '@n8n/eslint-config/node';
export default defineConfig(nodeConfig, {
export default defineConfig(
globalIgnores(['jest.config*.js']),
nodeConfig,
{
rules: {
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
complexity: 'error',

View File

@@ -0,0 +1,8 @@
/** @type {import('jest').Config} */
module.exports = {
...require('./jest.config'),
// Run only integration tests
testRegex: undefined, // Override base config testRegex
testMatch: ['**/*.integration.test.ts'],
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
};

View File

@@ -0,0 +1,10 @@
/** @type {import('jest').Config} */
module.exports = {
...require('./jest.config'),
// Exclude integration tests - only run unit tests
testPathIgnorePatterns: [
'/dist/',
'/node_modules/',
'\\.integration\\.test\\.ts$', // Exclude integration test files
],
};

View File

@@ -8,6 +8,8 @@
"format": "biome format --write src",
"format:check": "biome ci src",
"test": "jest",
"test:unit": "jest --config=jest.config.unit.js",
"test:integration": "jest --config=jest.config.integration.js",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"lint": "eslint . --quiet",

View File

@@ -2,7 +2,7 @@ import { defineConfig, globalIgnores } from 'eslint/config';
import { nodeConfig } from '@n8n/eslint-config/node';
export default defineConfig(
globalIgnores(['scripts/**/*.mjs', 'jest.config.integration.js']),
globalIgnores(['scripts/**/*.mjs', 'jest.config*.js']),
nodeConfig,
{
rules: {

View File

@@ -0,0 +1,11 @@
/** @type {import('jest').Config} */
module.exports = {
...require('./jest.config'),
// Exclude integration tests - only run unit tests
testPathIgnorePatterns: [
'/dist/',
'/node_modules/',
'/test/integration/', // Exclude integration test directory
'\\.integration\\.test\\.ts$', // Exclude integration test files in src
],
};

View File

@@ -21,6 +21,8 @@
"start:default": "cd bin && ./n8n",
"start:windows": "cd bin && n8n",
"test": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest",
"test:unit": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.unit.js",
"test:integration": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.integration.js",
"test:dev": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --watch",
"test:sqlite": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.integration.js --no-coverage",
"test:postgres": "N8N_LOG_LEVEL=silent DB_TYPE=postgresdb DB_POSTGRESDB_SCHEMA=alt_schema DB_TABLE_PREFIX=test_ jest --config=jest.config.integration.js --no-coverage",

View File

@@ -25,6 +25,14 @@
"dependsOn": ["^build", "build"],
"outputs": ["coverage/**", "*.xml"]
},
"test:unit": {
"dependsOn": ["^build", "build"],
"outputs": ["coverage/**", "*.xml"]
},
"test:integration": {
"dependsOn": ["^build", "build"],
"outputs": ["coverage/**", "*.xml"]
},
"watch": { "cache": false, "persistent": true },
"dev": { "cache": false, "persistent": true },
"build:playwright": {