UNPKG

grt

Version:

grt command-line interface โ€” test, diff, preview APIs

55 lines (46 loc) โ€ข 1.79 kB
import axios from 'axios'; import { getToken } from './config.js'; import chalk from 'chalk'; export async function runTest({ owner, repo, ref, url, auth }) { const greatlabsToken = process.env.greatlabs_TOKEN || getToken(); console.log(`๐Ÿ” Fetching schema for ${owner}/${repo}@${ref}...`); try { const schemaRes = await axios.get(`http://localhost:3000/schemas/${owner}/${repo}/${ref}`, { headers: { Authorization: `Bearer ${greatlabsToken}` } }); const schema = schemaRes.data; const paths = schema.paths || {}; let passed = 0; let failed = 0; for (const [path, methods] of Object.entries(paths)) { for (const [method] of Object.entries(methods)) { const endpoint = `${url}${path}`; try { const headers = auth ? { Authorization: `Bearer ${auth}` } : {}; const res = await axios({ method, url: endpoint, headers, validateStatus: () => true, }); const status = res.status; if (status >= 200 && status < 300) { console.log(chalk.green(`โœ… ${method.toUpperCase()} ${endpoint} (${status})`)); passed++; } else { console.log(chalk.red(`โŒ ${method.toUpperCase()} ${endpoint} โ†’ ${status}`)); failed++; } } catch (err) { console.log(chalk.red(`โŒ ${method.toUpperCase()} ${endpoint} โ†’ ${err.message}`)); failed++; } } } console.log(chalk.bold(`\n๐Ÿงช Test Summary: ${passed} passed, ${failed} failed`)); if (failed > 0) process.exit(1); } catch (err) { console.error('โŒ Failed to fetch schema:', err.message); process.exit(1); } }