This document explains how to run the test suite for the LPS Crawler project.
The project includes several types of tests:
tests/browser.test.js- BrowserInterface and RateLimiter teststests/crawler.test.js- LPSCrawler, MFTExtractor, TBRExtractor, and DataSynthesizer teststests/mathUtils.test.js- Mathematical utilities tests (68 test cases)
tests/mock-integration.test.js- Mock-based integration tests for all components (21 tests)tests/comprehensive-integration.test.js- Full browser-based integration tests (requires Chrome)tests/integration.test.js- Legacy integration tests (skipped by default)
test-implementation.js- Validates desktop app structure and file existencecomprehensive-test-suite.js- Comprehensive production-grade test suite
npm installnpm run test:unitThis runs all tests except browser-based integration tests. Currently includes:
- Browser interface tests
- Crawler tests
- Math utilities tests (68 test cases)
- Mock integration tests (21 test cases)
Total: 39 passing tests
npm run test:integrationNote: This requires Chrome to be installed via Puppeteer:
npx puppeteer browsers install chromenpm run test:allRuns all tests including integration tests. Requires Chrome to be installed.
npm test
# or
node test-implementation.jsThis validates the desktop app structure and implementation.
# Run a specific test file
npx jest tests/mock-integration.test.js
# Run tests matching a pattern
npx jest --testNamePattern="LPSCrawler"
# Run with verbose output
npx jest --verboseThe project uses Jest as the test runner. Configuration is in jest.config.js:
- Test Environment: Node.js
- Test Timeout: 60 seconds
- Test Pattern:
**/tests/**/*.test.js
Use Jest's standard test format:
describe('Component Name', () => {
test('should do something', () => {
expect(result).toBe(expected);
});
});Create mock browser interfaces for testing without a real browser:
const createMockBrowser = () => ({
browser: { close: jest.fn() },
page: {
url: () => 'https://example.com/',
evaluate: jest.fn().mockResolvedValue([]),
// ... other methods
},
initialize: jest.fn().mockResolvedValue(),
close: jest.fn().mockResolvedValue()
});
const crawler = new LPSCrawler(createMockBrowser());For tests that require a real browser, use the factory functions:
const { createCrawler } = require('../src');
test('should crawl a page', async () => {
const crawler = await createCrawler({
browser: { headless: true },
crawler: { maxPhases: 2 }
});
const result = await crawler.run('http://localhost:9876');
expect(result.totalDiscoveries).toBeGreaterThan(0);
await crawler.cleanup();
}, 30000);The tests are designed to run in CI environments:
# Example GitHub Actions workflow
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm run test:unit
- name: Install Chrome
run: npx puppeteer browsers install chrome
- name: Run integration tests
run: npm run test:integrationnpx jest --watchnode --inspect-brk node_modules/.bin/jest tests/mock-integration.test.js --runInBandThen open Chrome DevTools at chrome://inspect
LOG_LEVEL=debug npx jest tests/mock-integration.test.jsTo generate test coverage reports:
npx jest --coverageCoverage reports will be generated in the coverage/ directory.
-
Chrome Dependency: Full integration tests require Chrome to be installed
- Solution: Use mock-based tests for CI, or install Chrome via Puppeteer
-
Network Tests: Some tests may require network access
- Solution: Use the included test HTTP server for local testing
-
Timeout Issues: Some browser tests may timeout on slow systems
- Solution: Increase timeout in test configuration or individual tests
As of the latest run:
Test Suites: 4 passed, 4 total
Tests: 39 passed, 39 total
Snapshots: 0 total
Time: ~3s
- Browser interface tests: 4 passing
- Crawler tests: 13 passing
- Math utilities tests: 1 passing (68 internal assertions)
- Mock integration tests: 21 passing