# Testing with npm link

## Step 1: Link the Package

In the `apiforge-analyzer` directory:

```bash
cd /Users/harsh/Developer/APIForge/apiforge-analyzer
npm run build      # Build the package
npm link          # Create global symlink
```

## Step 2: Use in Your Test Project

### For Express Project

```bash
cd /path/to/your/express-project
npm link apiforge-analyzer
```

Test it:

```javascript
// test.js
const express = require('express')
const { analyze } = require('apiforge-analyzer')

const app = express()

app.get('/api/users', (req, res) => res.json({ users: [] }))
app.post('/api/users', (req, res) => res.json({ created: true }))

analyze(app, {
  projectName: 'Test API',
  saveJson: true,
  jsonPath: 'test-export.json',
  upload: false
}).then(() => {
  console.log('✅ Analysis complete!')
})
```

Run: `node test.js`

### For Next.js Project

```bash
cd /path/to/your/nextjs-project
npm link apiforge-analyzer
```

Create test endpoint:

```javascript
// pages/api/test-analyze.js
import { analyzeNextPages } from 'apiforge-analyzer'

export default async function handler(req, res) {
  await analyzeNextPages({
    projectName: 'My Next.js API',
    saveJson: true,
    upload: false
  })
  
  res.json({ success: true })
}
```

Visit: `http://localhost:3000/api/test-analyze`

### For Vite Project

```bash
cd /path/to/your/vite-project
npm link apiforge-analyzer
```

Test:

```javascript
// test-vite.js
import { analyzeVite } from 'apiforge-analyzer'

await analyzeVite('vite.config.js')
```

### For React Router Project

```bash
cd /path/to/your/react-project
npm link apiforge-analyzer
```

Test:

```javascript
// test-routes.js
import { analyzeReactRouter } from 'apiforge-analyzer'

await analyzeReactRouter('src/routes.tsx')
```

## Step 3: Unlink When Done

```bash
# In your test project
npm unlink apiforge-analyzer

# In apiforge-analyzer directory
npm unlink
```

## Quick Test Script

Create `test-all.js` in apiforge-analyzer directory:

```javascript
const express = require('express')
const { analyze, analyzeExpress } = require('./dist/cjs/index.js')

const app = express()
app.get('/test', (req, res) => res.json({ ok: true }))
app.post('/users/:id', (req, res) => res.json({ id: req.params.id }))

analyze(app, {
  projectName: 'Local Test',
  saveJson: true,
  jsonPath: './test-output.json',
  upload: false
}).then(() => {
  console.log('✅ Test passed!')
  console.log('Check test-output.json')
}).catch(err => {
  console.error('❌ Test failed:', err)
})
```

Run: `node test-all.js`

## Verify It Works

After running, check:
1. `test-output.json` should exist
2. Should contain your routes
3. Console should show "✅ Test passed!"
