Skip to content

Commit 1a4a935

Browse files
DavertMikclaude
andcommitted
fix: resolve CI failures — circular deps, frozen workerMode, null paths
- Move tsFileMapping from container to store to break circular dep (step/base.js -> container.js -> step.js -> step/base.js) - Use getters with global fallback for codeceptDir/outputDir so unit tests that set global.codecept_dir directly still work - Stop freezing workerMode — it's set after initialize() by run-workers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e98569b commit 1a4a935

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

lib/container.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Container {
183183
* @api
184184
*/
185185
static tsFileMapping() {
186-
return container.tsFileMapping
186+
return store.tsFileMapping
187187
}
188188

189189
/**
@@ -426,11 +426,11 @@ async function requireHelperFromModule(helperName, config, HelperClass) {
426426
tempJsFile = allTempFiles
427427
fileMapping = mapping
428428
// Store file mapping in container for runtime error fixing (merge with existing)
429-
if (!container.tsFileMapping) {
430-
container.tsFileMapping = new Map()
429+
if (!store.tsFileMapping) {
430+
store.tsFileMapping = new Map()
431431
}
432432
for (const [key, value] of mapping.entries()) {
433-
container.tsFileMapping.set(key, value)
433+
store.tsFileMapping.set(key, value)
434434
}
435435
} catch (tsError) {
436436
throw new Error(`Failed to load TypeScript helper ${importPath}: ${tsError.message}. Make sure 'typescript' package is installed.`)

lib/step/base.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { getCurrentTimeout } from '../timeout.js'
44
import { ucfirst, humanizeString, serializeError } from '../utils.js'
55
import recordStep from './record.js'
66
import store from '../store.js'
7-
import container from '../container.js'
87

98
const STACK_LINE = 5
109

@@ -154,7 +153,7 @@ class Step {
154153
.trim()
155154

156155
// Map .temp.mjs back to original .ts files using container's tsFileMapping
157-
const fileMapping = container?.tsFileMapping?.()
156+
const fileMapping = store.tsFileMapping
158157
if (line.includes('.temp.mjs') && fileMapping) {
159158
for (const [tsFile, mjsFile] of fileMapping.entries()) {
160159
if (line.includes(mjsFile)) {

lib/step/record.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import recorder from '../recorder.js'
33
import StepConfig from './config.js'
44
import output from '../output.js'
55
import store from '../store.js'
6-
import container from '../container.js'
76
import { TIMEOUT_ORDER } from '../timeout.js'
87
import retryStep from './retry.js'
98
import { fixErrorStack } from '../utils/typescript.js'
@@ -64,7 +63,7 @@ function recordStep(step, args) {
6463
step.endTime = +Date.now()
6564

6665
// Fix error stack to point to original .ts files (lazy import to avoid circular dependency)
67-
const fileMapping = container?.tsFileMapping?.()
66+
const fileMapping = store.tsFileMapping
6867
if (fileMapping) {
6968
fixErrorStack(err, fileMapping)
7069
}

lib/store.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@ const store = {
66
// --- Required (set once via initialize(), immutable after) ---
77

88
/** @type {string | null} */
9-
codeceptDir: null,
9+
_codeceptDir: null,
1010
/** @type {string | null} */
11-
outputDir: null,
11+
_outputDir: null,
12+
13+
get codeceptDir() {
14+
return this._codeceptDir || global.codecept_dir || null
15+
},
16+
set codeceptDir(val) {
17+
this._codeceptDir = val
18+
},
19+
20+
get outputDir() {
21+
return this._outputDir || global.output_dir || null
22+
},
23+
set outputDir(val) {
24+
this._outputDir = val
25+
},
26+
1227
/** @type {boolean} */
1328
workerMode: false,
1429

@@ -78,26 +93,25 @@ const store = {
7893
/** @type {CodeceptJS.Suite | null} */
7994
currentSuite: null,
8095

96+
/** @type {Map | null} */
97+
tsFileMapping: null,
98+
8199
/**
82100
* Initialize required store fields.
83101
* These values cannot be overwritten after initialization.
84102
* @param {object} opts
85103
* @param {string} opts.codeceptDir - root directory of tests
86104
* @param {string} opts.outputDir - resolved output directory
87-
* @param {boolean} [opts.workerMode=false] - running in worker mode
88105
*/
89106
initialize(opts) {
90107
if (!opts.codeceptDir) throw new Error('codeceptDir is required')
91108
if (!opts.outputDir) throw new Error('outputDir is required')
92109

93-
this.codeceptDir = opts.codeceptDir
94-
this.outputDir = opts.outputDir
95-
// workerMode may be set before initialize() by command entry points
96-
if (opts.workerMode !== undefined) this.workerMode = opts.workerMode
110+
this._codeceptDir = opts.codeceptDir
111+
this._outputDir = opts.outputDir
97112

98-
Object.defineProperty(this, 'codeceptDir', { value: opts.codeceptDir, writable: false, configurable: false })
99-
Object.defineProperty(this, 'outputDir', { value: opts.outputDir, writable: false, configurable: false })
100-
Object.defineProperty(this, 'workerMode', { value: this.workerMode, writable: false, configurable: false })
113+
Object.defineProperty(this, '_codeceptDir', { value: opts.codeceptDir, writable: false, configurable: false })
114+
Object.defineProperty(this, '_outputDir', { value: opts.outputDir, writable: false, configurable: false })
101115
},
102116
}
103117

0 commit comments

Comments
 (0)