Skip to content

Commit 504a5ae

Browse files
Jens SchulzeDavertMik
authored andcommitted
add custom steps to definition list (#174)
1 parent 9d606f9 commit 504a5ae

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

lib/command/definitions.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,34 @@ module.exports = function (genPath) {
3838
let codecept = new Codecept(config, {});
3939
codecept.init(testsPath);
4040
let helpers = container.helpers();
41-
let methods = '';
41+
let suppportI = container.support('I');
42+
let methods = [];
43+
let actions = [];
4244
for (let name in helpers) {
4345
let helper = helpers[name];
4446
methodsOfObject(helper).forEach((action) => {
4547
let params = getParamNames(helper[action]);
4648
if (params) params = params.join(', ');
4749
if (!params) params = '';
48-
methods += ` ${(action)}: (${params}) => any; \n`;
50+
methods.push(` ${(action)}: (${params}) => any; \n`);
51+
actions[action] = 1
4952
});
5053
}
51-
let definitionsTemplate = template.replace('{{methods}}', methods);
54+
for (let name in suppportI) {
55+
if (actions[name]) {
56+
continue
57+
}
58+
let actor = suppportI[name];
59+
let params = getParamNames(actor);
60+
if (params) params = params.join(', ');
61+
if (!params) params = '';
62+
methods.push(` ${(name)}: (${params}) => any; \n`);
63+
}
64+
let definitionsTemplate = template.replace('{{methods}}', methods.join(''));
5265
fs.writeFileSync(path.join(testsPath, 'steps.d.ts'), definitionsTemplate);
5366
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs');
5467
output.print('Definitions were generated in steps.d.ts');
5568
output.print('Load them by adding at the top of a test file:');
5669
output.print(output.colors.grey(`\n/// <reference path="./steps.d.ts" />`));
5770

58-
}
71+
}

lib/command/list.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@ module.exports = function (path) {
1616
codecept.init(testsPath);
1717
output.print('List of test actions: -- ');
1818
let helpers = container.helpers();
19+
let suppportI = container.support('I');
20+
let actions = [];
1921
for (let name in helpers) {
2022
let helper = helpers[name];
2123
methodsOfObject(helper).forEach((action) => {
2224
let params = getParamNames(helper[action]);
2325
if (params) params = params.join(', ');
26+
actions[action] = 1;
2427
output.print(` ${output.colors.grey(name)} I.${output.colors.bold(action)}(${params})`);
2528
});
2629
}
30+
for (let name in suppportI) {
31+
if (actions[name]) {
32+
continue
33+
}
34+
let actor = suppportI[name];
35+
let params = getParamNames(actor);
36+
if (params) params = params.join(', ');
37+
if (!params) params = '';
38+
output.print(` I.${output.colors.bold(name)}(${params})`);
39+
}
2740
output.print('PS: Actions are retrieved from enabled helpers. ')
2841
output.print('Implement custom actions in your helper classes.');
2942
};

0 commit comments

Comments
 (0)