技能 编程开发 Grammarly本地开发流程配置

Grammarly本地开发流程配置

v20260423
grammarly-local-dev-loop
本指南旨在配置Grammarly API的本地开发环境,提供完整的项目结构搭建和开发流程。它指导用户使用mocked responses和vitest进行全面的单元及集成测试。适用于需要快速迭代、构建稳定开发环境或进行API功能测试的开发场景。
获取技能
182 次下载
概览

Grammarly Local Dev Loop

Overview

Set up a development workflow for Grammarly API integrations with mocked responses and vitest.

Instructions

Step 1: Project Structure

grammarly-integration/
├── src/grammarly/
│   ├── client.ts       # API client with token management
│   ├── scoring.ts      # Writing Score API
│   ├── detection.ts    # AI + Plagiarism detection
│   └── types.ts        # TypeScript interfaces
├── tests/
│   ├── fixtures/       # Mock API responses
│   └── scoring.test.ts
├── .env.local
└── package.json

Step 2: Mocked Tests

import { describe, it, expect, vi } from 'vitest';

const mockFetch = vi.fn();
vi.stubGlobal('fetch', mockFetch);

describe('Writing Score', () => {
  it('should return scores for valid text', async () => {
    mockFetch.mockResolvedValueOnce({
      ok: true,
      json: async () => ({ overallScore: 85, engagement: 80, correctness: 90, clarity: 85, tone: 82 }),
    });
    // Test scoring logic
  });

  it('should reject text under 30 words', async () => {
    mockFetch.mockResolvedValueOnce({ ok: false, status: 400, text: async () => 'Text too short' });
    // Test error handling
  });
});

Resources

Next Steps

See grammarly-sdk-patterns for production patterns.

信息
Category 编程开发
Name grammarly-local-dev-loop
版本 v20260423
大小 1.97KB
更新时间 2026-04-26
语言