Skip to content

Commit bda5e5e

Browse files
committed
fix bugs
1 parent 69edd06 commit bda5e5e

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

lib/container.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let container = {
3232
translation: {},
3333
/** @type {Result | null} */
3434
result: null,
35-
sharedKeys: new Set() // Track keys shared via share() function
35+
sharedKeys: new Set(), // Track keys shared via share() function
3636
}
3737

3838
/**
@@ -202,6 +202,15 @@ class Container {
202202
static append(newContainer) {
203203
container = deepMerge(container, newContainer)
204204

205+
// If new helpers are added, set the helpers property on them
206+
if (newContainer.helpers) {
207+
for (const name in newContainer.helpers) {
208+
if (container.helpers[name] && typeof container.helpers[name] === 'object') {
209+
container.helpers[name].helpers = container.helpers
210+
}
211+
}
212+
}
213+
205214
// If new support objects are added, update the proxy support
206215
if (newContainer.support) {
207216
const newProxySupport = createSupportObjects(newContainer.support)
@@ -250,10 +259,10 @@ class Container {
250259
// Instead of using append which replaces the entire container,
251260
// directly update the support object to maintain proxy references
252261
Object.assign(container.support, data)
253-
262+
254263
// Track which keys were explicitly shared
255264
Object.keys(data).forEach(key => container.sharedKeys.add(key))
256-
265+
257266
if (!options.local) {
258267
WorkerStorage.share(data)
259268
}
@@ -349,6 +358,16 @@ async function createHelpers(config) {
349358
}
350359
}
351360

361+
// Set helpers property on each helper to allow access to other helpers
362+
for (const name in helpers) {
363+
if (helpers[name] && typeof helpers[name] === 'object') {
364+
helpers[name].helpers = helpers
365+
}
366+
}
367+
368+
// Wait for async helpers and call _init
369+
await asyncHelperPromise
370+
352371
for (const name in helpers) {
353372
if (helpers[name]._init) await helpers[name]._init()
354373
}
@@ -677,24 +696,23 @@ async function loadSupportObject(modulePath, supportObjectName) {
677696
// Use dynamic import for both ESM and CJS modules
678697
let importPath = modulePath
679698
let tempJsFile = null
680-
699+
681700
if (typeof importPath === 'string') {
682701
const ext = path.extname(importPath)
683-
702+
684703
// Handle TypeScript files
685704
if (ext === '.ts') {
686705
try {
687706
// Use the TypeScript transpilation utility
688707
const typescript = await import('typescript')
689708
const { tempFile, allTempFiles } = await transpileTypeScript(importPath, typescript)
690-
709+
691710
debug(`Transpiled TypeScript file: ${importPath} -> ${tempFile}`)
692-
711+
693712
// Attach cleanup handler
694713
importPath = tempFile
695714
// Store temp files list in a way that cleanup can access them
696715
tempJsFile = allTempFiles
697-
698716
} catch (tsError) {
699717
throw new Error(`Failed to load TypeScript file ${importPath}: ${tsError.message}. Make sure 'typescript' package is installed.`)
700718
}
@@ -703,7 +721,7 @@ async function loadSupportObject(modulePath, supportObjectName) {
703721
importPath = `${importPath}.js`
704722
}
705723
}
706-
724+
707725
let obj
708726
try {
709727
obj = await import(importPath)

test/rest/REST_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('REST', () => {
140140
let jsonResponse
141141

142142
beforeEach(async () => {
143-
Container.create({
143+
await Container.create({
144144
helpers: {
145145
REST: {},
146146
JSONResponse: {},

test/unit/bdd_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ const checkTestForErrors = test => {
5555
}
5656

5757
describe('BDD', () => {
58-
beforeEach(() => {
58+
beforeEach(async () => {
5959
clearSteps()
6060
recorder.start()
61-
container.create({})
61+
await container.create({})
6262
Config.reset()
6363
})
6464

test/unit/container_test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('Container', () => {
161161
FileSystem: {},
162162
},
163163
}
164-
container.create(config)
164+
await container.create(config)
165165
await container.started()
166166
// custom helpers
167167
expect(container.helpers('MyHelper')).is.ok
@@ -266,7 +266,7 @@ describe('Container', () => {
266266
FileSystem: {},
267267
},
268268
}
269-
container.create(config)
269+
await container.create(config)
270270
await container.started()
271271
container.append({
272272
helpers: {
@@ -294,10 +294,10 @@ describe('Container', () => {
294294
const tsStepsPath = path.join(__dirname, '../data/typescript-support/steps_file.ts')
295295
await container.create({
296296
include: {
297-
I: tsStepsPath
298-
}
297+
I: tsStepsPath,
298+
},
299299
})
300-
300+
301301
const I = container.support('I')
302302
expect(I).to.be.ok
303303
expect(I.testMethod).to.be.a('function')
@@ -309,10 +309,10 @@ describe('Container', () => {
309309
const tsStepsPath = path.join(__dirname, '../data/typescript-support/steps_file.ts')
310310
await container.create({
311311
include: {
312-
I: tsStepsPath
313-
}
312+
I: tsStepsPath,
313+
},
314314
})
315-
315+
316316
const I = container.support('I')
317317
// Note: These are proxied through MetaStep, so we can't call them directly in tests
318318
// The test verifies that the file loads and the structure is correct
@@ -325,10 +325,10 @@ describe('Container', () => {
325325
const tsStepsPath = path.join(__dirname, '../data/typescript-support/steps_with_dirname.ts')
326326
await container.create({
327327
include: {
328-
I: tsStepsPath
329-
}
328+
I: tsStepsPath,
329+
},
330330
})
331-
331+
332332
const I = container.support('I')
333333
expect(I).to.be.ok
334334
expect(I.getConfigPath).to.be.a('function')
@@ -340,10 +340,10 @@ describe('Container', () => {
340340
const tsStepsPath = path.join(__dirname, '../data/typescript-support/steps_with_require.ts')
341341
await container.create({
342342
include: {
343-
I: tsStepsPath
344-
}
343+
I: tsStepsPath,
344+
},
345345
})
346-
346+
347347
const I = container.support('I')
348348
expect(I).to.be.ok
349349
expect(I.getPluginPath).to.be.a('function')

test/unit/mocha/asyncWrapper_test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ describe('AsyncWrapper', () => {
2121
test.fn = fn
2222
await Container.create({
2323
helpers: {
24-
TestHelper: {
25-
testMethod: () => 'test result',
26-
},
24+
FileSystem: {},
2725
},
2826
})
2927
})

0 commit comments

Comments
 (0)