Skip to main content

Developer Guide

Welcome to the TrendGate Developer documentation. This guide will help you integrate TrendGate into your development workflow and CI/CD pipelines.

🚀 Quick Start

1. Install TrendGate CLI

# npm
npm install -g @trendgate/cli

# yarn
yarn global add @trendgate/cli

# pnpm
pnpm add -g @trendgate/cli

2. Authenticate

# Login with your TrendGate account
trendgate auth login

# Or use API key
export TRENDGATE_API_KEY=tg_live_your_api_key

3. Initialize Your Project

cd your-project
trendgate init

# This creates .trendgate.yml with default configuration

4. Run Your First Analysis

# Run tests and submit results
npm test -- --coverage
trendgate submit --auto-detect

🔑 API Key Management

Creating API Keys

As a Developer, you can create API keys for CI/CD integration:

  1. Go to Settings → API Keys
  2. Click Create New Key
  3. Name it descriptively (e.g., "GitHub Actions Production")
  4. Copy immediately - it won't be shown again!

Using API Keys

# Environment variable (recommended)
export TRENDGATE_API_KEY=tg_live_xxxxx

# CLI parameter
trendgate submit --api-key=tg_live_xxxxx

# Configuration file
echo "api_key: tg_live_xxxxx" >> .trendgate.yml

Best Practices

  • Use different keys for different environments
  • Rotate keys every 90 days
  • Never commit keys to version control
  • Use environment-specific key names

🔧 CI/CD Integration

GitHub Actions

name: Quality Check
on: [push, pull_request]

jobs:
test-and-analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Run tests with coverage
run: npm test -- --coverage --json --outputFile=test-results.json

- name: Submit to TrendGate
uses: trendgate/action@v1
with:
api-key: ${{ secrets.TRENDGATE_API_KEY }}
test-results: test-results.json
coverage-file: coverage/lcov.info
fail-on-regression: true

GitLab CI

quality_check:
script:
- npm ci
- npm test -- --coverage
- npx @trendgate/cli submit
variables:
TRENDGATE_API_KEY: $TRENDGATE_API_KEY
only:
- merge_requests
- main

Jenkins

pipeline {
agent any

environment {
TRENDGATE_API_KEY = credentials('trendgate-api-key')
}

stages {
stage('Test') {
steps {
sh 'npm test -- --coverage'
}
}

stage('Quality Analysis') {
steps {
sh 'npx @trendgate/cli submit'
}
}
}
}

📊 Test Result Formats

TrendGate supports multiple test result formats:

Jest

{
"testResults": [{
"name": "test suite",
"status": "passed",
"numPassingTests": 10,
"numFailingTests": 0
}]
}

Playwright

{
"config": {},
"suites": [{
"title": "e2e tests",
"specs": [{
"title": "should work",
"ok": true
}]
}]
}

Coverage (LCOV)

TN:
SF:src/index.js
FN:1,myFunction
FNDA:1,myFunction
FNF:1
FNH:1

🤖 MCP Server Integration

TrendGate provides an MCP (Model Context Protocol) server for AI agents:

Setup

# Install MCP server
npm install @trendgate/mcp-server

# Configure in your AI tool
{
"mcpServers": {
"trendgate": {
"command": "npx",
"args": ["@trendgate/mcp-server"],
"env": {
"TRENDGATE_API_KEY": "tg_live_xxxxx"
}
}
}
}

Available Tools

// Query test trends
const trends = await mcp.call('query_test_trends', {
module: 'src/payments',
timeRange: '7d',
metrics: ['pass_rate', 'coverage']
});

// Trigger quality evaluation
const result = await mcp.call('evaluate_quality', {
branch: 'feature/new-feature',
baseline: 'main'
});

// Generate quality report
const report = await mcp.call('generate_report', {
format: 'markdown',
includeCharts: true
});

💻 Local Development

VS Code Extension

Install the TrendGate extension for real-time quality feedback:

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "TrendGate"
  4. Install and configure with API key

Features:

  • Inline coverage indicators
  • Test status in file explorer
  • Quality metrics in status bar
  • Quick actions for running tests

Pre-commit Hooks

# Install husky
npm install --save-dev husky

# Add TrendGate check
npx husky add .husky/pre-push "npx trendgate check --fail-on-regression"

🛠️ Configuration Reference

Complete .trendgate.yml Example

version: 1
project: my-app

# API Configuration
api:
endpoint: https://api.trendgate.ai
timeout: 30000

# Test Configuration
tests:
frameworks:
- jest
- playwright
patterns:
- "**/*.test.{js,ts}"
- "**/*.spec.{js,ts}"
exclude:
- "node_modules/**"
- "dist/**"

# Quality Policies
policies:
test_pass_rate:
threshold: 95
enforce: true

coverage:
line: 80
branch: 75
function: 90
enforce: true

performance:
lighthouse:
performance: 85
accessibility: 95
enforce: false

# Baseline Configuration
baseline:
branch: main
strategy: rolling_average
window: 7

# Notifications
notifications:
slack:
webhook: ${SLACK_WEBHOOK}
channels:
success: "#deployments"
failure: "#alerts"

📈 Best Practices

1. Incremental Adoption

  • Start with test pass rate monitoring
  • Add coverage once stable
  • Enable enforcement gradually
  • Add performance metrics last

2. Branch Strategy

# Feature branches - lenient
feature/*:
test_pass_rate: 90
enforce: false

# Develop - moderate
develop:
test_pass_rate: 95
coverage: 75
enforce: true

# Main - strict
main:
test_pass_rate: 98
coverage: 85
enforce: true

3. Handling Flaky Tests

  • Tag flaky tests in code
  • Exclude from quality gates
  • Track separately
  • Fix incrementally

4. Performance Optimization

  • Run TrendGate analysis in parallel with other CI tasks
  • Use incremental coverage for large codebases
  • Cache test results when possible
  • Submit results asynchronously

🔍 Debugging

Common Issues

"API key not valid"

# Verify key is set
echo $TRENDGATE_API_KEY

# Test authentication
trendgate auth verify

"Test results not found"

# Check file paths
trendgate submit --test-results=./path/to/results.json --debug

# Verify format
trendgate validate ./test-results.json

"Quality gate failed unexpectedly"

# Check current baseline
trendgate baseline show

# Compare with previous run
trendgate compare HEAD~1

Debug Mode

Enable verbose logging:

# CLI
trendgate submit --debug

# Environment variable
export TRENDGATE_DEBUG=true

# Configuration
debug: true

📚 Additional Resources

Need help? Join our Developer Discord or email dev-support@trendgate.ai