Nx testing

From qauth-labs/qauth · View interactive version

Nx testing is an AI agent skill from the GitHub repository qauth-labs/qauth. Testing workflows with Vitest in Nx monorepo. Use when writing tests, running test suites, or debugging test failures.

How to use this skill

Skill file

Nx Testing Workflows

Test Stack

Running Tests

# Single project
pnpm nx test auth-server
pnpm nx test auth-server --watch
pnpm nx test auth-server --coverage

# Multiple projects
pnpm nx run-many -t test --all
pnpm nx affected -t test
pnpm nx run-many -t test --all --parallel=3

# Vitest UI
pnpm test:ui

Test File Patterns

Co-locate tests with source:

libs/server/jwt/src/
├── jwt.service.ts
├── jwt.service.spec.ts
└── index.ts

Unit Test Example

import { describe, it, expect, beforeEach } from 'vitest';
import { createService } from './service';

describe('Service', () => {
  let service: ReturnType<typeof createService>;

  beforeEach(() => {
    service = createService();
  });

  it('should do something', () => {
    expect(service.method()).toBe(expected);
  });
});

Integration Test with Fastify

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { buildTestApp } from '@qauth-labs/shared-testing';
import type { FastifyInstance } from 'fastify';

describe('Route', () => {
  let app: FastifyInstance;

  beforeAll(async () => {
    app = await buildTestApp();
  });

  afterAll(async () => {
    await app.close();
  });

  it('should return 200', async () => {
    const response = await app.inject({
      method: 'GET',
      url: '/health',
    });
    expect(response.statusCode).toBe(200);
  });
});

Best Practices

  1. Test business logic in isolation
  2. Use @qauth-labs/shared-testing utilities
  3. Use Testcontainers for real PostgreSQL
  4. Mock external services
  5. Name tests descriptively
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.