Skip to content

Commit f9ae948

Browse files
authored
test: Split up unit and integration tests for CI (#21438)
1 parent 210f7c7 commit f9ae948

File tree

10 files changed

+90
-10
lines changed

10 files changed

+90
-10
lines changed

.github/workflows/units-tests-reusable.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ env:
2727

2828
jobs:
2929
unit-test-backend:
30-
name: Backend
30+
name: Backend Unit Tests
3131
runs-on: blacksmith-4vcpu-ubuntu-2204
3232
env:
33-
COVERAGE_ENABLED: ${{ inputs.collectCoverage }}
33+
COVERAGE_ENABLED: ${{ inputs.collectCoverage }} # Coverage collected when true
3434
steps:
3535
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3636
with:
@@ -41,20 +41,54 @@ jobs:
4141
with:
4242
node-version: ${{ inputs.nodeVersion }}
4343

44-
- name: Test
45-
run: pnpm test:ci:backend
44+
- name: Test Unit
45+
run: pnpm test:ci:backend:unit
46+
47+
- name: Upload test results to Codecov
48+
if: ${{ !cancelled() }}
49+
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
50+
with:
51+
token: ${{ secrets.CODECOV_TOKEN }}
52+
name: backend-unit
53+
54+
- name: Upload coverage to Codecov
55+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
56+
with:
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
flags: backend-unit
59+
name: backend-unit
60+
61+
integration-test-backend:
62+
name: Backend Integration Tests
63+
runs-on: blacksmith-4vcpu-ubuntu-2204
64+
env:
65+
COVERAGE_ENABLED: ${{ inputs.collectCoverage }} # Coverage collected when true
66+
steps:
67+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
68+
with:
69+
ref: ${{ inputs.ref }}
70+
71+
- name: Build
72+
uses: n8n-io/n8n/.github/actions/setup-nodejs-blacksmith@f5fbbbe0a28a886451c886cac6b49192a39b0eea # v1.104.1
73+
with:
74+
node-version: ${{ inputs.nodeVersion }}
75+
76+
- name: Test Integration
77+
run: pnpm test:ci:backend:integration
4678

4779
- name: Upload test results to Codecov
4880
if: ${{ !cancelled() }}
4981
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
5082
with:
5183
token: ${{ secrets.CODECOV_TOKEN }}
84+
name: backend-integration
5285

5386
- name: Upload coverage to Codecov
5487
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
5588
with:
5689
token: ${{ secrets.CODECOV_TOKEN }}
57-
flags: backend
90+
flags: backend-integration
91+
name: backend-integration
5892

5993
unit-test-frontend:
6094
name: Frontend (${{ matrix.shard }}/2)
@@ -97,9 +131,9 @@ jobs:
97131
unit-test:
98132
name: Unit tests
99133
runs-on: ubuntu-latest
100-
needs: [unit-test-backend, unit-test-frontend]
134+
needs: [unit-test-backend, integration-test-backend, unit-test-frontend]
101135
if: always()
102136
steps:
103137
- name: Fail if tests failed
104-
if: needs.unit-test-backend.result == 'failure' || needs.unit-test-frontend.result == 'failure'
138+
if: needs.unit-test-backend.result == 'failure' || needs.integration-test-backend.result == 'failure' || needs.unit-test-frontend.result == 'failure'
105139
run: exit 1

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
"test:ci": "turbo run test --continue --concurrency=1",
4343
"test:ci:frontend": "turbo run test --continue --filter='./packages/frontend/**'",
4444
"test:ci:backend": "turbo run test --continue --concurrency=1 --filter='!./packages/frontend/**'",
45+
"test:ci:backend:unit": "turbo run test:unit --continue --filter='!./packages/frontend/**'",
46+
"test:ci:backend:integration": "turbo run test:integration --continue --concurrency=1 --filter='!./packages/frontend/**'",
4547
"test:affected": "turbo run test --affected --concurrency=1",
4648
"test:with:docker": "pnpm --filter=n8n-playwright test:container:standard",
4749
"test:show:report": "pnpm --filter=n8n-playwright exec playwright show-report",

packages/@n8n/ai-workflow-builder.ee/eslint.config.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { defineConfig } from 'eslint/config';
1+
import { defineConfig, globalIgnores } from 'eslint/config';
22
import { nodeConfig } from '@n8n/eslint-config/node';
33

4-
export default defineConfig(nodeConfig, {
4+
export default defineConfig(
5+
globalIgnores(['jest.config*.js']),
6+
nodeConfig,
7+
{
58
rules: {
69
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
710
complexity: 'error',
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
...require('./jest.config'),
4+
// Run only integration tests
5+
testRegex: undefined, // Override base config testRegex
6+
testMatch: ['**/*.integration.test.ts'],
7+
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
8+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
...require('./jest.config'),
4+
// Exclude integration tests - only run unit tests
5+
testPathIgnorePatterns: [
6+
'/dist/',
7+
'/node_modules/',
8+
'\\.integration\\.test\\.ts$', // Exclude integration test files
9+
],
10+
};

packages/@n8n/ai-workflow-builder.ee/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"format": "biome format --write src",
99
"format:check": "biome ci src",
1010
"test": "jest",
11+
"test:unit": "jest --config=jest.config.unit.js",
12+
"test:integration": "jest --config=jest.config.integration.js",
1113
"test:coverage": "jest --coverage",
1214
"test:watch": "jest --watch",
1315
"lint": "eslint . --quiet",

packages/cli/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig, globalIgnores } from 'eslint/config';
22
import { nodeConfig } from '@n8n/eslint-config/node';
33

44
export default defineConfig(
5-
globalIgnores(['scripts/**/*.mjs', 'jest.config.integration.js']),
5+
globalIgnores(['scripts/**/*.mjs', 'jest.config*.js']),
66
nodeConfig,
77
{
88
rules: {

packages/cli/jest.config.unit.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
...require('./jest.config'),
4+
// Exclude integration tests - only run unit tests
5+
testPathIgnorePatterns: [
6+
'/dist/',
7+
'/node_modules/',
8+
'/test/integration/', // Exclude integration test directory
9+
'\\.integration\\.test\\.ts$', // Exclude integration test files in src
10+
],
11+
};

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"start:default": "cd bin && ./n8n",
2222
"start:windows": "cd bin && n8n",
2323
"test": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest",
24+
"test:unit": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.unit.js",
25+
"test:integration": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.integration.js",
2426
"test:dev": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --watch",
2527
"test:sqlite": "N8N_LOG_LEVEL=silent DB_TYPE=sqlite jest --config=jest.config.integration.js --no-coverage",
2628
"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",

turbo.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
"dependsOn": ["^build", "build"],
2626
"outputs": ["coverage/**", "*.xml"]
2727
},
28+
"test:unit": {
29+
"dependsOn": ["^build", "build"],
30+
"outputs": ["coverage/**", "*.xml"]
31+
},
32+
"test:integration": {
33+
"dependsOn": ["^build", "build"],
34+
"outputs": ["coverage/**", "*.xml"]
35+
},
2836
"watch": { "cache": false, "persistent": true },
2937
"dev": { "cache": false, "persistent": true },
3038
"build:playwright": {

0 commit comments

Comments
 (0)