diff --git a/example-esm/steps.d.ts b/example-esm/steps.d.ts index d5d62ecc0..d544e62d8 100644 --- a/example-esm/steps.d.ts +++ b/example-esm/steps.d.ts @@ -1,11 +1,9 @@ /// +type CustomHelper = InstanceType; declare namespace CodeceptJS { - interface SupportObject { - I: I - current: any - } - + interface SupportObject { I: I, current: any } + interface Methods extends CustomHelper, FileSystem, REST {} interface I extends WithTranslation {} namespace Translation { interface Actions {} diff --git a/examples/steps.d.ts b/examples/steps.d.ts new file mode 100644 index 000000000..8c779b85e --- /dev/null +++ b/examples/steps.d.ts @@ -0,0 +1,15 @@ +/// +type steps_file = typeof import('./custom_steps.js')['default']; +type Smth = typeof import('./pages/Smth.js')['default']; +type loginPage = typeof import('./pages/Login.js')['default']; +type signinFragment = typeof import('./fragments/Signin.js')['default']; +type User = InstanceType; + +declare namespace CodeceptJS { + interface SupportObject { I: I, current: any, Smth: Smth, loginPage: loginPage, signinFragment: signinFragment } + interface Methods extends Playwright, REST, User {} + interface I extends ReturnType, WithTranslation {} + namespace Translation { + interface Actions {} + } +} diff --git a/lib/command/definitions.js b/lib/command/definitions.js index db76bcde2..ade5c2535 100644 --- a/lib/command/definitions.js +++ b/lib/command/definitions.js @@ -41,7 +41,7 @@ const getDefinitionsFileContent = ({ hasCustomHelper, hasCustomStepsFile, helper const importPathsFragment = importPaths.join('\n') const supportObjectsTypeFragment = convertMapToType(supportObject) - const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : '' + const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : 'interface Methods {}' const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2) return generateDefinitionsContent({ 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 {} + } +} diff --git a/test/data/sandbox/configs/definitions/codecept.no-helpers.js b/test/data/sandbox/configs/definitions/codecept.no-helpers.js new file mode 100644 index 000000000..3625377cd --- /dev/null +++ b/test/data/sandbox/configs/definitions/codecept.no-helpers.js @@ -0,0 +1,10 @@ +export const config = { + tests: './*_test.js', + timeout: 10000, + output: './output', + helpers: {}, + include: {}, + bootstrap: false, + mocha: {}, + name: 'sandbox-no-helpers', +}; diff --git a/test/runner/definitions_test.js b/test/runner/definitions_test.js index 0fd6f25d8..ea10085ba 100644 --- a/test/runner/definitions_test.js +++ b/test/runner/definitions_test.js @@ -283,6 +283,22 @@ describe('Definitions', function () { done() }) }) + + it('def should create definition file with empty Methods interface when no helpers configured', done => { + exec(`${runner} def --config ${codecept_dir}/codecept.no-helpers.js`, (err, stdout) => { + stdout.should.include('Definitions were generated in steps.d.ts') + const types = typesFrom(`${codecept_dir}/steps.d.ts`) + types.should.be.valid + + const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`) + const fileContent = definitionFile.getFullText() + fileContent.should.include('interface Methods {}') + fileContent.should.include('interface I extends WithTranslation') + + assert(!err) + done() + }) + }) }) /**