Files
n8n/packages/nodes-base/TESTING.MD
alighasami 3d5eaf9445
Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

1.8 KiB

To write unit tests it is suggested to use AI for help.

Approach for standard unit tests

  1. Create the test file: Decide which node you want to test and create a test file with the corresponding name in the test folder. For example, for a node in nodeA/v2/NodeAV2.node.ts, create a test file in nodeA/v2/test/NodeAV2.test.ts.

  2. Use AI assistance: Send this prompt to your AI tool (Cursor, Copilot, Claude, etc.):

    Using guidelines in @TESTING_PROMPT.md, write tests for @NodeAV2.node.ts in @NodeAV2.node.test.ts
    

    Make sure file names after @ are detected and referenced by your tool. You can improve the prompt by asking to cover specific test cases.

  3. Review and refine: Thoroughly review the generated tests, make necessary fixes, and remove redundant tests. Even if generated by AI, it's still your responsibility to ensure tests are working and reasonable.

Approach for workflow unit tests

Workflow unit tests are tests that use user predefined workflows in json format and NodeTestHarness helper that runs the workflow. This is closer to integration tests.

For these tests you can follow the guidelines defined above, but with some modifications:

  • Use TESTING_PROMPT_WORKFLOW.md instead
  • Use a different prompt. It's also important to specify a credentials schema if any credentials are being used, because AI struggles with identifying the schema. You can use the following prompt:
I need you to write workflow unit tests for @NodeAV2.node.ts in @NodeAV2.node.test.ts
using guidelines in @TESTING_PROMPT_WORKFLOW.md 
You should test each resource and operation in the node
After writing a first test make sure it passes, then write other tests.

To mock credentials use this schema
oauth2: {
    scope: '',
    oauthTokenData: {
      access_token: 'ACCESSTOKEN',
    },
  }