Skip to content

Commit 262935d

Browse files
authored
Fix TypeScript definitions generation when no helpers configured (#5325)
1 parent 23fad16 commit 262935d

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

example-esm/steps.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/// <reference types='codeceptjs' />
2+
type CustomHelper = InstanceType<typeof import('./helpers/CustomHelper.js').default>;
23

34
declare namespace CodeceptJS {
4-
interface SupportObject {
5-
I: I
6-
current: any
7-
}
8-
5+
interface SupportObject { I: I, current: any }
6+
interface Methods extends CustomHelper, FileSystem, REST {}
97
interface I extends WithTranslation<Methods> {}
108
namespace Translation {
119
interface Actions {}

examples/steps.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types='codeceptjs' />
2+
type steps_file = typeof import('./custom_steps.js')['default'];
3+
type Smth = typeof import('./pages/Smth.js')['default'];
4+
type loginPage = typeof import('./pages/Login.js')['default'];
5+
type signinFragment = typeof import('./fragments/Signin.js')['default'];
6+
type User = InstanceType<typeof import('./user_helper.js').default>;
7+
8+
declare namespace CodeceptJS {
9+
interface SupportObject { I: I, current: any, Smth: Smth, loginPage: loginPage, signinFragment: signinFragment }
10+
interface Methods extends Playwright, REST, User {}
11+
interface I extends ReturnType<steps_file>, WithTranslation<Methods> {}
12+
namespace Translation {
13+
interface Actions {}
14+
}
15+
}

lib/command/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const getDefinitionsFileContent = ({ hasCustomHelper, hasCustomStepsFile, helper
4141

4242
const importPathsFragment = importPaths.join('\n')
4343
const supportObjectsTypeFragment = convertMapToType(supportObject)
44-
const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : ''
44+
const methodsTypeFragment = helperNames.length > 0 ? `interface Methods extends ${helperNames.join(', ')} {}` : 'interface Methods {}'
4545
const translatedActionsFragment = JSON.stringify(translations.vocabulary.actions, null, 2)
4646

4747
return generateDefinitionsContent({
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types='codeceptjs' />
2+
type MyHelper = InstanceType<typeof import('./myhelper_helper.js').default>;
3+
4+
declare namespace CodeceptJS {
5+
interface SupportObject { I: I, current: any }
6+
interface Methods extends FileSystem, MyHelper {}
7+
interface I extends WithTranslation<Methods> {}
8+
namespace Translation {
9+
interface Actions {}
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const config = {
2+
tests: './*_test.js',
3+
timeout: 10000,
4+
output: './output',
5+
helpers: {},
6+
include: {},
7+
bootstrap: false,
8+
mocha: {},
9+
name: 'sandbox-no-helpers',
10+
};

test/runner/definitions_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ describe('Definitions', function () {
283283
done()
284284
})
285285
})
286+
287+
it('def should create definition file with empty Methods interface when no helpers configured', done => {
288+
exec(`${runner} def --config ${codecept_dir}/codecept.no-helpers.js`, (err, stdout) => {
289+
stdout.should.include('Definitions were generated in steps.d.ts')
290+
const types = typesFrom(`${codecept_dir}/steps.d.ts`)
291+
types.should.be.valid
292+
293+
const definitionFile = types.getSourceFileOrThrow(`${codecept_dir}/steps.d.ts`)
294+
const fileContent = definitionFile.getFullText()
295+
fileContent.should.include('interface Methods {}')
296+
fileContent.should.include('interface I extends WithTranslation<Methods>')
297+
298+
assert(!err)
299+
done()
300+
})
301+
})
286302
})
287303

288304
/**

0 commit comments

Comments
 (0)