Test Component
The test component provides standardized testing configuration for your GitLab CI / CD pipelines.
Usageโ
Include the test component in your .gitlab - ci.yml
:
include:
- component: [COMPONENT_REGISTRY] / [email protected]
inputs:
test_command: 'npm test'
coverage_path: 'coverage'
```text
## Configuration
### Required Inputs
| Input | Description | Default |
| -------------- | -------------------- | ------- |
| `test_command`| Command to run tests | None |
### Optional Inputs
| Input | Description | Default |
| ------------------ | ------------------------------------- | --------------------------- |
|`coverage_path`| Directory containing coverage reports |`coverage`|
|`test_pattern`| Pattern for test files |`**/ * .test.{js, jsx, ts, tsx}`|
|`node_version`| Node.js version to use |`18`|
|`jest_config`| Path to Jest config file |`jest.config.js`|
|`test_timeout`| Test timeout in seconds |`300`|
|`pre_test_script`| Script to run before tests | None |
|`post_test_script`| Script to run after tests | None |
## Examples
### Basic Usage
```yaml
test:
extends: .test
variables:
TEST_COMMAND: 'npm test'
```text
### With Coverage
```yaml
test:
extends: .test
variables:
TEST_COMMAND: 'npm run test:coverage'
COVERAGE_PATH: 'coverage'
```text
### Multiple Test Suites
```yaml
unit - tests:
extends: .test
variables:
TEST_COMMAND: 'npm run test:unit'
TEST_PATTERN: '**/ * .unit.test.ts'
integration - tests:
extends: .test
variables:
TEST_COMMAND: 'npm run test:integration'
TEST_PATTERN: '**/ * .integration.test.ts'
```text
## Coverage Reports
The test component automatically handles coverage reports:
```yaml
coverage:
paths:
- [COVERAGE_PATH]
reports:
coverage_report:
coverage_format: cobertura
path: [COVERAGE_PATH] / cobertura - coverage.xml
```text
## Test Results
Test results are published automatically:
```yaml
artifacts:
reports:
junit: junit.xml
```text
## Environment Variables
### Available Variables
| Variable | Description |
| ---------------------- | -------------------------------- |
| `CI_JOB_TOKEN`| GitLab CI token |
|`NODE_ENV`| Node environment (set to 'test') |
|`JEST_JUNIT_OUTPUT`| JUnit report output path |
|`COVERAGE_REPORT_PATH`| Coverage report path |
### Custom Variables
You can set custom environment variables:
```yaml
variables:
MY_TEST_VAR: 'value'
```text
## Best Practices
1. Test Organization
- Group related tests
- Use descriptive names
- Follow test patterns
2. Coverage Goals
- Set coverage thresholds
- Track coverage trends
- Document exclusions
3. Performance
- Optimize test suites
- Use test parallelization
- Cache test results
## Troubleshooting
### Common Issues
1. Test Failures
- Check test logs
- Verify dependencies
- Review error messages
2. Coverage Issues
- Check report paths
- Verify thresholds
- Update exclusions
3. Performance Problems
- Review test times
- Check resource usage
- Optimize slow tests
## Support
Need help? Check our [Support Guide](.. / guide / support.md) or [create an issue](https://gitlab.bluefly.io / bluefly / internal - projects / llm / bfcicomponents/ - /issues).