Skip to content

🌿 Fern Scribe: Expand integration test documentation so it's easi... #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions fern/products/sdks/overview/typescript/testing.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
title: "Integration Tests"
description: "Test your SDK with auto-generated integration tests"
---

# Integration Tests

Fern can automatically generate integration tests for your TypeScript SDK to verify that your client behaves correctly against a mock server. This feature helps ensure your SDK works as expected and maintains compatibility with your API specification.

## Supported Generators

Integration test generation is currently supported in:
- TypeScript SDK Generator (v1.2.4+)
- C# SDK Generator

<Callout type="info">
We recommend using TypeScript SDK Generator v1.5.0 or later for the best experience with integration tests.
</Callout>

## Getting Started

### Prerequisites

- Fern CLI (latest version)
- Node.js 16+
- npm or yarn
- TypeScript SDK Generator v1.2.4 or later

### Updating Your Generator Version

To use integration tests, ensure you're using a supported generator version:

```yaml
generators:
- name: fernapi/fern-typescript-sdk
version: 1.5.0
output:
location: local-file-system
path: ../generated/typescript
```

<Callout type="warning">
If you're seeing version 1.0.0 or 1.0.1 selected automatically, update your Fern CLI to the latest version to access newer generator versions.
</Callout>

## Test Structure

When you generate your SDK, Fern automatically creates:
1. A test directory with the basic test infrastructure
2. Integration tests based on your API specification
3. Stubs for custom tests

The generated tests use a mock server to validate:
- Request/response handling
- Parameter serialization
- Error scenarios
- Authentication flows
- API endpoint behavior

## Running Tests

To run the integration tests:

```bash
npm test
```

Or with yarn:

```bash
yarn test
```

## Custom Tests

While the auto-generated tests cover most common scenarios, you can add custom tests for specific use cases:

```typescript
describe('Custom API Tests', () => {
it('should handle specific business logic', async () => {
const client = new YourApiClient();
const response = await client.someEndpoint();
expect(response).toBeDefined();
});
});
```

## Best Practices

1. Keep your generator version up to date for the latest testing features
2. Run tests before publishing SDK updates
3. Add custom tests for complex business logic
4. Use the mock server for consistent test behavior

<Callout type="info">
Integration test support for additional SDK generators is under development. Check the Fern documentation for updates.
</Callout>
105 changes: 105 additions & 0 deletions fern/products/sdks/pages/testing/integration-tests.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: 'Integration Tests'
description: 'Testing your SDK against a mock server'
---

# Integration Tests

Fern can automatically generate integration tests for your SDK to verify its functionality against a mock server. This feature ensures your SDK correctly implements your API specification.

## Supported Languages

Integration test generation is currently supported for:
- TypeScript (v1.2.4 and later, recommended v1.5.0+)
- C#

Support for additional languages is in development.

## Prerequisites

- Fern CLI (latest version)
- Node.js 16+
- npm or yarn
- TypeScript SDK generator v1.5.0+ for best results

## Setting Up Integration Tests

### 1. Update Your Generator Version

In your `fern.config.json`, specify the generator version:

```json
{
"generators": {
"typescript": {
"version": "1.5.0"
}
}
}
```

### 2. Generate the SDK

Run the Fern CLI to generate your SDK with integration tests:

```bash
fern generate
```

### 3. Running Tests

The generated tests will be in your SDK's test directory. Run them using your language's standard test runner:

For TypeScript:
```bash
npm test
```

## What Gets Tested

The generated integration tests verify:
- Request/response handling
- Parameter serialization
- Error handling
- Authentication flows
- Content type handling

<Note>
The mock server automatically implements your API specification, allowing for comprehensive testing without hitting your actual API endpoints.
</Note>

## Custom Tests

While automatic tests cover most common scenarios, you can add custom tests to verify specific business logic or edge cases:

```typescript
describe('Custom API Tests', () => {
it('should handle specific business case', async () => {
const client = new ApiClient();
const response = await client.customEndpoint();
expect(response).toBeDefined();
});
});
```

## Best Practices

- Keep your Fern CLI and generators up to date
- Run integration tests as part of your CI/CD pipeline
- Combine generated tests with custom tests for comprehensive coverage
- Review generated tests to understand expected API behavior

<Warning>
Always use a stable generator version in production. Test new generator versions in a development environment first.
</Warning>

## Troubleshooting

If you encounter issues:

1. Verify you're using a supported generator version
2. Ensure your API specification is valid
3. Check that all required dependencies are installed
4. Review the generator output for any error messages

For additional help, reach out to the Fern team via the support channels.
24 changes: 6 additions & 18 deletions fern/products/sdks/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ navigation:
slug: capabilities
- link: Customer Showcase
href: https://buildwithfern.com/showcase
- page: Testing
path: ./overview/typescript/testing.mdx
- section: Generators
contents:
- section: TypeScript
Expand All @@ -41,8 +43,6 @@ navigation:
slug: custom-code
- changelog: ./overview/typescript/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: Python
contents:
- page: Quickstart
Expand All @@ -59,12 +59,10 @@ navigation:
path: ./overview/python/publishing-to-pypi.mdx
slug: publishing
- page: Adding custom code
path: ./overview/python/custom-code.mdx
path: ./overview/python/custom-code.mdx
slug: custom-code
- changelog: ./overview/python/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: Go
contents:
- page: Quickstart
Expand All @@ -81,12 +79,10 @@ navigation:
path: ./overview/go/publishing-to-go-package-manager.mdx
slug: publishing
- page: Adding custom code
path: ./overview/go/custom-code.mdx
path: ./overview/go/custom-code.mdx
slug: custom-code
- changelog: ./overview/go/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: Java
contents:
- page: Quickstart
Expand All @@ -107,8 +103,6 @@ navigation:
slug: custom-code
- changelog: ./overview/java/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: .NET
slug: csharp
contents:
Expand All @@ -131,8 +125,6 @@ navigation:
slug: custom-code
- changelog: ./overview/csharp/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: PHP
contents:
- page: Quickstart
Expand All @@ -154,8 +146,6 @@ navigation:
slug: custom-code
- changelog: ./overview/php/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- section: Ruby
contents:
- page: Quickstart
Expand All @@ -177,13 +167,11 @@ navigation:
slug: custom-code
- changelog: ./overview/ruby/changelog
slug: changelog
# - link: Customer Showcase
# href: https://buildwithfern.com/showcase
- page: MCP Server
path: ./overview/mcp-server/introduction.mdx
slug: mcp-server
- section: Deep Dives
contents:
contents:
- page: Customize Method Names
path: ./guides/customize-method-names.mdx
slug: customize-method-names
Expand All @@ -207,7 +195,7 @@ navigation:
path: ./guides/self-host-fern-generators.mdx
slug: self-host-generators
- section: Reference
contents:
contents:
- page: generators.yml
path: ./reference/generators-yml-reference.mdx
slug: generators-yml