Agent Skills › NangoHQ/nango › running-tests

running-tests

GitHub

提供Nango仓库中Vitest测试运行指南,涵盖单元、集成和CLI测试命令、Docker依赖、常用工具函数及常见错误排查。

.agents/skills/running-tests/SKILL.md NangoHQ/nango

Trigger Scenarios

运行单元测试或集成测试 配置Vitest环境 调试测试失败或零测试报告

Install

npx skills add NangoHQ/nango --skill running-tests -g -y
More Options

Non-standard path

npx skills add https://github.com/NangoHQ/nango/tree/master/.agents/skills/running-tests -g -y

Use without installing

npx skills use NangoHQ/nango@running-tests

指定 Agent (Claude Code)

npx skills add NangoHQ/nango --skill running-tests -a claude-code -g -y

安装 repo 全部 skill

npx skills add NangoHQ/nango --all -g -y

预览 repo 内 skill

npx skills add NangoHQ/nango --list

SKILL.md

Frontmatter
{
    "name": "running-tests",
    "description": "Use when running tests in the Nango monorepo - knows unit vs integration configs, vitest commands, Docker setup, and common test patterns"
}

Running Tests in Nango

Overview

Nango uses Vitest with three separate configs for unit, integration, and CLI tests. Getting the config wrong silently runs zero tests.

Quick Reference

Type Command File pattern
Unit npm run test:unit *.unit.test.ts
Integration npm run test:integration *.integration.test.ts
CLI npm run test:cli *.unit.cli-test.ts
All npm run test all patterns

Running Specific Tests

# Single integration test file
npm run test:integration -- packages/server/lib/controllers/v1/team/getTeam.integration.test.ts

# Single unit test file
npm run test:unit -- packages/server/lib/authz/permissions.unit.test.ts

# Pattern match
npm run test:integration -- -t "should be protected"

All commands run from the repo root.

Before Running Tests

Always run npm install first — after pulling changes, switching branches, or in a fresh worktree. Missing deps cause import errors that look like code issues.

Integration Test Requirements

  • Docker required: Global setup (tests/setup.ts) starts PostgreSQL, Elasticsearch, ActiveMQ, and Redis via testcontainers
  • Tests run sequentially (fileParallelism: false, singleFork: true)
  • Timeout: 20 seconds per test
  • Environment: FLAG_AUTH_ROLES_ENABLED=true, timezone UTC

Writing Integration Tests

import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { seeders } from '@nangohq/shared';
import { runServer, shouldBeProtected, shouldRequireQueryEnv } from '../../../../utils/tests.js';

const route = '/api/v1/endpoint';
let api: Awaited<ReturnType<typeof runServer>>;

describe(`GET ${route}`, () => {
    beforeAll(async () => {
        api = await runServer(); // Starts Express + runs all migrations
    });
    afterAll(() => { api.server.close(); });

    it('should be protected', async () => {
        const res = await api.fetch(route, { method: 'GET', query: { env: 'dev' } });
        shouldBeProtected(res);
    });
});

Key utilities (packages/server/lib/utils/tests.ts):

  • runServer() — starts Express with DB migrations
  • shouldBeProtected(res) — asserts 401
  • shouldRequireQueryEnv(res) — asserts 400 missing env
  • authenticateUser(api, user, password) — returns session cookie (use for endpoints needing res.locals.user)
  • isSuccess(json) / isError(json) — response type guards

Seeders (@nangohq/shared):

  • seeders.seedAccountEnvAndUser() — creates account, environment, user, secret key

Custom Matchers

Available in all tests via tests/setupFiles.ts:

  • toBeIsoDate(), toBeIsoDateTimezone(), toBeUUID(), toBeSha256()
  • toBeWithinMs(expected, toleranceMs)

Common Mistakes

Mistake Symptom Fix
Wrong config for integration tests 0 tests found Use npm run test:integration not npm run test:unit
Using bearer token for session endpoints 401 errors Use authenticateUser() + session cookie
Running from package dir Config not found Always run from repo root
Docker not running Connection refused Integration tests need Docker for testcontainers
Missing query: { env: 'dev' } 400 invalid query Most endpoints require env query param

Version History

  • b75293e Current 2026-08-28 21:54

Same Skill Collection

.agents/skills/adding-audit-events/SKILL.md
.agents/skills/agent-builder-skill/SKILL.md
.agents/skills/building-and-verifying/SKILL.md
.agents/skills/creating-database-migrations/SKILL.md
.agents/skills/creating-integration-docs/SKILL.md
.agents/skills/creating-skills-skill/SKILL.md
.agents/skills/managing-analytics-events/SKILL.md
.agents/skills/running-and-testing-locally/SKILL.md
.agents/skills/ui-visual-debugging/SKILL.md

Metadata

Files
0
Version
c934467
Hash
e2e2c4df
Indexed
2026-08-28 21:54

홈 - 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-20 12:17
浙ICP备14020137号-1