Skip to content
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

docs: add the development guide on how to run test #1250

Merged
merged 9 commits into from
Oct 2, 2024
77 changes: 77 additions & 0 deletions Development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Development Guide
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

This guide will help you set up the `generator` locally, run tests, and use Docker for isolated testing.

## Getting Started
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

1. Clone the repository:

```bash
git clone https://github.com/asyncapi/generator.git
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved
cd generator
derberg marked this conversation as resolved.
Show resolved Hide resolved
```

2. Install dependencies:

```bash
npm install
```

## Running Tests
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

### Local Testing
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

To run all tests locally:

- Unit tests: `npm run generator:test:unit`
- Integration tests: `npm run generator:test:integration`
- CLI tests: `npm run generator:test:cli`

### Adding Tests
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

1. Create new test files in the appropriate directory under `test/`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is no longer in root


2. Follow the existing test patterns.

3. Run your new tests using the commands mentioned above.

## Docker Isolated Testing
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

To run tests in an isolated Docker environment:

1. Ensure Docker is installed and running on your machine.

2. Run the following command from the project root:

```bash
docker run --rm -v ${PWD}:/app -w /app node:18 sh -c "
cp -r /app /tmp/app &&
cd /tmp/app &&
npm install &&
npm test
"
```

This command does the following:
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved
- Mounts the current directory to `/app` in the container
- Copies the project to a temporary directory
- Installs dependencies
- Runs all tests

Note: This approach ensures a clean environment for each test run by removing any existing `node_modules`.

## Additional Commands
Gmin2 marked this conversation as resolved.
Show resolved Hide resolved

- Lint the code: `npm run lint`
- Generate documentation: `npm run docs`
- Build Docker image: `npm run docker:build`

## Troubleshooting

If you encounter any issues during development or testing, please check the following:

1. Ensure you're using the correct Node.js version (18.12.0 or higher) and npm version (8.19.0 or higher).
2. Clear the `node_modules` directory and reinstall dependencies if you encounter unexpected behavior.
3. For Docker-related issues, make sure Docker is running and you have sufficient permissions.

If problems persist, please open an issue on the GitHub repository.
Loading