vitest-cucumber-plugin 0.1.8 → 0.5.0

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
@@ -106,9 +106,3 @@ Then('I should be told {string}', function (state,[ answer ], dataTable) {
106
106
 
107
107
  Currently, all step definition files must be in ECMAScript module format. CommonJS files might
108
108
  work, but this configuration isn't tested.
109
-
110
-
111
- ### Not yet implemented
112
-
113
- This plugin is not yet feature complete. Here is the list of features from Cucumber which aren't yet implemented:
114
- * Doc strings
package/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,4 @@
1
+ * v0.5.0 : Implemented Doc Strings. Plugin is now feature complete.
1
2
  * v0.1.8 : Implemented Rule keyword
2
3
  * v0.1.7 : Implemented Hooks API
3
4
  * v0.1.6 : Implemented tags boolean expression support
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-cucumber-plugin",
3
- "version": "0.1.8",
3
+ "version": "0.5.0",
4
4
  "description": "Plugin for Vitest which allows for tests to be written in Cucumber format.",
5
5
  "keywords": [
6
6
  "vite",
package/src/gherkin.js CHANGED
@@ -26,6 +26,7 @@ var gherkin_umd$1 = {exports: {}};
26
26
  escapedNewline : '\\n',
27
27
  escapedBackSlash : '\\\\',
28
28
  scenarioOutline : ['Scenario Outline','Scenario Template'],
29
+ docString : ['```','"""'],
29
30
  word : {
30
31
  match : /[^ \t\n\:\|\@\*]+/,
31
32
  type : moo.keywords({
@@ -38,6 +39,13 @@ var gherkin_umd$1 = {exports: {}};
38
39
  }),
39
40
  },
40
41
  });
42
+
43
+ const trimWhitespace = (cols,str) => {
44
+ const lines = str.split('\n').slice(0,-1);
45
+ return fp.reduce((s,line) => {
46
+ return s+line.slice(cols)+'\n'
47
+ },'')(lines);
48
+ };
41
49
  var grammar = {
42
50
  Lexer: lexer,
43
51
  ParserRules: [
@@ -95,7 +103,7 @@ var gherkin_umd$1 = {exports: {}};
95
103
  (data) => { return { type : { type : 'examples', name : data[1] }, name : data[4] } }
96
104
  },
97
105
  {"name": "examplesKeyword", "symbols": [(lexer.has("examples") ? {type: "examples"} : examples)], "postprocess": data => data[0].value},
98
- {"name": "dataTable", "symbols": [], "postprocess": data => []},
106
+ {"name": "dataTable", "symbols": ["dataTableRow"], "postprocess": data => [data[0]]},
99
107
  {"name": "dataTable", "symbols": ["dataTable", "dataTableRow"], "postprocess": data => fp.concat(data[0],[data[1]])},
100
108
  {"name": "dataTableRow", "symbols": ["_", (lexer.has("pipe") ? {type: "pipe"} : pipe), "dataTableColumns", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => data[2]},
101
109
  {"name": "dataTableColumns", "symbols": [], "postprocess": data => []},
@@ -108,12 +116,14 @@ var gherkin_umd$1 = {exports: {}};
108
116
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => '|'},
109
117
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => '\\'},
110
118
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => '\n'},
111
- {"name": "steps", "symbols": ["stepAndTable", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
119
+ {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
112
120
  {"name": "moreSteps", "symbols": [], "postprocess": data => []},
113
- {"name": "moreSteps", "symbols": ["moreSteps", "stepAndTable"], "postprocess": data => fp.concat(data[0],data[1])},
121
+ {"name": "moreSteps", "symbols": ["moreSteps", "step"], "postprocess": data => fp.concat(data[0],data[1])},
114
122
  {"name": "moreSteps", "symbols": ["moreSteps", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]},
115
- {"name": "step", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
116
- {"name": "stepAndTable", "symbols": ["step", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
123
+ {"name": "step", "symbols": ["stepStatement"]},
124
+ {"name": "step", "symbols": ["stepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
125
+ {"name": "step", "symbols": ["stepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
126
+ {"name": "stepStatement", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
117
127
  {"name": "stepKeyword", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": (data) => { return { type : 'step', name : data[0].value } }},
118
128
  {"name": "text", "symbols": [], "postprocess": data => ''},
119
129
  {"name": "text", "symbols": ["text", (lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0]+data[1].value},
@@ -137,6 +147,18 @@ var gherkin_umd$1 = {exports: {}};
137
147
  }
138
148
  },
139
149
  {"name": "freeform", "symbols": ["freeform", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]+'\n'},
150
+ {"name": "docString", "symbols": ["docStringStatement", "docText", "docStringStatement"], "postprocess":
151
+ data => fp.set('text',trimWhitespace(data[0].ws.length,data[1]),data[0])
152
+ },
153
+ {"name": "docStringStatement", "symbols": ["_", (lexer.has("docString") ? {type: "docString"} : docString), "contentType", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
154
+ (data) => { return { type : { type : 'docString', name : data[1].value }, ws : data[0], contentType : data[2] } }
155
+ },
156
+ {"name": "contentType", "symbols": [], "postprocess": data => null},
157
+ {"name": "contentType", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => null},
158
+ {"name": "contentType", "symbols": [(lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0].value},
159
+ {"name": "docText", "symbols": [], "postprocess": data => ''},
160
+ {"name": "docText", "symbols": ["docText", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => data[0]+data[1]+data[2].value},
161
+ {"name": "docText", "symbols": ["docText", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]+data[1].value},
140
162
  {"name": "_", "symbols": [], "postprocess": data => ''},
141
163
  {"name": "_", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => data[0].value},
142
164
  {"name": "emptyLines", "symbols": [], "postprocess": data => ''},
package/src/gherkin.ne CHANGED
@@ -13,6 +13,7 @@ const lexer = moo.compile({
13
13
  escapedNewline : '\\n',
14
14
  escapedBackSlash : '\\\\',
15
15
  scenarioOutline : ['Scenario Outline','Scenario Template'],
16
+ docString : ['```','"""'],
16
17
  word : {
17
18
  match : /[^ \t\n\:\|\@\*]+/,
18
19
  type : moo.keywords({
@@ -25,6 +26,13 @@ const lexer = moo.compile({
25
26
  }),
26
27
  },
27
28
  });
29
+
30
+ const trimWhitespace = (cols,str) => {
31
+ const lines = str.split('\n').slice(0,-1);
32
+ return fp.reduce((s,line) => {
33
+ return s+line.slice(cols)+'\n'
34
+ },'')(lines);
35
+ };
28
36
  %}
29
37
 
30
38
  @lexer lexer
@@ -98,7 +106,7 @@ examplesStatement -> _ examplesKeyword _ %colon text %newline {%
98
106
  %}
99
107
  examplesKeyword -> %examples {% data => data[0].value %}
100
108
 
101
- dataTable -> null {% data => [] %}
109
+ dataTable -> dataTableRow {% data => [data[0]] %}
102
110
  | dataTable dataTableRow {% data => fp.concat(data[0],[data[1]]) %}
103
111
 
104
112
  dataTableRow -> _ %pipe dataTableColumns %newline {% data => data[2] %}
@@ -116,14 +124,17 @@ escapedColumnCharaters -> %escapedPipe {% data => '|' %}
116
124
  | %escapedBackSlash {% data => '\\' %}
117
125
  | %escapedNewline {% data => '\n' %}
118
126
 
119
- steps -> stepAndTable moreSteps {% data => fp.concat(data[0],data[1]) %}
127
+ steps -> step moreSteps {% data => fp.concat(data[0],data[1]) %}
120
128
 
121
129
  moreSteps -> null {% data => [] %}
122
- | moreSteps stepAndTable {% data => fp.concat(data[0],data[1]) %}
130
+ | moreSteps step {% data => fp.concat(data[0],data[1]) %}
123
131
  | moreSteps %emptyLine {% data => data[0] %}
124
132
 
125
- step -> _ stepKeyword text %newline {% data => { return { type : data[1], text : data[2].trim() } } %}
126
- stepAndTable -> step dataTable {% data => fp.set('dataTable',data[1],data[0]) %}
133
+ step -> stepStatement
134
+ | stepStatement dataTable {% data => fp.set('dataTable',data[1],data[0]) %}
135
+ | stepStatement docString {% data => fp.set('docString',data[1],data[0]) %}
136
+
137
+ stepStatement -> _ stepKeyword text %newline {% data => { return { type : data[1], text : data[2].trim() } } %}
127
138
 
128
139
  stepKeyword -> %step {% (data) => { return { type : 'step', name : data[0].value } } %}
129
140
 
@@ -153,6 +164,21 @@ freeform -> null {% data => '' %}
153
164
  %}
154
165
  | freeform %emptyLine {% data => data[0]+'\n' %}
155
166
 
167
+ docString -> docStringStatement docText docStringStatement {%
168
+ data => fp.set('text',trimWhitespace(data[0].ws.length,data[1]),data[0])
169
+ %}
170
+ docStringStatement -> _ %docString contentType %newline {%
171
+ (data) => { return { type : { type : 'docString', name : data[1].value }, ws : data[0], contentType : data[2] } }
172
+ %}
173
+
174
+ contentType -> null {% data => null %}
175
+ | %ws {% data => null %}
176
+ | %word {% data => data[0].value %}
177
+
178
+ docText -> null {% data => '' %}
179
+ | docText text %newline {% data => data[0]+data[1]+data[2].value %}
180
+ | docText %emptyLine {% data => data[0]+data[1].value %}
181
+
156
182
  _ -> null {% data => '' %}
157
183
  | %ws {% data => data[0].value %}
158
184
 
@@ -17,6 +17,7 @@ const lexer = moo.compile({
17
17
  escapedNewline : '\\n',
18
18
  escapedBackSlash : '\\\\',
19
19
  scenarioOutline : ['Scenario Outline','Scenario Template'],
20
+ docString : ['```','"""'],
20
21
  word : {
21
22
  match : /[^ \t\n\:\|\@\*]+/,
22
23
  type : moo.keywords({
@@ -29,6 +30,13 @@ const lexer = moo.compile({
29
30
  }),
30
31
  },
31
32
  });
33
+
34
+ const trimWhitespace = (cols,str) => {
35
+ const lines = str.split('\n').slice(0,-1);
36
+ return fp.reduce((s,line) => {
37
+ return s+line.slice(cols)+'\n'
38
+ },'')(lines);
39
+ };
32
40
  var grammar = {
33
41
  Lexer: lexer,
34
42
  ParserRules: [
@@ -86,7 +94,7 @@ var grammar = {
86
94
  (data) => { return { type : { type : 'examples', name : data[1] }, name : data[4] } }
87
95
  },
88
96
  {"name": "examplesKeyword", "symbols": [(lexer.has("examples") ? {type: "examples"} : examples)], "postprocess": data => data[0].value},
89
- {"name": "dataTable", "symbols": [], "postprocess": data => []},
97
+ {"name": "dataTable", "symbols": ["dataTableRow"], "postprocess": data => [data[0]]},
90
98
  {"name": "dataTable", "symbols": ["dataTable", "dataTableRow"], "postprocess": data => fp.concat(data[0],[data[1]])},
91
99
  {"name": "dataTableRow", "symbols": ["_", (lexer.has("pipe") ? {type: "pipe"} : pipe), "dataTableColumns", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => data[2]},
92
100
  {"name": "dataTableColumns", "symbols": [], "postprocess": data => []},
@@ -99,12 +107,14 @@ var grammar = {
99
107
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => '|'},
100
108
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => '\\'},
101
109
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => '\n'},
102
- {"name": "steps", "symbols": ["stepAndTable", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
110
+ {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
103
111
  {"name": "moreSteps", "symbols": [], "postprocess": data => []},
104
- {"name": "moreSteps", "symbols": ["moreSteps", "stepAndTable"], "postprocess": data => fp.concat(data[0],data[1])},
112
+ {"name": "moreSteps", "symbols": ["moreSteps", "step"], "postprocess": data => fp.concat(data[0],data[1])},
105
113
  {"name": "moreSteps", "symbols": ["moreSteps", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]},
106
- {"name": "step", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
107
- {"name": "stepAndTable", "symbols": ["step", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
114
+ {"name": "step", "symbols": ["stepStatement"]},
115
+ {"name": "step", "symbols": ["stepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
116
+ {"name": "step", "symbols": ["stepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
117
+ {"name": "stepStatement", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
108
118
  {"name": "stepKeyword", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": (data) => { return { type : 'step', name : data[0].value } }},
109
119
  {"name": "text", "symbols": [], "postprocess": data => ''},
110
120
  {"name": "text", "symbols": ["text", (lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0]+data[1].value},
@@ -128,6 +138,18 @@ var grammar = {
128
138
  }
129
139
  },
130
140
  {"name": "freeform", "symbols": ["freeform", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]+'\n'},
141
+ {"name": "docString", "symbols": ["docStringStatement", "docText", "docStringStatement"], "postprocess":
142
+ data => fp.set('text',trimWhitespace(data[0].ws.length,data[1]),data[0])
143
+ },
144
+ {"name": "docStringStatement", "symbols": ["_", (lexer.has("docString") ? {type: "docString"} : docString), "contentType", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
145
+ (data) => { return { type : { type : 'docString', name : data[1].value }, ws : data[0], contentType : data[2] } }
146
+ },
147
+ {"name": "contentType", "symbols": [], "postprocess": data => null},
148
+ {"name": "contentType", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => null},
149
+ {"name": "contentType", "symbols": [(lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0].value},
150
+ {"name": "docText", "symbols": [], "postprocess": data => ''},
151
+ {"name": "docText", "symbols": ["docText", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => data[0]+data[1]+data[2].value},
152
+ {"name": "docText", "symbols": ["docText", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]+data[1].value},
131
153
  {"name": "_", "symbols": [], "postprocess": data => ''},
132
154
  {"name": "_", "symbols": [(lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => data[0].value},
133
155
  {"name": "emptyLines", "symbols": [], "postprocess": data => ''},
package/src/index.js CHANGED
@@ -45,7 +45,9 @@ export const Test = (state,step) => {
45
45
  log.debug('Test step: '+JSON.stringify(step)+' state:'+JSON.stringify(state));
46
46
  const stepDefinitionMatch = findStepDefinitionMatch(step);
47
47
 
48
- const newState = stepDefinitionMatch.stepDefinition.f(state,stepDefinitionMatch.parameters,step.dataTable);
48
+ const extraData = step.dataTable ? step.dataTable : (step.docString ? step.docString.text : null );
49
+
50
+ const newState = stepDefinitionMatch.stepDefinition.f(state,stepDefinitionMatch.parameters,extraData);
49
51
  log.debug('Test newState: '+JSON.stringify(newState));
50
52
 
51
53
  return newState;
@@ -0,0 +1,21 @@
1
+ Feature: Doc Strings
2
+ Scenario: You should be able to use Doc Strings with Given, When and Then statements
3
+ Given the following doc string:
4
+ """markdown
5
+ This is some cool text.
6
+
7
+ It is fun.
8
+ """
9
+
10
+ When the following doc string is appended:
11
+ ```
12
+ This is more fun.
13
+ ```
14
+
15
+ Then final doc string will look like this:
16
+ """
17
+ This is some cool text.
18
+
19
+ It is fun.
20
+ This is more fun.
21
+ """
@@ -0,0 +1,15 @@
1
+ import { Given, When, Then, DataTable } from 'vitest-cucumber-plugin';
2
+ import { expect } from 'vitest'
3
+ import _ from 'lodash/fp';
4
+
5
+ Given('the following doc string:',(state,params,docString) => {
6
+ return _.set('docString',docString,state);
7
+ });
8
+
9
+ When('the following doc string is appended:',(state,params,docString) => {
10
+ return _.set('docString',_.getOr('','docString',state)+docString,state);
11
+ });
12
+
13
+ Then('final doc string will look like this:',(state,params,docString) => {
14
+ expect(docString).toEqual(_.get('docString',state));
15
+ });