ferrucc-io/dotcodegen

View on GitHub
docs/configuration.md

Summary

Maintainability
Test Coverage
# Configuration

## Introduction

To make sure the tests generated by `dotcodegen` fit your team's needs, you can customize the instructions used to generate the tests. This section will guide you through the process of customizing the instructions.

The instructions are markdown files in plain English. They are used to generate the tests for your codebase. You can customize the instructions to fit your team's needs.

## Writing your first instruction

To write your first instruction make sure you have `codegen` installed. If you don't have it installed, follow the [installation](../README.md#installation) instructions.

Create a new file in the `.codegen/instructions` directory called `react.md`. This file will contain the instructions used to generate the tests.

```bash
mkdir -p .codegen/instructions
touch .codegen/instructions/react.md
```

Then for the content of the file, you'll want to specify:

- The regex to match the files you want to generate the test for. (e.g. `.*\.tsx` or `api/.*\.rb`)
- The suffix of the test file. (e.g. `.test.tsx` or `_spec.rb`)
- The instructions to generate the tests.

Here's an example of a `react.md` file:

```markdown
---
regex: '.*\.tsx'
test_file_suffix: '.test.tsx'
---

When writing a test, you should follow these steps:

1. Avoid typos.
2. Avoid things that could be infinite loops.
3. This codebase is a React codebase, try to follow the conventions of the React community.

Here's an example of a good test you should reply with:

<!-- Copy paste one of your existing tests here -->

```

## Customizing the file paths

In some programming languages, tests live in specific directories. For example, in Ruby, tests live in a `spec` directory. You can specify the directory where the tests should be generated by adding a `test_file_directory` key to the instruction file.

Here's an example of a `rails-controller.md` file, that specifies `spec/controllers` the directory where the tests should be generated and removes the `app/controllers` prefix from the starting file path:

```markdown
---
regex: 'app/controllers/.*\.rb'
root_path: 'app/controllers'
test_root_path: 'spec/controllers'
test_file_suffix: '_spec.rb'
---

Follow these steps when writing a test for a Rails controller:

1. Avoid typos.
2. Avoid things that could be infinite loops.
3. This codebase is a Rails codebase, try to follow the conventions of the Rails community.
```


## Instructions reference

The instructions need to be .md files in the `.codegen/instructions` directory. For each instruction file, you can specify the following keys:

- `regex`: The regex to match the files you want to generate the test for. (e.g. `.*\.tsx` or `api/.*\.rb`)
- `test_root_path`: The root path that codegen will pre-pend to all test files. (e.g. `spec/controllers` or `api`)
- `root_path`: The root path of your which you want to remove when adding the test files `test_root_path`. (e.g. `app/controllers` or `api`)
- `test_file_suffix`: The suffix of the test file. (e.g. `.test.tsx` or `_spec.rb`) We will automatically add this suffix to the file name and remove the .extension from your original file name.

## The .codegen directory

The `.codegen` directory is where you can customize the instructions used to generate the tests. The directory should be placed at the root of your project.