This document describes how to run tests and use code quality tools for the IPTV Proxy project.
npm testThis will run all unit and integration tests using Mocha.
npm run test:watchThis will automatically re-run tests when files change.
npm run test:coverageNote: Coverage reporting with c8 is configured but requires additional setup.
Tests are organized in the test/ directory:
test/
├── unit/ # Unit tests for individual functions
│ └── parseM3U.test.js
├── integration/ # Integration tests with mocked dependencies
│ ├── epg.test.js
│ └── parseM3U.test.js
├── fixtures/ # Test data files
│ ├── valid-playlist.m3u
│ ├── malformed-playlist.m3u
│ └── valid-epg.xml
├── validators.test.js # Output format validation tests
└── helpers.js # Test utilities and helper functions
Check code for lint issues:
npm run lintAuto-fix lint issues where possible:
npm run lint:fix- Configuration:
eslint.config.js(Flat Config) - Supports JavaScript/ESM and Vue.js files
- Rules are set to 'warn' for style issues to not block CI
Check if code is formatted correctly:
npm run format:checkAuto-format all code:
npm run format- Configuration:
.prettierrc.json - Settings:
- Single quotes
- 2-space indentation
- 100 character line width
- Semicolons required
- ES5 trailing commas
Unit tests focus on testing individual functions in isolation:
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { applyMapping } from '../../scripts/parseM3U.js';
describe('M3U Parser - applyMapping', () => {
it('should apply mapping by channel name', () => {
const channel = { name: 'Test Channel', tvg_id: 'test.1' };
const mapping = { 'Test Channel': { name: 'Mapped Channel' } };
const result = applyMapping(channel, mapping);
expect(result.name).to.equal('Mapped Channel');
});
});Integration tests test multiple components working together, often with mocked HTTP requests:
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import nock from 'nock';
describe('M3U Parser Integration', () => {
beforeEach(() => {
nock.cleanAll();
});
afterEach(() => {
nock.cleanAll();
});
it('should mock M3U playlist fetch successfully', async () => {
nock('http://test.example.com').get('/playlist.m3u').reply(200, '#EXTM3U\n...');
// Test code here
});
});Use the helper functions in test/helpers.js:
import { generateM3UPlaylist, generateXMLTV, createMockChannel } from './helpers.js';
// Generate test M3U data
const m3u = generateM3UPlaylist([
{
name: 'Channel 1',
tvg_id: 'ch1',
url: 'http://example.com/stream1',
},
]);
// Generate test XMLTV data
const xml = generateXMLTV(
[{ id: 'ch1', name: 'Channel 1' }],
[{ channel: 'ch1', start: '...', stop: '...', title: 'Show' }]
);The project includes validators for M3U and XMLTV formats:
import { validateM3UFormat, validateXMLTVFormat } from './test/validators.test.js';
const m3uResult = validateM3UFormat(m3uContent);
console.log('Valid:', m3uResult.isValid);
console.log('Errors:', m3uResult.errors);
console.log('Warnings:', m3uResult.warnings);
const xmlResult = validateXMLTVFormat(xmlContent);
console.log('Valid:', xmlResult.isValid);
console.log('Channels:', xmlResult.channelCount);
console.log('Programmes:', xmlResult.programmeCount);These validators are also run in CI to ensure output format compliance.
Tests and code quality checks run automatically in GitHub Actions:
- Lint and Security Checks: Runs ESLint and Prettier checks
- Tests: Runs all unit and integration tests
- Format Validation: Validates M3U and XMLTV output formats
See .github/workflows/ci.yml for the complete CI configuration.
- Write tests for new features: Add unit tests for new functions and integration tests for new workflows
- Mock external dependencies: Use
nockto mock HTTP requests in tests - Use descriptive test names: Test names should clearly describe what is being tested
- Keep tests focused: Each test should verify one specific behavior
- Use fixtures for complex data: Store test data files in
test/fixtures/ - Clean up after tests: Use
beforeEachandafterEachhooks to set up and tear down test state
While not currently enforced, aim for:
- Unit tests: 80%+ coverage of core logic
- Integration tests: Cover all major workflows
- Format validation: 100% of output formats validated
- Check that dependencies are installed:
npm ci - Clear any cached data:
rm -rf data/ - Check test output for specific errors
- Run
npm run lint:fixto auto-fix common issues - Consult
eslint.config.jsfor rule configuration
- Run
npm run formatto auto-format code - Check
.prettierrc.jsonfor style configuration