1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| class TestToolMatrix { constructor() { this.tools = { unitTesting: { vitest: { speed: '⚡ Extremely fast (uses Vite)', features: ['Instant test startup', 'HMR integration', 'TypeScript support'], ecosystem: 'Vite ecosystem', bestFor: ['Vite projects', 'Fast feedback', 'TypeScript projects'] }, jest: { maturity: 'Highly mature with rich ecosystem', features: ['Large plugin ecosystem', 'Snapshot testing', 'Mocking utilities'], ecosystem: 'Broad JavaScript ecosystem', bestFor: ['Legacy projects', 'Complex mocking', 'Enterprise applications'] }, mocha: { flexibility: 'Highly configurable', features: ['Flexible reporters', 'Various assertion libraries', 'Browser testing'], ecosystem: 'Traditional Node.js ecosystem', bestFor: ['Node.js applications', 'Custom testing needs', 'Browser automation'] } },
componentTesting: { 'react-testing-library': { philosophy: 'Test user behavior, not implementation', features: ['Queries by text/labels', 'Fire events', 'Wait for async'], bestFor: ['React applications', 'Behavior-driven tests', 'Accessibility testing'] }, '@testing-library/vue': { vueNative: true, features: ['Vue-specific queries', 'Reactivity handling', 'Slot testing'], bestFor: ['Vue applications', 'Composition API testing', 'Component interactions'] }, '@testing-library/user-event': { realisticInteraction: true, features: ['Sequence of events', 'Keyboard navigation', 'Focus management'], bestFor: ['Accessibility testing', 'Complex user flows', 'Realistic interactions'] } },
e2eTesting: { playwright: { crossBrowser: true, features: ['All browsers', 'Mobile testing', 'Network interception', 'Visual testing'], bestFor: ['Modern web apps', 'Cross-browser testing', 'Complex user flows'] }, cypress: { developerExperience: 'Excellent DX with dashboard', features: ['Time travel', 'Automatic waiting', 'Screenshot comparisons'], bestFor: ['Single browser focus', 'Developer productivity', 'CI/CD integration'] }, webdriverio: { flexibility: 'Multi-framework support', features: ['App and web testing', 'Cloud services', 'Component testing'], bestFor: ['Hybrid testing', 'Mobile apps', 'Enterprise testing'] } } }; }
getRecommendation(techStack, projectRequirements) { const recommendations = { unit: this.recommendUnitTesting(techStack, projectRequirements), integration: this.recommendIntegrationTesting(techStack, projectRequirements), e2e: this.recommendE2ETesting(techStack, projectRequirements) };
return recommendations; }
recommendUnitTesting(techStack, requirements) { if (techStack.includes('vite')) { return { tool: 'vitest', reason: 'Vite-native testing with instant startup', configuration: this.getVitestConfig() }; } else if (requirements.speed && requirements.modern) { return { tool: 'vitest', reason: 'Fastest test execution', configuration: this.getVitestConfig() }; } else { return { tool: 'jest', reason: 'Mature ecosystem with extensive features', configuration: this.getJestConfig() }; } }
getVitestConfig() { return { test: { environment: 'jsdom', setupFiles: ['./test/setup.js'], globals: true, coverage: { provider: 'v8', reporter: ['text', 'json', 'html'], exclude: ['node_modules/', 'test/', 'dist/'] } } }; }
getJestConfig() { return { testEnvironment: 'jsdom', setupFilesAfterEnv: ['<rootDir>/test/setup.js'], collectCoverageFrom: [ 'src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts', '!src/index.js' ], coverageThreshold: { global: { branches: 80, functions: 80, lines: 80, statements: 80 } } }; } }
|