-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { GherkinDocument } from '@cucumber/messages' | ||
|
||
import { LintError } from '../error' | ||
import { switchOrSeveritySchema } from '../schemas' | ||
import Rule from '../rule' | ||
|
||
/** | ||
* Allowed: | ||
* off | on | error | warn | ||
*/ | ||
export const schema = switchOrSeveritySchema | ||
|
||
export const run = (rule: Rule, document: GherkinDocument): Array<LintError> => { | ||
const errors: Array<LintError> = [] | ||
|
||
if (!document) { | ||
errors.push({ | ||
message: 'Feature file is empty', | ||
location: { | ||
line: 0, | ||
column: 0, | ||
}, | ||
} as LintError) | ||
} | ||
|
||
return errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Feature: No Empty File | ||
|
||
Scenario: This is valid | ||
Given I do something | ||
When I do something else | ||
Then I should have done something | ||
And I should have done something else | ||
But I shouldn't have done nothing | ||
|
||
Scenario Outline: Valid Indentation | ||
When I do each of these things | ||
| <THING> | | ||
Then I should have done something | ||
|
||
Examples: | ||
| THING | | ||
| sleep | | ||
| eat | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from 'node:path' | ||
import { Runner, Severity } from '../../src' | ||
import { expect } from 'chai' | ||
|
||
describe('No Empty File', () => { | ||
it('returns errors if the rule fails', async () => { | ||
const featureDirectory = path.join(import.meta.dirname, './features/no-empty-file') | ||
|
||
const runner = new Runner({ | ||
configDirectory: '.', | ||
featureDirectory, | ||
rules: { | ||
'no-empty-file': Severity.warn, | ||
}, | ||
}) | ||
|
||
await runner.init() | ||
const result = await runner.run() | ||
|
||
expect(result.success).to.eq(false) | ||
expect(result.errors.size).to.eq(1) | ||
expect(result.errors.has(`${featureDirectory}/valid.feature`)).to.eq(false) | ||
|
||
const errors = result.errors.get(`${featureDirectory}/invalid.feature`) | ||
expect(errors.length).to.eq(1) | ||
expect(errors[0].message).to.eq('Feature file is empty') | ||
}) | ||
}) |