Skip to content

Commit 6f53fb4

Browse files
DavertMikclaude
andcommitted
fix: migrate utils_test to use store instead of globals
Revert getter priority to store-first (correct design). Fix the test to set store.codeceptDir/outputDir instead of globals. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b223193 commit 6f53fb4

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const store = {
1111
_outputDir: null,
1212

1313
get codeceptDir() {
14-
return global.codecept_dir || this._codeceptDir || null
14+
return this._codeceptDir || global.codecept_dir || null
1515
},
1616
set codeceptDir(val) {
1717
this._codeceptDir = val
1818
},
1919

2020
get outputDir() {
21-
return global.output_dir || this._outputDir || null
21+
return this._outputDir || global.output_dir || null
2222
},
2323
set outputDir(val) {
2424
this._outputDir = val

test/unit/utils_test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path'
44
import { fileURLToPath } from 'url'
55
import sinon from 'sinon'
66
import * as utils from '../../lib/utils.js'
7+
import store from '../../lib/store.js'
78
import playwright from 'playwright'
89

910
const __filename = fileURLToPath(import.meta.url)
@@ -302,20 +303,20 @@ describe('utils', () => {
302303
})
303304

304305
describe('#screenshotOutputFolder', () => {
305-
let _oldGlobalOutputDir
306-
let _oldGlobalCodeceptDir
306+
let _oldOutputDir
307+
let _oldCodeceptDir
307308

308309
before(() => {
309-
_oldGlobalOutputDir = global.output_dir
310-
_oldGlobalCodeceptDir = global.codecept_dir
310+
_oldOutputDir = store.outputDir
311+
_oldCodeceptDir = store.codeceptDir
311312

312-
global.output_dir = '/Users/someuser/workbase/project1/test_output'
313-
global.codecept_dir = '/Users/someuser/workbase/project1/tests/e2e'
313+
store.outputDir = '/Users/someuser/workbase/project1/test_output'
314+
store.codeceptDir = '/Users/someuser/workbase/project1/tests/e2e'
314315
})
315316

316317
after(() => {
317-
global.output_dir = _oldGlobalOutputDir
318-
global.codecept_dir = _oldGlobalCodeceptDir
318+
store.outputDir = _oldOutputDir
319+
store.codeceptDir = _oldCodeceptDir
319320
})
320321

321322
it('returns the joined filename for filename only', () => {
@@ -326,7 +327,7 @@ describe('utils', () => {
326327
it('returns the given filename for absolute one', () => {
327328
const _path = utils.screenshotOutputFolder('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png'.replace(/\//g, path.sep))
328329
if (os.platform() === 'win32') {
329-
expect(_path).eql(path.resolve(global.codecept_dir, '/Users/someuser/workbase/project1/test_output/screenshot1.failed.png'))
330+
expect(_path).eql(path.resolve(store.codeceptDir, '/Users/someuser/workbase/project1/test_output/screenshot1.failed.png'))
330331
} else {
331332
expect(_path).eql('/Users/someuser/workbase/project1/test_output/screenshot1.failed.png')
332333
}

0 commit comments

Comments
 (0)