Skip to content

Commit

Permalink
DQA-9679: Add Behat Lint (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva authored Oct 29, 2024
1 parent ebfd066 commit 47491b7
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package.json
package-lock.json
/docs_tmp/
/.toolkit-mock
/gherkinlint.json

# Documentation folder exclusions.
!docs/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"consolidation/annotated-command": "^4.7.0",
"consolidation/robo": "^3.0 || ^4.0 || ^5.0",
"cweagans/composer-patches": "^1.7 || ^2.0",
"dantleech/gherkin-lint": "^0.2.3",
"drush/drush": "^11.0.4 || ^12.0 || ^13.0",
"ec-europa/qa-automation": "^9.3",
"ec-europa/toolkit-composer-plugin": "^0.0.1",
Expand Down
4 changes: 4 additions & 0 deletions config/commands/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ command:
config: ${toolkit.lint.cspell.config}
files: ${toolkit.lint.cspell.files}
options: ${toolkit.lint.cspell.options}
lint-behat:
options:
config: ${toolkit.lint.behat.config}
files: ${toolkit.lint.behat.files}
3 changes: 3 additions & 0 deletions config/runner/toolkit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ toolkit:
config: '.cspell.json'
files: '${toolkit.build.custom-code-folder}/'
options: '--dot --gitignore'
behat:
config: 'gherkinlint.json'
files: 'tests/features'
axe-scan:
config: axe-scan.config.json
urls:
Expand Down
19 changes: 19 additions & 0 deletions docs/guide/testing-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,25 @@ These are the default configurations in the ``runner.yml`` file.
files: 'lib/'
options: '--dot --gitignore'
Behat lint testing
^^^^^^^^^^^^^^^^^^^

To run the Behat lint you can make use of the ``toolkit:lint-behat`` command:

.. code-block::
docker-compose exec web ./vendor/bin/run toolkit:lint-behat
These are the default configurations in the ``runner.yml`` file.

.. code-block:: yaml
toolkit:
lint:
behat:
config: 'gherkinlint.json'
files: 'tests/features'
Testing in CI
-------------

Expand Down
1 change: 1 addition & 0 deletions resources/cspell/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ewppa
EXITCODE
expirable
fpfis
gherkinlint
grasmash
grumphp
gulpfile
Expand Down
73 changes: 73 additions & 0 deletions resources/gherkinlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"rules": {
"allowed-tags": {
"enabled": false
},
"filename": {
"enabled": true,
"style": "snake_case"
},
"indentation": {
"width": 2,
"feature": 0,
"rule": 1,
"background": 1,
"scenario": 1,
"step": 2,
"table": 3,
"literalBlock": 2,
"examples": 2,
"examplesTable": 3
},
"keyword-order": {
"enabled": false,
"tolerateThenBeforeWhen": true
},
"no-background-with-single-scenario": {
"enabled": true
},
"no-consecutive-empty-lines": {
"enabled": true
},
"no-restricted-patterns": {
"enabled": false
},
"no-duplicate-tags": {
"enabled": true
},
"no-duplicated-feature-names": {
"enabled": true
},
"no-duplicated-scenario-names": {
"enabled": true
},
"no-empty-background": {
"enabled": true
},
"no-empty-file": {
"enabled": true
},
"no-empty-scenarios": {
"enabled": true
},
"no-homogenous-tags": {
"enabled": true
},
"no-trailing-spaces": {
"enabled": true
},
"no-unnamed-features": {
"enabled": true
},
"one-space-between-tags": {
"enabled": true
},
"scenario-size": {
"enabled": false
},
"scenarios-per-file": {
"enabled": true,
"min": 1
}
}
}
33 changes: 33 additions & 0 deletions src/TaskRunner/Commands/LintCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,37 @@ public function toolkitLintCsPell(array $options = [
return $this->collectionBuilder()->addTaskList($tasks);
}

/**
* Run lint Behat.
*
* @command toolkit:lint-behat
*
* @option config The path to the config file.
* @option files The files to check.
*
* @aliases tk-lbehat
*
* @usage --files='tests/features' --config='gherkinlint.json'
*/
public function toolkitLintBehat(array $options = [
'config' => InputOption::VALUE_REQUIRED,
'files' => InputOption::VALUE_REQUIRED,
])
{
$tasks = [];
$bin = $this->getBinPath('gherkinlint');

// Ensure the config file exists.
if (!file_exists($options['config'])) {
$this->output->writeln('Could not find the config file, the default will be created in the project root.');
$tasks[] = $this->taskFilesystemStack()->copy(
Toolkit::getToolkitRoot() . '/resources/gherkinlint.json',
$options['config']
);
}

$tasks[] = $this->taskExec($bin . ' lint ' . $options['files']);
return $this->collectionBuilder()->addTaskList($tasks);
}

}
21 changes: 21 additions & 0 deletions tests/fixtures/commands/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,24 @@
->option('show-deprecated')
->rawArg('.')
[Simulator] Running ./vendor/bin/parallel-lint --exclude dist/ --exclude .cache/ --exclude vendor/ --exclude web/ -e 'php,module,inc,theme,install' --show-deprecated .
- command: 'toolkit:lint-behat'
configuration: []
resources: []
expectations:
- contains: |
Could not find the config file, the default will be created in the project root.
[Simulator] Simulating Filesystem\FilesystemStack()
->copy('/test/toolkit/resources/gherkinlint.json', 'gherkinlint.json')
[Simulator] Simulating Exec('./vendor/bin/gherkinlint lint tests/features')
[Simulator] Running ./vendor/bin/gherkinlint lint tests/features
- command: 'toolkit:lint-behat'
configuration: []
resources:
- from: sample-gherkinlint.json
to: gherkinlint.json
expectations:
- contains: |
[Simulator] Simulating Exec('./vendor/bin/gherkinlint lint tests/features')
[Simulator] Running ./vendor/bin/gherkinlint lint tests/features
73 changes: 73 additions & 0 deletions tests/fixtures/samples/sample-gherkinlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"rules": {
"allowed-tags": {
"enabled": false
},
"filename": {
"enabled": true,
"style": "snake_case"
},
"indentation": {
"width": 2,
"feature": 0,
"rule": 1,
"background": 1,
"scenario": 1,
"step": 2,
"table": 3,
"literalBlock": 2,
"examples": 2,
"examplesTable": 3
},
"keyword-order": {
"enabled": false,
"tolerateThenBeforeWhen": true
},
"no-background-with-single-scenario": {
"enabled": true
},
"no-consecutive-empty-lines": {
"enabled": true
},
"no-restricted-patterns": {
"enabled": false
},
"no-duplicate-tags": {
"enabled": true
},
"no-duplicated-feature-names": {
"enabled": true
},
"no-duplicated-scenario-names": {
"enabled": true
},
"no-empty-background": {
"enabled": true
},
"no-empty-file": {
"enabled": true
},
"no-empty-scenarios": {
"enabled": true
},
"no-homogenous-tags": {
"enabled": true
},
"no-trailing-spaces": {
"enabled": true
},
"no-unnamed-features": {
"enabled": true
},
"one-space-between-tags": {
"enabled": true
},
"scenario-size": {
"enabled": false
},
"scenarios-per-file": {
"enabled": true,
"min": 1
}
}
}

0 comments on commit 47491b7

Please sign in to comment.