-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Problem
Currently, 46 integration tests in tests/integration/n8n-api/workflows/smart-parameters.test.ts are failing in CI with "No response from n8n server" because they require:
- A running n8n instance
- Valid API credentials (N8N_API_URL, N8N_API_KEY)
- Test webhook URLs
This blocks contributor PRs from passing CI checks, as contributors don't have access to these credentials.
Root Cause
These tests are labeled "integration tests" but are actually end-to-end tests requiring external infrastructure. True integration tests should:
- Use mocked HTTP responses (MSW - Mock Service Worker)
- Test code integration, not external API availability
- Run successfully in any CI environment
Affected files:
tests/integration/n8n-api/workflows/smart-parameters.test.ts(46 failing tests)tests/integration/n8n-api/workflows/autofix-workflow.test.ts- All tests using
getTestN8nClient()
Current Impact
- 46 tests fail on every PR unless n8n credentials are available
- Contributors cannot run these tests locally without a real n8n instance
- PR checks block merging even for unrelated code changes
- CI workflow has empty environment variables for n8n credentials
Proposed Solution
1. Immediate Fix (Short-term)
Add skip logic when credentials aren't available:
// In test setup files
beforeAll(() => {
if (process.env.CI && \!process.env.N8N_API_URL) {
console.warn('⚠️ Skipping n8n API integration tests - credentials not available');
console.warn('These tests require N8N_API_URL and N8N_API_KEY to be set');
process.exit(0); // Exit with success to not block CI
}
});2. Long-term Solution (Recommended)
Restructure test architecture into three distinct tiers:
tests/
├── unit/ # Pure logic, no external dependencies (✅ already working)
├── integration/ # Mocked HTTP responses using MSW (⚠️ needs refactoring)
└── e2e/ # Real n8n instance required (❌ should be optional)
└── README.md # Documentation: "Run with: N8N_API_URL=... npm run test:e2e"
Benefits:
- Integration tests use MSW to mock n8n API responses
- Tests validate request/response handling without real infrastructure
- All tests can run in any CI environment
- E2E tests become optional for contributors
3. Implementation Steps
-
Install MSW (Mock Service Worker)
npm install -D msw
-
Create mock handlers for n8n API
// tests/mocks/n8n-api-handlers.ts import { http, HttpResponse } from 'msw'; export const n8nHandlers = [ http.post('*/workflows', () => { return HttpResponse.json({ id: 'test-workflow-id', ... }); }), http.patch('*/workflows/:id', () => { return HttpResponse.json({ success: true }); }), // ... more handlers ];
-
Refactor integration tests to use mocks
import { setupServer } from 'msw/node'; import { n8nHandlers } from '../../mocks/n8n-api-handlers'; const server = setupServer(...n8nHandlers); beforeAll(() => server.listen()); afterEach(() => server.resetHandlers()); afterAll(() => server.close());
-
Move real API tests to e2e directory
mv tests/integration/n8n-api/workflows/smart-parameters.test.ts tests/e2e/
-
Update CI workflows
# .github/workflows/test.yml - Always runs - name: Run unit and integration tests run: | npm run test:unit npm run test:integration # Now uses MSW mocks # .github/workflows/test-e2e.yml - Manual trigger only - name: Run E2E tests if: github.event_name == 'workflow_dispatch' run: npm run test:e2e
Acceptance Criteria
- Integration tests run successfully without real n8n credentials
- All contributor PRs can pass CI checks
- E2E tests are separated and marked as optional
- Documentation updated with instructions for running E2E tests locally
- MSW configured for mocking n8n API responses
- Test coverage maintained or improved
Related
- Discovered in PR fix: Add commit-based release notes to GitHub releases #355 review
- Affects all PRs that trigger integration test suite
- Blocks contributor workflows
Priority
High - This blocks all contributor PRs from merging successfully.
Conceived by Romuald Członkowski - www.aiadvisors.pl/en