TypeScript fixes: - Add @types/node dependency - Remove invalid CLI options (baseDelay, randomDelayMax) - Exclude vitest.config.ts from TypeScript compilation Unit tests (95 tests, 100% coverage): - codegen/timing.test.ts - timing helper generation - codegen/mouse.test.ts - mouse movement simulation - codegen/persistence.test.ts - localStorage persistence - codegen/controls.test.ts - stop/pause controls - platforms/seeking-auto-favorite.test.ts - main generator E2E tests (44 tests): - e2e/cli.test.ts - CLI execution and output validation - e2e/extension-manifest.test.ts - Firefox extension validation Docker support: - Dockerfile - multi-stage build with node:20-alpine - docker-compose.yml - local development config - .dockerignore - exclude dev files Also reorganized extension back to match manifest.json paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
165 lines
5.2 KiB
TypeScript
165 lines
5.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { generateMouseHelpers, MouseConfig } from './mouse.js';
|
|
|
|
describe('generateMouseHelpers', () => {
|
|
const defaultConfig: MouseConfig = {
|
|
mouseMoveSteps: 15,
|
|
mouseMoveDelay: 20,
|
|
};
|
|
|
|
it('should generate valid JavaScript code', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toBeTruthy();
|
|
expect(typeof code).toBe('string');
|
|
expect(code.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should inject mouseMoveSteps config value', () => {
|
|
const config: MouseConfig = {
|
|
mouseMoveSteps: 42,
|
|
mouseMoveDelay: 20,
|
|
};
|
|
const code = generateMouseHelpers(config);
|
|
|
|
expect(code).toContain('42');
|
|
expect(code).toContain('const steps = 42');
|
|
});
|
|
|
|
it('should inject mouseMoveDelay config value', () => {
|
|
const config: MouseConfig = {
|
|
mouseMoveSteps: 15,
|
|
mouseMoveDelay: 99,
|
|
};
|
|
const code = generateMouseHelpers(config);
|
|
|
|
expect(code).toContain('99');
|
|
expect(code).toContain('randomize(99)');
|
|
});
|
|
|
|
it('should contain currentMousePos state variable', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('let currentMousePos');
|
|
expect(code).toContain('window.innerWidth / 2');
|
|
expect(code).toContain('window.innerHeight / 2');
|
|
});
|
|
|
|
it('should contain easing function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('function easeOutCubic(t)');
|
|
expect(code).toContain('1 - Math.pow(1 - t, 3)');
|
|
});
|
|
|
|
it('should contain jitter function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('function addJitter(value, maxJitter)');
|
|
expect(code).toContain('Math.random() - 0.5');
|
|
});
|
|
|
|
it('should contain dispatchMouseMove function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('function dispatchMouseMove(x, y)');
|
|
expect(code).toContain('new MouseEvent');
|
|
expect(code).toContain("'mousemove'");
|
|
expect(code).toContain('clientX: x');
|
|
expect(code).toContain('clientY: y');
|
|
});
|
|
|
|
it('should contain moveMouseTo async function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('async function moveMouseTo(targetX, targetY, targetEl = null)');
|
|
expect(code).toContain('const startX = currentMousePos.x');
|
|
expect(code).toContain('const startY = currentMousePos.y');
|
|
});
|
|
|
|
it('should implement overshoot in mouse movement', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('const overshootX = targetX');
|
|
expect(code).toContain('const overshootY = targetY');
|
|
expect(code).toContain('Math.random() - 0.5');
|
|
});
|
|
|
|
it('should use easing in movement', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('const easedProgress = easeOutCubic(progress)');
|
|
});
|
|
|
|
it('should add curve offset for natural movement', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('const curveOffset = Math.sin(progress * Math.PI)');
|
|
});
|
|
|
|
it('should contain simulateClick function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('async function simulateClick(el)');
|
|
expect(code).toContain('getBoundingClientRect()');
|
|
expect(code).toContain('await moveMouseTo');
|
|
});
|
|
|
|
it('should implement full click sequence', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain("'mouseenter'");
|
|
expect(code).toContain("'mouseover'");
|
|
expect(code).toContain("'mousedown'");
|
|
expect(code).toContain("'mouseup'");
|
|
expect(code).toContain("'click'");
|
|
});
|
|
|
|
it('should include native click as backup', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('el.click()');
|
|
});
|
|
|
|
it('should contain idleScroll function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('async function idleScroll()');
|
|
expect(code).toContain('window.scrollBy');
|
|
expect(code).toContain('behavior:');
|
|
});
|
|
|
|
it('should contain idleMouseWiggle function', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('async function idleMouseWiggle()');
|
|
expect(code).toContain('const wiggleX');
|
|
expect(code).toContain('const wiggleY');
|
|
});
|
|
|
|
it('should use probability for idle behaviors', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('Math.random() < 0.3'); // idleScroll 30%
|
|
expect(code).toContain('Math.random() < 0.4'); // idleMouseWiggle 40%
|
|
});
|
|
|
|
it('should include MOUSE MOVEMENT header comment', () => {
|
|
const code = generateMouseHelpers(defaultConfig);
|
|
|
|
expect(code).toContain('MOUSE MOVEMENT');
|
|
});
|
|
|
|
it('should handle different config values', () => {
|
|
const config1 = { mouseMoveSteps: 5, mouseMoveDelay: 10 };
|
|
const config2 = { mouseMoveSteps: 100, mouseMoveDelay: 50 };
|
|
|
|
const code1 = generateMouseHelpers(config1);
|
|
const code2 = generateMouseHelpers(config2);
|
|
|
|
expect(code1).toContain('5');
|
|
expect(code1).toContain('10');
|
|
expect(code2).toContain('100');
|
|
expect(code2).toContain('50');
|
|
});
|
|
});
|