Skip to content

Commit

Permalink
Feature: add target folder parameter to def command (codeceptjs#1689)
Browse files Browse the repository at this point in the history
* add parameter 'to' to def command

* update doc for def command

* change name of def param to output
  • Loading branch information
Evgeniy Lukoyanov authored and DavertMik committed Jun 2, 2019
1 parent 51c3110 commit 833eb82
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ program.command('list [path]')
program.command('def [path]')
.description('Generates TypeScript definitions for all I actions.')
.option('-c, --config [file]', 'configuration file to be used')
.option('-o, --output [folder]', 'target folder to paste definitions')
.action(require('../lib/command/definitions'));

program.command('gherkin:init [path]')
Expand Down
7 changes: 7 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ Feature('My new test');

After doing that IDE should provide autocompletion for `I` object inside `Scenario` and `within` blocks.

Add optional parameter `output` (or shortcat `-o`), if you want to place your definition file in specific folder:

```sh
codeceptjs def --output ./tests/typings
codeceptjs def -o ./tests/typings
```

## List Commands

Prints all available methods of `I` to console
Expand Down
4 changes: 3 additions & 1 deletion lib/command/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ module.exports = function (genPath, options) {
const config = getConfig(configFile);
if (!config) return;

const targetFolderPath = options.output && getTestRoot(options.output) || testsPath;

const codecept = new Codecept(config, {});
codecept.init(testsPath);

Expand Down Expand Up @@ -188,7 +190,7 @@ module.exports = function (genPath, options) {
definitionsTemplate = definitionsTemplate.replace(/\{\{I\}\}/g, translations.I);
}

fs.writeFileSync(path.join(testsPath, 'steps.d.ts'), definitionsTemplate);
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsTemplate);
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs');
output.print('Definitions were generated in steps.d.ts');
output.print('Load them by adding at the top of a test file:');
Expand Down

0 comments on commit 833eb82

Please sign in to comment.