vitest-cucumber-plugin 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -111,5 +111,4 @@ work, but this configuration isn't tested.
111
111
  ### Not yet implemented
112
112
 
113
113
  This plugin is not yet feature complete. Here is the list of features from Cucumber which aren't yet implemented:
114
- * Rule keyword
115
114
  * Doc strings
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,4 @@
1
+ * v0.1.8 : Implemented Rule keyword
1
2
  * v0.1.7 : Implemented Hooks API
2
3
  * v0.1.6 : Implemented tags boolean expression support
3
4
  * v0.1.5 : Implemented escape characters for Data Tables
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-cucumber-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Plugin for Vitest which allows for tests to be written in Cucumber format.",
5
5
  "keywords": [
6
6
  "vite",
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash/fp.js';
2
2
  import { log } from '../logger.js';
3
- import { generateExample, generateScenarioOutline } from './index.js';
3
+ import { generateExample, generateScenarioOutline, generateRule } from './index.js';
4
4
  import { escape, shouldSkip } from './util.js';
5
5
 
6
6
  export const generateFeature = (config,feature) => {
@@ -18,6 +18,8 @@ export const generateFeature = (config,feature) => {
18
18
  return testStatements + generateExample(config,statement);
19
19
  } else if (statement.type.type === 'scenarioOutline') {
20
20
  return testStatements + generateScenarioOutline(config,statement);
21
+ } else if (statement.type.type === 'rule') {
22
+ return testStatements + generateRule(config,statement);
21
23
  }
22
24
  },'')(statements);
23
25
 
@@ -3,11 +3,13 @@ import { generateExample } from './example.js';
3
3
  import { generateExamples } from './examples.js';
4
4
  import { generateScenarioOutline } from './scenario-outline.js';
5
5
  import { generateFeature } from './feature.js';
6
+ import { generateRule } from './rule.js';
6
7
 
7
8
  export {
8
9
  generateTests,
9
10
  generateExample,
10
11
  generateExamples,
11
12
  generateScenarioOutline,
12
- generateFeature
13
+ generateFeature,
14
+ generateRule,
13
15
  };
@@ -0,0 +1,22 @@
1
+ import _ from 'lodash/fp.js';
2
+ import { generateExample } from './index.js';
3
+ import { escape, shouldSkip } from './util.js';
4
+ import { log } from '../logger.js';
5
+
6
+ export const generateRule = (config,rule) => {
7
+ log.debug('generateRule config: '+JSON.stringify(config)+' rule: '+JSON.stringify(rule));
8
+
9
+ const examplesCode = _.reduce((examplesCode,example) => {
10
+ return examplesCode + generateExample(config,example);
11
+ },'')(rule.examples);
12
+
13
+ const skip = shouldSkip(config,rule.tags) ? '.skip' : '';
14
+ const tagsStr = JSON.stringify(rule.tags);
15
+
16
+ const code = ` // tags : ${tagsStr}
17
+ describe${skip}('${escape(rule.type.name)}: ${escape(rule.name)}', () => {
18
+ ${examplesCode}});
19
+ `;
20
+
21
+ return code;
22
+ }
package/src/gherkin.js CHANGED
@@ -34,6 +34,7 @@ var gherkin_umd$1 = {exports: {}};
34
34
  step : ['Given','When','Then','And','But'],
35
35
  example : ['Example','Scenario'],
36
36
  background : 'Background',
37
+ rule : 'Rule',
37
38
  }),
38
39
  },
39
40
  });
@@ -61,6 +62,7 @@ var gherkin_umd$1 = {exports: {}};
61
62
  },
62
63
  {"name": "statement", "symbols": ["example"], "postprocess": data => data[0]},
63
64
  {"name": "statement", "symbols": ["scenarioOutline"], "postprocess": data => data[0]},
65
+ {"name": "statement", "symbols": ["rule"], "postprocess": data => data[0]},
64
66
  {"name": "statements", "symbols": [], "postprocess": data => []},
65
67
  {"name": "statements", "symbols": ["statements", "statement"], "postprocess": data => fp.concat(data[0],data[1])},
66
68
  {"name": "example", "symbols": ["tags", "exampleStatement", "steps"], "postprocess": (data) => fp.assign(data[1],{ tags : data[0], steps : data[2] })},
@@ -68,6 +70,8 @@ var gherkin_umd$1 = {exports: {}};
68
70
  (data) => { return { type : { type : 'example', name : data[1] }, name : data[4].trim() } }
69
71
  },
70
72
  {"name": "exampleKeyword", "symbols": [(lexer.has("example") ? {type: "example"} : example)], "postprocess": data => data[0].value},
73
+ {"name": "exampleList", "symbols": [], "postprocess": data => []},
74
+ {"name": "exampleList", "symbols": ["exampleList", "example"], "postprocess": data => fp.concat(data[0],data[1])},
71
75
  {"name": "scenarioOutline", "symbols": ["tags", "scenarioOutlineStatement", "steps", "examplesList"], "postprocess":
72
76
  data => fp.assign(data[1],{ tags : data[0], steps : data[2], examples : data[3] })
73
77
  },
@@ -75,6 +79,13 @@ var gherkin_umd$1 = {exports: {}};
75
79
  (data) => { return { type : { type : 'scenarioOutline', name : data[1] }, name : data[4].trim() } }
76
80
  },
77
81
  {"name": "scenarioOutlineKeyword", "symbols": [(lexer.has("scenarioOutline") ? {type: "scenarioOutline"} : scenarioOutline)], "postprocess": data => data[0].value},
82
+ {"name": "rule", "symbols": ["tags", "ruleStatement", "example", "exampleList"], "postprocess":
83
+ data => fp.assign(data[1],{ tags : data[0], examples : fp.concat(data[2],data[3]) })
84
+ },
85
+ {"name": "ruleStatement", "symbols": ["_", "ruleKeyword", "_", (lexer.has("colon") ? {type: "colon"} : colon), "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
86
+ (data) => { return { type : { type : 'rule', name : data[1] }, name : data[4].trim() } }
87
+ },
88
+ {"name": "ruleKeyword", "symbols": [(lexer.has("rule") ? {type: "rule"} : rule)], "postprocess": data => data[0].value},
78
89
  {"name": "examplesList", "symbols": [], "postprocess": data => []},
79
90
  {"name": "examplesList", "symbols": ["examplesList", "examples"], "postprocess": data => fp.concat(data[0],data[1])},
80
91
  {"name": "examples", "symbols": ["tags", "examplesStatement", "dataTable", "emptyLines"], "postprocess":
package/src/gherkin.ne CHANGED
@@ -21,6 +21,7 @@ const lexer = moo.compile({
21
21
  step : ['Given','When','Then','And','But'],
22
22
  example : ['Example','Scenario'],
23
23
  background : 'Background',
24
+ rule : 'Rule',
24
25
  }),
25
26
  },
26
27
  });
@@ -56,6 +57,7 @@ backgroundStatement -> _ %background _ %colon text %newline {%
56
57
 
57
58
  statement -> example {% data => data[0] %}
58
59
  | scenarioOutline {% data => data[0] %}
60
+ | rule {% data => data[0] %}
59
61
 
60
62
  statements -> null {% data => [] %}
61
63
  | statements statement {% data => fp.concat(data[0],data[1]) %}
@@ -66,6 +68,9 @@ exampleStatement -> _ exampleKeyword _ %colon text %newline {%
66
68
  %}
67
69
  exampleKeyword -> %example {% data => data[0].value %}
68
70
 
71
+ exampleList -> null {% data => [] %}
72
+ | exampleList example {% data => fp.concat(data[0],data[1]) %}
73
+
69
74
  scenarioOutline -> tags scenarioOutlineStatement steps examplesList {%
70
75
  data => fp.assign(data[1],{ tags : data[0], steps : data[2], examples : data[3] })
71
76
  %}
@@ -74,6 +79,14 @@ scenarioOutlineStatement -> _ scenarioOutlineKeyword _ %colon text %newline {%
74
79
  %}
75
80
  scenarioOutlineKeyword -> %scenarioOutline {% data => data[0].value %}
76
81
 
82
+ rule -> tags ruleStatement example exampleList {%
83
+ data => fp.assign(data[1],{ tags : data[0], examples : fp.concat(data[2],data[3]) })
84
+ %}
85
+ ruleStatement -> _ ruleKeyword _ %colon text %newline {%
86
+ (data) => { return { type : { type : 'rule', name : data[1] }, name : data[4].trim() } }
87
+ %}
88
+ ruleKeyword -> %rule {% data => data[0].value %}
89
+
77
90
  examplesList -> null {% data => [] %}
78
91
  | examplesList examples {% data => fp.concat(data[0],data[1]) %}
79
92
 
@@ -25,6 +25,7 @@ const lexer = moo.compile({
25
25
  step : ['Given','When','Then','And','But'],
26
26
  example : ['Example','Scenario'],
27
27
  background : 'Background',
28
+ rule : 'Rule',
28
29
  }),
29
30
  },
30
31
  });
@@ -52,6 +53,7 @@ var grammar = {
52
53
  },
53
54
  {"name": "statement", "symbols": ["example"], "postprocess": data => data[0]},
54
55
  {"name": "statement", "symbols": ["scenarioOutline"], "postprocess": data => data[0]},
56
+ {"name": "statement", "symbols": ["rule"], "postprocess": data => data[0]},
55
57
  {"name": "statements", "symbols": [], "postprocess": data => []},
56
58
  {"name": "statements", "symbols": ["statements", "statement"], "postprocess": data => fp.concat(data[0],data[1])},
57
59
  {"name": "example", "symbols": ["tags", "exampleStatement", "steps"], "postprocess": (data) => fp.assign(data[1],{ tags : data[0], steps : data[2] })},
@@ -59,6 +61,8 @@ var grammar = {
59
61
  (data) => { return { type : { type : 'example', name : data[1] }, name : data[4].trim() } }
60
62
  },
61
63
  {"name": "exampleKeyword", "symbols": [(lexer.has("example") ? {type: "example"} : example)], "postprocess": data => data[0].value},
64
+ {"name": "exampleList", "symbols": [], "postprocess": data => []},
65
+ {"name": "exampleList", "symbols": ["exampleList", "example"], "postprocess": data => fp.concat(data[0],data[1])},
62
66
  {"name": "scenarioOutline", "symbols": ["tags", "scenarioOutlineStatement", "steps", "examplesList"], "postprocess":
63
67
  data => fp.assign(data[1],{ tags : data[0], steps : data[2], examples : data[3] })
64
68
  },
@@ -66,6 +70,13 @@ var grammar = {
66
70
  (data) => { return { type : { type : 'scenarioOutline', name : data[1] }, name : data[4].trim() } }
67
71
  },
68
72
  {"name": "scenarioOutlineKeyword", "symbols": [(lexer.has("scenarioOutline") ? {type: "scenarioOutline"} : scenarioOutline)], "postprocess": data => data[0].value},
73
+ {"name": "rule", "symbols": ["tags", "ruleStatement", "example", "exampleList"], "postprocess":
74
+ data => fp.assign(data[1],{ tags : data[0], examples : fp.concat(data[2],data[3]) })
75
+ },
76
+ {"name": "ruleStatement", "symbols": ["_", "ruleKeyword", "_", (lexer.has("colon") ? {type: "colon"} : colon), "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
77
+ (data) => { return { type : { type : 'rule', name : data[1] }, name : data[4].trim() } }
78
+ },
79
+ {"name": "ruleKeyword", "symbols": [(lexer.has("rule") ? {type: "rule"} : rule)], "postprocess": data => data[0].value},
69
80
  {"name": "examplesList", "symbols": [], "postprocess": data => []},
70
81
  {"name": "examplesList", "symbols": ["examplesList", "examples"], "postprocess": data => fp.concat(data[0],data[1])},
71
82
  {"name": "examples", "symbols": ["tags", "examplesStatement", "dataTable", "emptyLines"], "postprocess":
@@ -0,0 +1,14 @@
1
+ Feature: Is it Friday yet?
2
+ Everybody wants to know when it's Friday
3
+
4
+ Rule: The Sunday case
5
+ Scenario: Sunday isn't Friday
6
+ Given today is Sunday
7
+ When I ask whether it's Friday yet
8
+ Then I should be told "Nope"
9
+
10
+ Rule: The Friday case
11
+ Scenario: Friday is Friday
12
+ Given today is Friday
13
+ When I ask whether it's Friday yet
14
+ Then I should be told "TGIF"
@@ -0,0 +1,19 @@
1
+ import { Given, When, Then } from 'vitest-cucumber-plugin';
2
+ import _ from 'lodash/fp.js';
3
+ import { expect } from 'vitest'
4
+
5
+ Given('today is Sunday', function () {
6
+ return { today : 'Sunday' };
7
+ });
8
+
9
+ Given('today is Friday', function () {
10
+ return { today : 'Friday' };
11
+ });
12
+
13
+ When('I ask whether it\'s Friday yet', function (state) {
14
+ return _.set('answer',(state.today === 'Friday') ? 'TGIF' : 'Nope',state);
15
+ });
16
+
17
+ Then('I should be told {string}', function (state,[ answer ]) {
18
+ expect(state.answer).toBe(answer);
19
+ });