Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions example-esm/steps.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// <reference types='codeceptjs' />
type CustomHelper = InstanceType<typeof import('./helpers/CustomHelper.js').default>;

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<Methods> {}
namespace Translation {
interface Actions {}
Expand Down
15 changes: 15 additions & 0 deletions examples/steps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types='codeceptjs' />
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<typeof import('./user_helper.js').default>;

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<steps_file>, WithTranslation<Methods> {}
namespace Translation {
interface Actions {}
}
}
2 changes: 1 addition & 1 deletion lib/command/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
11 changes: 11 additions & 0 deletions test/data/sandbox/configs/custom-helper-esm/steps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types='codeceptjs' />
type MyHelper = InstanceType<typeof import('./myhelper_helper.js').default>;

declare namespace CodeceptJS {
interface SupportObject { I: I, current: any }
interface Methods extends FileSystem, MyHelper {}
interface I extends WithTranslation<Methods> {}
namespace Translation {
interface Actions {}
}
}
10 changes: 10 additions & 0 deletions test/data/sandbox/configs/definitions/codecept.no-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const config = {
tests: './*_test.js',
timeout: 10000,
output: './output',
helpers: {},
include: {},
bootstrap: false,
mocha: {},
name: 'sandbox-no-helpers',
};
16 changes: 16 additions & 0 deletions test/runner/definitions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Methods>')

assert(!err)
done()
})
})
})

/**
Expand Down