|
| 1 | +const path = require('path') |
| 2 | +const fs = require('fs') |
| 3 | +const { exec } = require('child_process') |
| 4 | +const { expect } = require('expect') |
| 5 | + |
| 6 | +const runner = path.join(__dirname, '../../bin/codecept.js') |
| 7 | +const codecept_dir = path.join(__dirname, '../data/sandbox') |
| 8 | + |
| 9 | +describe('stepByStepReport regression tests', function () { |
| 10 | + this.timeout(120000) // Increased timeout for acceptance tests |
| 11 | + |
| 12 | + const outputDir = path.join(codecept_dir, 'output') |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + // Clean up output directory before each test |
| 16 | + if (fs.existsSync(outputDir)) { |
| 17 | + fs.rmSync(outputDir, { recursive: true, force: true }) |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + afterEach(() => { |
| 22 | + // Clean up output directory after each test |
| 23 | + if (fs.existsSync(outputDir)) { |
| 24 | + fs.rmSync(outputDir, { recursive: true, force: true }) |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + function createConfig(name, extraConfig = {}) { |
| 29 | + const config = ` |
| 30 | +// Override the standard acting helpers to include FakeDriver for testing |
| 31 | +const Container = require('../../lib/container') |
| 32 | +const originalHelpers = Container.STANDARD_ACTING_HELPERS |
| 33 | +Object.defineProperty(Container, 'STANDARD_ACTING_HELPERS', { |
| 34 | + get: () => [...originalHelpers, 'FakeDriver'] |
| 35 | +}) |
| 36 | +
|
| 37 | +exports.config = { |
| 38 | + tests: './stepbystep_test.js', |
| 39 | + timeout: 30000, |
| 40 | + output: './output', |
| 41 | + helpers: { |
| 42 | + FakeDriver: { |
| 43 | + require: '../fake_driver', |
| 44 | + browser: 'dummy', |
| 45 | + windowSize: '1024x768' |
| 46 | + }, |
| 47 | + }, |
| 48 | + plugins: { |
| 49 | + stepByStepReport: { |
| 50 | + enabled: true, |
| 51 | + deleteSuccessful: false, |
| 52 | + ...${JSON.stringify(extraConfig)} |
| 53 | + }, |
| 54 | + }, |
| 55 | + include: {}, |
| 56 | + bootstrap: false, |
| 57 | + mocha: {}, |
| 58 | + name: '${name}', |
| 59 | +} |
| 60 | +` |
| 61 | + const configPath = path.join(codecept_dir, `codecept.${name}.js`) |
| 62 | + fs.writeFileSync(configPath, config) |
| 63 | + return configPath |
| 64 | + } |
| 65 | + |
| 66 | + function runCommand(command) { |
| 67 | + return new Promise((resolve, reject) => { |
| 68 | + exec(command, { cwd: codecept_dir }, (err, stdout, stderr) => { |
| 69 | + resolve({ err, stdout, stderr }) |
| 70 | + }) |
| 71 | + }) |
| 72 | + } |
| 73 | + |
| 74 | + it('should handle run-workers without consolidating screenshots', async function () { |
| 75 | + const configPath = createConfig('workers-test') |
| 76 | + |
| 77 | + const command = `${runner} run-workers 2 --config ${configPath} --grep "@stepbystep"` |
| 78 | + const result = await runCommand(command) |
| 79 | + |
| 80 | + console.log('STDOUT:', result.stdout) |
| 81 | + console.log('STDERR:', result.stderr) |
| 82 | + |
| 83 | + // Key regression test: ensure no stepByStepReport consolidation directory |
| 84 | + const consolidatedDir = path.join(outputDir, 'stepByStepReport') |
| 85 | + expect(fs.existsSync(consolidatedDir)).toBe(false) |
| 86 | + |
| 87 | + console.log('✓ No stepByStepReport consolidation directory created for run-workers') |
| 88 | + |
| 89 | + // Verify basic functionality without requiring screenshots |
| 90 | + expect(result.stdout).toContain('CodeceptJS') |
| 91 | + |
| 92 | + // Clean up |
| 93 | + fs.unlinkSync(configPath) |
| 94 | + }) |
| 95 | + |
| 96 | + it('should handle run-multiple without consolidating screenshots', async function () { |
| 97 | + const multipleConfig = ` |
| 98 | +// Override the standard acting helpers to include FakeDriver for testing |
| 99 | +const Container = require('../../lib/container') |
| 100 | +const originalHelpers = Container.STANDARD_ACTING_HELPERS |
| 101 | +Object.defineProperty(Container, 'STANDARD_ACTING_HELPERS', { |
| 102 | + get: () => [...originalHelpers, 'FakeDriver'] |
| 103 | +}) |
| 104 | +
|
| 105 | +exports.config = { |
| 106 | + tests: './stepbystep_test.js', |
| 107 | + timeout: 30000, |
| 108 | + output: './output', |
| 109 | + helpers: { |
| 110 | + FakeDriver: { |
| 111 | + require: '../fake_driver', |
| 112 | + browser: 'dummy', |
| 113 | + windowSize: '1024x768' |
| 114 | + }, |
| 115 | + }, |
| 116 | + plugins: { |
| 117 | + stepByStepReport: { |
| 118 | + enabled: true, |
| 119 | + deleteSuccessful: false, |
| 120 | + }, |
| 121 | + }, |
| 122 | + include: {}, |
| 123 | + bootstrap: false, |
| 124 | + mocha: {}, |
| 125 | + name: 'multiple-test', |
| 126 | + multiple: { |
| 127 | + basic: { |
| 128 | + browsers: ['chrome'] |
| 129 | + } |
| 130 | + } |
| 131 | +} |
| 132 | +` |
| 133 | + |
| 134 | + const configPath = path.join(codecept_dir, 'codecept.multiple.js') |
| 135 | + fs.writeFileSync(configPath, multipleConfig) |
| 136 | + |
| 137 | + const command = `${runner} run-multiple basic --config ${configPath} --grep "@stepbystep"` |
| 138 | + const result = await runCommand(command) |
| 139 | + |
| 140 | + console.log('STDOUT:', result.stdout) |
| 141 | + console.log('STDERR:', result.stderr) |
| 142 | + |
| 143 | + // Key regression test: ensure no stepByStepReport consolidation directory |
| 144 | + const consolidatedDir = path.join(outputDir, 'stepByStepReport') |
| 145 | + expect(fs.existsSync(consolidatedDir)).toBe(false) |
| 146 | + |
| 147 | + console.log('✓ No stepByStepReport consolidation directory created for run-multiple') |
| 148 | + |
| 149 | + // Verify that the command runs successfully with run-multiple |
| 150 | + expect(result.stdout).toContain('CodeceptJS') |
| 151 | + |
| 152 | + // Clean up |
| 153 | + fs.unlinkSync(configPath) |
| 154 | + }) |
| 155 | + |
| 156 | + it('should handle regular run command with backward compatibility', async function () { |
| 157 | + const configPath = createConfig('regular') |
| 158 | + |
| 159 | + const command = `${runner} run --config ${configPath} --grep "@stepbystep"` |
| 160 | + const result = await runCommand(command) |
| 161 | + |
| 162 | + console.log('STDOUT:', result.stdout) |
| 163 | + console.log('STDERR:', result.stderr) |
| 164 | + |
| 165 | + // Key regression test: ensure no stepByStepReport consolidation directory |
| 166 | + const consolidatedDir = path.join(outputDir, 'stepByStepReport') |
| 167 | + expect(fs.existsSync(consolidatedDir)).toBe(false) |
| 168 | + |
| 169 | + console.log('✓ No stepByStepReport consolidation directory created for regular run') |
| 170 | + |
| 171 | + // Verify backward compatibility - regular run should work |
| 172 | + expect(result.stdout).toContain('CodeceptJS') |
| 173 | + |
| 174 | + // Clean up |
| 175 | + fs.unlinkSync(configPath) |
| 176 | + }) |
| 177 | + |
| 178 | + it('should handle custom output directories', async function () { |
| 179 | + const configPath = createConfig('custom-output', { output: './output/custom' }) |
| 180 | + |
| 181 | + const command = `${runner} run-workers 2 --config ${configPath} --grep "@stepbystep"` |
| 182 | + const result = await runCommand(command) |
| 183 | + |
| 184 | + console.log('STDOUT:', result.stdout) |
| 185 | + console.log('STDERR:', result.stderr) |
| 186 | + |
| 187 | + // Check that no consolidation happens in any output directory |
| 188 | + const mainConsolidatedDir = path.join(outputDir, 'stepByStepReport') |
| 189 | + const customConsolidatedDir = path.join(outputDir, 'custom', 'stepByStepReport') |
| 190 | + |
| 191 | + expect(fs.existsSync(mainConsolidatedDir)).toBe(false) |
| 192 | + expect(fs.existsSync(customConsolidatedDir)).toBe(false) |
| 193 | + |
| 194 | + console.log('✓ No stepByStepReport consolidation directory created with custom output') |
| 195 | + |
| 196 | + // Clean up |
| 197 | + fs.unlinkSync(configPath) |
| 198 | + }) |
| 199 | + |
| 200 | + it('should not crash with stepByStepReport plugin enabled', async function () { |
| 201 | + // This test ensures the plugin initialization and basic operations work |
| 202 | + // without causing crashes across different execution modes |
| 203 | + const configPath = createConfig('no-crash-test') |
| 204 | + |
| 205 | + const commands = [`${runner} run --config ${configPath} --grep "@stepbystep"`, `${runner} run-workers 2 --config ${configPath} --grep "@stepbystep"`] |
| 206 | + |
| 207 | + for (const command of commands) { |
| 208 | + const result = await runCommand(command) |
| 209 | + |
| 210 | + console.log(`Command: ${command}`) |
| 211 | + console.log('STDOUT:', result.stdout) |
| 212 | + console.log('STDERR:', result.stderr) |
| 213 | + |
| 214 | + // Ensure the plugin doesn't cause crashes |
| 215 | + expect(result.stdout).toContain('CodeceptJS') |
| 216 | + expect(result.stderr).not.toContain('Cannot read properties of undefined') |
| 217 | + expect(result.stderr).not.toContain('TypeError') |
| 218 | + |
| 219 | + // Key regression test |
| 220 | + const consolidatedDir = path.join(outputDir, 'stepByStepReport') |
| 221 | + expect(fs.existsSync(consolidatedDir)).toBe(false) |
| 222 | + } |
| 223 | + |
| 224 | + console.log('✓ Plugin works without crashes across execution modes') |
| 225 | + |
| 226 | + // Clean up |
| 227 | + fs.unlinkSync(configPath) |
| 228 | + }) |
| 229 | +}) |
0 commit comments