Insolitum Developers
Guides

Testing

Testing strategies for Insolitum Universe modules. Unit tests, component tests, E2E tests, and CI/CD pipeline.

Testing

A well-tested module passes marketplace review faster and maintains reliability for users.

Health Endpoint Test

The module-starter includes a basic health endpoint test:

tests/health.test.ts
import { describe, it, expect } from 'vitest';
 
describe('Health Endpoint', () => {
  it('returns status ok', async () => {
    const response = await fetch('http://localhost:3010/api/health');
    const data = await response.json();
 
    expect(response.status).toBe(200);
    expect(data.status).toBe('ok');
    expect(data.module).toBeDefined();
    expect(data.version).toBeDefined();
    expect(data.timestamp).toBeDefined();
  });
});

Unit Tests with Vitest

pnpm add -D vitest @testing-library/react @testing-library/jest-dom jsdom
vitest.config.ts
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
 
export default defineConfig({
  plugins: [react()],
  test: {
    environment: 'jsdom',
    setupFiles: './tests/setup.ts',
  },
});

Testing Hooks

tests/useModuleApi.test.ts
import { renderHook } from '@testing-library/react';
import { useModuleApi } from '@/hooks/useModuleApi';
 
// Mock ShellAuthProvider context
vi.mock('@/lib/shell-auth', () => ({
  useShellAuth: () => ({
    organizationId: 'test-org-id',
    user: { id: 'test-user', email: 'test@example.com' },
    isAuthenticated: true,
  }),
}));
 
describe('useModuleApi', () => {
  it('provides query function', () => {
    const { result } = renderHook(() => useModuleApi());
    expect(result.current.query).toBeDefined();
    expect(result.current.organizationId).toBe('test-org-id');
  });
});

E2E Tests with Playwright

pnpm add -D @playwright/test
npx playwright install
e2e/module.spec.ts
import { test, expect } from '@playwright/test';
 
test('module loads and shows dashboard', async ({ page }) => {
  await page.goto('http://localhost:3010');
 
  // Should show loading state initially
  await expect(page.getByText('Oczekiwanie na autoryzacje')).toBeVisible();
});
 
test('health endpoint returns ok', async ({ request }) => {
  const response = await request.get('http://localhost:3010/api/health');
  const data = await response.json();
 
  expect(response.ok()).toBeTruthy();
  expect(data.status).toBe('ok');
});

CI/CD Pipeline

The module-starter includes a GitHub Actions workflow:

.github/workflows/ci.yml
name: CI
 
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
 
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v2
        with:
          version: 8
      - uses: actions/setup-node@v4
        with:
          node-version: 18
          cache: pnpm
      - run: pnpm install
      - run: pnpm typecheck
      - run: pnpm lint
      - run: pnpm build

Test Checklist Before Submission

  • Health endpoint returns { status: "ok" } with 200
  • Module builds without errors (pnpm build)
  • TypeScript compiles without errors (pnpm typecheck)
  • Linter passes (pnpm lint)
  • Module loads correctly in universe-shell iframe
  • Auth handshake works (user info displayed)
  • Data queries are scoped to organization_id
  • Module works with dark theme
  • No console errors in production build

On this page