Skip to content

Commit 58bb205

Browse files
Copilotkobenguyent
andcommitted
Changes before error encountered
Co-authored-by: kobenguyent <[email protected]>
1 parent 28bfac6 commit 58bb205

33 files changed

+276
-558
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
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+
})

test/data/fake_driver.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const Helper = require('../../lib/helper')
2+
const fs = require('fs')
3+
const path = require('path')
24

35
class FakeDriver extends Helper {
46
printBrowser() {
@@ -8,6 +10,34 @@ class FakeDriver extends Helper {
810
printWindowSize() {
911
this.debug(this.config.windowSize)
1012
}
13+
14+
wait(seconds) {
15+
// Simple wait implementation
16+
return new Promise(resolve => setTimeout(resolve, seconds * 1000))
17+
}
18+
19+
see(text) {
20+
// Always fail to trigger screenshot saving
21+
throw new Error(`Expected to see "${text}" but this is a fake driver`)
22+
}
23+
24+
async saveScreenshot(fileName, fullPage) {
25+
// Create a fake screenshot (1x1 PNG) for testing purposes
26+
const fakePngBuffer = Buffer.from([
27+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x37, 0x6e, 0xf9, 0x24, 0x00, 0x00,
28+
0x00, 0x0a, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x62, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0xe5, 0x27, 0xde, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
29+
])
30+
31+
// Ensure directory exists
32+
const dir = path.dirname(fileName)
33+
if (!fs.existsSync(dir)) {
34+
fs.mkdirSync(dir, { recursive: true })
35+
}
36+
37+
// Write the fake PNG file
38+
fs.writeFileSync(fileName, fakePngBuffer)
39+
this.debug(`Fake screenshot saved to: ${fileName}`)
40+
}
1141
}
1242

1343
module.exports = FakeDriver
66 Bytes
Loading

test/data/sandbox/codecept.addt.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/data/sandbox/codecept.async.bootstrapall.multiple.code.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/data/sandbox/codecept.bdd.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/data/sandbox/codecept.beforetest.failure.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/data/sandbox/codecept.bootstrapall.multiple.code.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

test/data/sandbox/codecept.bootstrapall.multiple.function.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)