From bf494fe136babfa9b958cbeb87bf11c73e706cf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:38:54 +0000 Subject: [PATCH 1/6] Initial plan From 342af3bf8ba31f0ab47419e3faefe01c0006aa9f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:51:06 +0000 Subject: [PATCH 2/6] Initial investigation of custom helper type definition issue Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- .../configs/custom-helper-esm/codecept.conf.js | 14 ++++++++++++++ .../configs/custom-helper-esm/myhelper_helper.js | 9 +++++++++ .../sandbox/configs/custom-helper-esm/steps.d.ts | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/data/sandbox/configs/custom-helper-esm/codecept.conf.js create mode 100644 test/data/sandbox/configs/custom-helper-esm/myhelper_helper.js create mode 100644 test/data/sandbox/configs/custom-helper-esm/steps.d.ts diff --git a/test/data/sandbox/configs/custom-helper-esm/codecept.conf.js b/test/data/sandbox/configs/custom-helper-esm/codecept.conf.js new file mode 100644 index 000000000..99127f023 --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/codecept.conf.js @@ -0,0 +1,14 @@ +export const config = { + tests: './*_test.js', + output: './output', + helpers: { + FileSystem: {}, + MyHelper: { + require: './myhelper_helper.js', + }, + }, + include: {}, + bootstrap: false, + mocha: {}, + name: 'custom-helper-esm', +}; diff --git a/test/data/sandbox/configs/custom-helper-esm/myhelper_helper.js b/test/data/sandbox/configs/custom-helper-esm/myhelper_helper.js new file mode 100644 index 000000000..95c19e1fb --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/myhelper_helper.js @@ -0,0 +1,9 @@ +import Helper from '../../../../../lib/helper.js'; + +class MyHelper extends Helper { + openPage(url) { + return this.helpers.FileSystem.amInPath(url); + } +} + +export default MyHelper; diff --git a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts new file mode 100644 index 000000000..463492aed --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts @@ -0,0 +1,11 @@ +/// +type MyHelper = import('./myhelper_helper.js'); + +declare namespace CodeceptJS { + interface SupportObject { I: I, current: any } + interface Methods extends FileSystem, MyHelper {} + interface I extends WithTranslation {} + namespace Translation { + interface Actions {} + } +} From 8b3c11c93b52d3f65f65b1f2ca2d03e0ea327a83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:01:58 +0000 Subject: [PATCH 3/6] Fix custom helper type definitions for ESM default exports Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- lib/command/definitions.js | 9 ++++++-- .../configs/custom-helper-esm/My_test.ts | 7 ++++++ .../custom-helper-esm/codecept-ts.conf.js | 14 ++++++++++++ .../configs/custom-helper-esm/myhelper_ts.ts | 9 ++++++++ .../configs/custom-helper-esm/steps.d.ts | 2 +- .../configs/step-enhancements/steps.d.ts | 11 ++++++++++ test/runner/definitions_test.js | 22 +++++++++++++++++++ 7 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 test/data/sandbox/configs/custom-helper-esm/My_test.ts create mode 100644 test/data/sandbox/configs/custom-helper-esm/codecept-ts.conf.js create mode 100644 test/data/sandbox/configs/custom-helper-esm/myhelper_ts.ts create mode 100644 test/data/sandbox/configs/step-enhancements/steps.d.ts diff --git a/lib/command/definitions.js b/lib/command/definitions.js index 81bc83e02..db76bcde2 100644 --- a/lib/command/definitions.js +++ b/lib/command/definitions.js @@ -239,8 +239,13 @@ function getImportString(testsPath, targetFolderPath, pathsToType, pathsToValue) } for (const name in pathsToValue) { - const relativePath = getPath(pathsToValue[name], targetFolderPath, testsPath) - importStrings.push(`type ${name} = import('${relativePath}');`) + const originalPath = pathsToValue[name] + const relativePath = getPath(originalPath, targetFolderPath, testsPath) + if (originalPath.endsWith('.js') || originalPath.endsWith('.ts')) { + importStrings.push(`type ${name} = InstanceType;`) + } else { + importStrings.push(`type ${name} = import('${relativePath}');`) + } } return importStrings diff --git a/test/data/sandbox/configs/custom-helper-esm/My_test.ts b/test/data/sandbox/configs/custom-helper-esm/My_test.ts new file mode 100644 index 000000000..878b66728 --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/My_test.ts @@ -0,0 +1,7 @@ +Feature("My"); + +const {I} = inject(); + +Scenario("test something", () => { + I.openPage("http://codecept.io"); +}); diff --git a/test/data/sandbox/configs/custom-helper-esm/codecept-ts.conf.js b/test/data/sandbox/configs/custom-helper-esm/codecept-ts.conf.js new file mode 100644 index 000000000..97a055620 --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/codecept-ts.conf.js @@ -0,0 +1,14 @@ +export const config = { + tests: './*_test.js', + output: './output', + helpers: { + FileSystem: {}, + MyHelperTs: { + require: './myhelper_ts.ts', + }, + }, + include: {}, + bootstrap: false, + mocha: {}, + name: 'custom-helper-esm-ts', +}; diff --git a/test/data/sandbox/configs/custom-helper-esm/myhelper_ts.ts b/test/data/sandbox/configs/custom-helper-esm/myhelper_ts.ts new file mode 100644 index 000000000..d5f13dac7 --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/myhelper_ts.ts @@ -0,0 +1,9 @@ +import Helper from '../../../../../lib/helper.js'; + +class MyHelperTs extends Helper { + openPageTs(url: string): Promise { + return this.helpers.FileSystem.amInPath(url); + } +} + +export default MyHelperTs; diff --git a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts index 463492aed..edb27382a 100644 --- a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts +++ b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts @@ -1,5 +1,5 @@ /// -type MyHelper = import('./myhelper_helper.js'); +type MyHelper = InstanceType; declare namespace CodeceptJS { interface SupportObject { I: I, current: any } diff --git a/test/data/sandbox/configs/step-enhancements/steps.d.ts b/test/data/sandbox/configs/step-enhancements/steps.d.ts new file mode 100644 index 000000000..7f7a36764 --- /dev/null +++ b/test/data/sandbox/configs/step-enhancements/steps.d.ts @@ -0,0 +1,11 @@ +/// +type CustomHelper = InstanceType; + +declare namespace CodeceptJS { + interface SupportObject { I: I, current: any } + interface Methods extends FileSystem, CustomHelper {} + interface I extends WithTranslation {} + namespace Translation { + interface Actions {} + } +} diff --git a/test/runner/definitions_test.js b/test/runner/definitions_test.js index 4e06c2cc1..0fd6f25d8 100644 --- a/test/runner/definitions_test.js +++ b/test/runner/definitions_test.js @@ -261,6 +261,28 @@ describe('Definitions', function () { done() }) }) + + it('def should create definition file with custom helper using ESM default export', done => { + const customHelperDir = `${codecept_dir}/../custom-helper-esm` + exec(`${runner} def --config ${customHelperDir}/codecept.conf.js`, (err, stdout) => { + stdout.should.include('Definitions were generated in steps.d.ts') + const types = typesFrom(`${customHelperDir}/steps.d.ts`) + types.should.be.valid + + const definitionFile = types.getSourceFileOrThrow(`${customHelperDir}/steps.d.ts`) + const fileContent = definitionFile.getFullText() + fileContent.should.include("type MyHelper = InstanceType;") + + const extend = getExtends(definitionFile.getModule('CodeceptJS').getInterfaceOrThrow('I')) + const hasOpenPageMethod = extend.some(ext => + ext.methods && ext.methods.some(m => m.name === 'openPage') + ) + hasOpenPageMethod.should.be.true + + assert(!err) + done() + }) + }) }) /** From 63c38d3c5ac09330ca941cab97689cf7fe45fac9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:05:39 +0000 Subject: [PATCH 4/6] Remove generated steps.d.ts files from test fixtures --- .../data/sandbox/configs/custom-helper-esm/steps.d.ts | 11 ----------- .../data/sandbox/configs/step-enhancements/steps.d.ts | 11 ----------- 2 files changed, 22 deletions(-) delete mode 100644 test/data/sandbox/configs/custom-helper-esm/steps.d.ts delete mode 100644 test/data/sandbox/configs/step-enhancements/steps.d.ts diff --git a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts deleted file mode 100644 index edb27382a..000000000 --- a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// -type MyHelper = InstanceType; - -declare namespace CodeceptJS { - interface SupportObject { I: I, current: any } - interface Methods extends FileSystem, MyHelper {} - interface I extends WithTranslation {} - namespace Translation { - interface Actions {} - } -} diff --git a/test/data/sandbox/configs/step-enhancements/steps.d.ts b/test/data/sandbox/configs/step-enhancements/steps.d.ts deleted file mode 100644 index 7f7a36764..000000000 --- a/test/data/sandbox/configs/step-enhancements/steps.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// -type CustomHelper = InstanceType; - -declare namespace CodeceptJS { - interface SupportObject { I: I, current: any } - interface Methods extends FileSystem, CustomHelper {} - interface I extends WithTranslation {} - namespace Translation { - interface Actions {} - } -} From cdb5b16c1ad9e0e3ecd9e6d80fd273baa2529a07 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:09:37 +0000 Subject: [PATCH 5/6] Final verification complete - all tests pass Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- .../data/sandbox/configs/custom-helper-esm/steps.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/data/sandbox/configs/custom-helper-esm/steps.d.ts diff --git a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts new file mode 100644 index 000000000..edb27382a --- /dev/null +++ b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts @@ -0,0 +1,11 @@ +/// +type MyHelper = InstanceType; + +declare namespace CodeceptJS { + interface SupportObject { I: I, current: any } + interface Methods extends FileSystem, MyHelper {} + interface I extends WithTranslation {} + namespace Translation { + interface Actions {} + } +} From ac24a431ec374811a55c7e5a2296ead973a9a4bb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 15:09:58 +0000 Subject: [PATCH 6/6] Remove generated steps.d.ts file from test fixtures Co-authored-by: kobenguyent <7845001+kobenguyent@users.noreply.github.com> --- .../data/sandbox/configs/custom-helper-esm/steps.d.ts | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 test/data/sandbox/configs/custom-helper-esm/steps.d.ts diff --git a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts b/test/data/sandbox/configs/custom-helper-esm/steps.d.ts deleted file mode 100644 index edb27382a..000000000 --- a/test/data/sandbox/configs/custom-helper-esm/steps.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// -type MyHelper = InstanceType; - -declare namespace CodeceptJS { - interface SupportObject { I: I, current: any } - interface Methods extends FileSystem, MyHelper {} - interface I extends WithTranslation {} - namespace Translation { - interface Actions {} - } -}