vitest-cucumber-plugin 0.5.2 → 0.5.3

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/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,4 @@
1
+ * v0.5.3 : Provide code snippets when a step definition is not found
1
2
  * v0.5.2 : Throw an error if a step file import fails instead of logging it
2
3
  * v0.5.1 : Added info level logging for tracing state through steps. Also added a log file option.
3
4
  * v0.5.0 : Implemented Doc Strings. Plugin is now feature complete.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-cucumber-plugin",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
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
@@ -20,7 +20,7 @@ var gherkin_umd$1 = {exports: {}};
20
20
  ws : /[ \t]+/,
21
21
  at : '@',
22
22
  colon : ':',
23
- step : '*',
23
+ repeatStep : '*',
24
24
  pipe : '|',
25
25
  escapedPipe : '\\|',
26
26
  escapedNewline : '\\n',
@@ -32,7 +32,10 @@ var gherkin_umd$1 = {exports: {}};
32
32
  type : moo.keywords({
33
33
  feature : 'Feature',
34
34
  examples : ['Examples','Scenarios'],
35
- step : ['Given','When','Then','And','But'],
35
+ given : 'Given',
36
+ when : 'When',
37
+ then : 'Then',
38
+ repeatStep : ['And','But'],
36
39
  example : ['Example','Scenario'],
37
40
  background : 'Background',
38
41
  rule : 'Rule',
@@ -44,8 +47,18 @@ var gherkin_umd$1 = {exports: {}};
44
47
  const lines = str.split('\n').slice(0,-1);
45
48
  return fp.reduce((s,line) => {
46
49
  return s+line.slice(cols)+'\n'
47
- },'')(lines);
50
+ },'')(lines);
48
51
  };
52
+
53
+ const setRepeatStepTypesReducer = (steps,step) => {
54
+ if (!fp.has('type.type',step)) {
55
+ step = fp.set('type.type',fp.last(steps).type.type,step);
56
+ }
57
+ return fp.concat(steps,step);
58
+ };
59
+
60
+ const setRepeatStepTypes = (steps) => fp.reduce(setRepeatStepTypesReducer,[],steps);
61
+
49
62
  var grammar = {
50
63
  Lexer: lexer,
51
64
  ParserRules: [
@@ -116,15 +129,25 @@ var gherkin_umd$1 = {exports: {}};
116
129
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => '|'},
117
130
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => '\\'},
118
131
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => '\n'},
119
- {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
132
+ {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => setRepeatStepTypes(fp.concat(data[0],data[1]))},
120
133
  {"name": "moreSteps", "symbols": [], "postprocess": data => []},
121
134
  {"name": "moreSteps", "symbols": ["moreSteps", "step"], "postprocess": data => fp.concat(data[0],data[1])},
135
+ {"name": "moreSteps", "symbols": ["moreSteps", "repeatStep"], "postprocess": data => fp.concat(data[0],data[1])},
122
136
  {"name": "moreSteps", "symbols": ["moreSteps", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]},
123
137
  {"name": "step", "symbols": ["stepStatement"]},
124
138
  {"name": "step", "symbols": ["stepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
125
139
  {"name": "step", "symbols": ["stepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
126
140
  {"name": "stepStatement", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
127
- {"name": "stepKeyword", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": (data) => { return { type : 'step', name : data[0].value } }},
141
+ {"name": "stepKeyword", "symbols": [(lexer.has("given") ? {type: "given"} : given)], "postprocess": (data) => { return { type : 'given', name : data[0].value } }},
142
+ {"name": "stepKeyword", "symbols": [(lexer.has("when") ? {type: "when"} : when)], "postprocess": (data) => { return { type : 'when', name : data[0].value } }},
143
+ {"name": "stepKeyword", "symbols": [(lexer.has("then") ? {type: "then"} : then)], "postprocess": (data) => { return { type : 'then', name : data[0].value } }},
144
+ {"name": "repeatStep", "symbols": ["repeatStepStatement"]},
145
+ {"name": "repeatStep", "symbols": ["repeatStepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
146
+ {"name": "repeatStep", "symbols": ["repeatStepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
147
+ {"name": "repeatStepStatement", "symbols": ["_", "repeatStepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
148
+ data => { return { type : data[1], text : data[2].trim() } }
149
+ },
150
+ {"name": "repeatStepKeyword", "symbols": [(lexer.has("repeatStep") ? {type: "repeatStep"} : repeatStep)], "postprocess": (data) => { return { name : data[0].value } }},
128
151
  {"name": "text", "symbols": [], "postprocess": data => ''},
129
152
  {"name": "text", "symbols": ["text", (lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0]+data[1].value},
130
153
  {"name": "text", "symbols": ["text", (lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => data[0]+data[1].value},
@@ -133,7 +156,10 @@ var gherkin_umd$1 = {exports: {}};
133
156
  {"name": "text", "symbols": ["text", (lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => data[0]+data[1].value},
134
157
  {"name": "text", "symbols": ["text", (lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => data[0]+data[1].value},
135
158
  {"name": "text", "symbols": ["text", (lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => data[0]+data[1].value},
136
- {"name": "keywords", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": data => data[0].value},
159
+ {"name": "keywords", "symbols": [(lexer.has("given") ? {type: "given"} : given)], "postprocess": data => data[0].value},
160
+ {"name": "keywords", "symbols": [(lexer.has("when") ? {type: "when"} : when)], "postprocess": data => data[0].value},
161
+ {"name": "keywords", "symbols": [(lexer.has("then") ? {type: "then"} : then)], "postprocess": data => data[0].value},
162
+ {"name": "keywords", "symbols": [(lexer.has("repeatStep") ? {type: "repeatStep"} : repeatStep)], "postprocess": data => data[0].value},
137
163
  {"name": "keywords", "symbols": [(lexer.has("colon") ? {type: "colon"} : colon)], "postprocess": data => data[0].value},
138
164
  {"name": "keywords", "symbols": [(lexer.has("example") ? {type: "example"} : example)], "postprocess": data => data[0].value},
139
165
  {"name": "keywords", "symbols": [(lexer.has("examples") ? {type: "examples"} : examples)], "postprocess": data => data[0].value},
package/src/gherkin.ne CHANGED
@@ -7,7 +7,7 @@ const lexer = moo.compile({
7
7
  ws : /[ \t]+/,
8
8
  at : '@',
9
9
  colon : ':',
10
- step : '*',
10
+ repeatStep : '*',
11
11
  pipe : '|',
12
12
  escapedPipe : '\\|',
13
13
  escapedNewline : '\\n',
@@ -19,7 +19,10 @@ const lexer = moo.compile({
19
19
  type : moo.keywords({
20
20
  feature : 'Feature',
21
21
  examples : ['Examples','Scenarios'],
22
- step : ['Given','When','Then','And','But'],
22
+ given : 'Given',
23
+ when : 'When',
24
+ then : 'Then',
25
+ repeatStep : ['And','But'],
23
26
  example : ['Example','Scenario'],
24
27
  background : 'Background',
25
28
  rule : 'Rule',
@@ -31,8 +34,18 @@ const trimWhitespace = (cols,str) => {
31
34
  const lines = str.split('\n').slice(0,-1);
32
35
  return fp.reduce((s,line) => {
33
36
  return s+line.slice(cols)+'\n'
34
- },'')(lines);
37
+ },'')(lines);
35
38
  };
39
+
40
+ const setRepeatStepTypesReducer = (steps,step) => {
41
+ if (!fp.has('type.type',step)) {
42
+ step = fp.set('type.type',fp.last(steps).type.type,step);
43
+ }
44
+ return fp.concat(steps,step);
45
+ };
46
+
47
+ const setRepeatStepTypes = (steps) => fp.reduce(setRepeatStepTypesReducer,[],steps);
48
+
36
49
  %}
37
50
 
38
51
  @lexer lexer
@@ -124,10 +137,11 @@ escapedColumnCharaters -> %escapedPipe {% data => '|' %}
124
137
  | %escapedBackSlash {% data => '\\' %}
125
138
  | %escapedNewline {% data => '\n' %}
126
139
 
127
- steps -> step moreSteps {% data => fp.concat(data[0],data[1]) %}
140
+ steps -> step moreSteps {% data => setRepeatStepTypes(fp.concat(data[0],data[1])) %}
128
141
 
129
142
  moreSteps -> null {% data => [] %}
130
143
  | moreSteps step {% data => fp.concat(data[0],data[1]) %}
144
+ | moreSteps repeatStep {% data => fp.concat(data[0],data[1]) %}
131
145
  | moreSteps %emptyLine {% data => data[0] %}
132
146
 
133
147
  step -> stepStatement
@@ -136,7 +150,19 @@ step -> stepStatement
136
150
 
137
151
  stepStatement -> _ stepKeyword text %newline {% data => { return { type : data[1], text : data[2].trim() } } %}
138
152
 
139
- stepKeyword -> %step {% (data) => { return { type : 'step', name : data[0].value } } %}
153
+ stepKeyword -> %given {% (data) => { return { type : 'given', name : data[0].value } } %}
154
+ | %when {% (data) => { return { type : 'when', name : data[0].value } } %}
155
+ | %then {% (data) => { return { type : 'then', name : data[0].value } } %}
156
+
157
+ repeatStep -> repeatStepStatement
158
+ | repeatStepStatement dataTable {% data => fp.set('dataTable',data[1],data[0]) %}
159
+ | repeatStepStatement docString {% data => fp.set('docString',data[1],data[0]) %}
160
+
161
+ repeatStepStatement -> _ repeatStepKeyword text %newline {%
162
+ data => { return { type : data[1], text : data[2].trim() } }
163
+ %}
164
+
165
+ repeatStepKeyword -> %repeatStep {% (data) => { return { name : data[0].value } } %}
140
166
 
141
167
  text -> null {% data => '' %}
142
168
  | text %word {% data => data[0]+data[1].value %}
@@ -147,7 +173,10 @@ text -> null {% data => '' %}
147
173
  | text %escapedNewline {% data => data[0]+data[1].value %}
148
174
  | text %escapedBackSlash {% data => data[0]+data[1].value %}
149
175
 
150
- keywords -> %step {% data => data[0].value %}
176
+ keywords -> %given {% data => data[0].value %}
177
+ | %when {% data => data[0].value %}
178
+ | %then {% data => data[0].value %}
179
+ | %repeatStep {% data => data[0].value %}
151
180
  | %colon {% data => data[0].value %}
152
181
  | %example {% data => data[0].value %}
153
182
  | %examples {% data => data[0].value %}
@@ -11,7 +11,7 @@ const lexer = moo.compile({
11
11
  ws : /[ \t]+/,
12
12
  at : '@',
13
13
  colon : ':',
14
- step : '*',
14
+ repeatStep : '*',
15
15
  pipe : '|',
16
16
  escapedPipe : '\\|',
17
17
  escapedNewline : '\\n',
@@ -23,7 +23,10 @@ const lexer = moo.compile({
23
23
  type : moo.keywords({
24
24
  feature : 'Feature',
25
25
  examples : ['Examples','Scenarios'],
26
- step : ['Given','When','Then','And','But'],
26
+ given : 'Given',
27
+ when : 'When',
28
+ then : 'Then',
29
+ repeatStep : ['And','But'],
27
30
  example : ['Example','Scenario'],
28
31
  background : 'Background',
29
32
  rule : 'Rule',
@@ -35,8 +38,18 @@ const trimWhitespace = (cols,str) => {
35
38
  const lines = str.split('\n').slice(0,-1);
36
39
  return fp.reduce((s,line) => {
37
40
  return s+line.slice(cols)+'\n'
38
- },'')(lines);
41
+ },'')(lines);
39
42
  };
43
+
44
+ const setRepeatStepTypesReducer = (steps,step) => {
45
+ if (!fp.has('type.type',step)) {
46
+ step = fp.set('type.type',fp.last(steps).type.type,step);
47
+ }
48
+ return fp.concat(steps,step);
49
+ };
50
+
51
+ const setRepeatStepTypes = (steps) => fp.reduce(setRepeatStepTypesReducer,[],steps);
52
+
40
53
  var grammar = {
41
54
  Lexer: lexer,
42
55
  ParserRules: [
@@ -107,15 +120,25 @@ var grammar = {
107
120
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => '|'},
108
121
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => '\\'},
109
122
  {"name": "escapedColumnCharaters", "symbols": [(lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => '\n'},
110
- {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => fp.concat(data[0],data[1])},
123
+ {"name": "steps", "symbols": ["step", "moreSteps"], "postprocess": data => setRepeatStepTypes(fp.concat(data[0],data[1]))},
111
124
  {"name": "moreSteps", "symbols": [], "postprocess": data => []},
112
125
  {"name": "moreSteps", "symbols": ["moreSteps", "step"], "postprocess": data => fp.concat(data[0],data[1])},
126
+ {"name": "moreSteps", "symbols": ["moreSteps", "repeatStep"], "postprocess": data => fp.concat(data[0],data[1])},
113
127
  {"name": "moreSteps", "symbols": ["moreSteps", (lexer.has("emptyLine") ? {type: "emptyLine"} : emptyLine)], "postprocess": data => data[0]},
114
128
  {"name": "step", "symbols": ["stepStatement"]},
115
129
  {"name": "step", "symbols": ["stepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
116
130
  {"name": "step", "symbols": ["stepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
117
131
  {"name": "stepStatement", "symbols": ["_", "stepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": data => { return { type : data[1], text : data[2].trim() } }},
118
- {"name": "stepKeyword", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": (data) => { return { type : 'step', name : data[0].value } }},
132
+ {"name": "stepKeyword", "symbols": [(lexer.has("given") ? {type: "given"} : given)], "postprocess": (data) => { return { type : 'given', name : data[0].value } }},
133
+ {"name": "stepKeyword", "symbols": [(lexer.has("when") ? {type: "when"} : when)], "postprocess": (data) => { return { type : 'when', name : data[0].value } }},
134
+ {"name": "stepKeyword", "symbols": [(lexer.has("then") ? {type: "then"} : then)], "postprocess": (data) => { return { type : 'then', name : data[0].value } }},
135
+ {"name": "repeatStep", "symbols": ["repeatStepStatement"]},
136
+ {"name": "repeatStep", "symbols": ["repeatStepStatement", "dataTable"], "postprocess": data => fp.set('dataTable',data[1],data[0])},
137
+ {"name": "repeatStep", "symbols": ["repeatStepStatement", "docString"], "postprocess": data => fp.set('docString',data[1],data[0])},
138
+ {"name": "repeatStepStatement", "symbols": ["_", "repeatStepKeyword", "text", (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess":
139
+ data => { return { type : data[1], text : data[2].trim() } }
140
+ },
141
+ {"name": "repeatStepKeyword", "symbols": [(lexer.has("repeatStep") ? {type: "repeatStep"} : repeatStep)], "postprocess": (data) => { return { name : data[0].value } }},
119
142
  {"name": "text", "symbols": [], "postprocess": data => ''},
120
143
  {"name": "text", "symbols": ["text", (lexer.has("word") ? {type: "word"} : word)], "postprocess": data => data[0]+data[1].value},
121
144
  {"name": "text", "symbols": ["text", (lexer.has("ws") ? {type: "ws"} : ws)], "postprocess": data => data[0]+data[1].value},
@@ -124,7 +147,10 @@ var grammar = {
124
147
  {"name": "text", "symbols": ["text", (lexer.has("escapedPipe") ? {type: "escapedPipe"} : escapedPipe)], "postprocess": data => data[0]+data[1].value},
125
148
  {"name": "text", "symbols": ["text", (lexer.has("escapedNewline") ? {type: "escapedNewline"} : escapedNewline)], "postprocess": data => data[0]+data[1].value},
126
149
  {"name": "text", "symbols": ["text", (lexer.has("escapedBackSlash") ? {type: "escapedBackSlash"} : escapedBackSlash)], "postprocess": data => data[0]+data[1].value},
127
- {"name": "keywords", "symbols": [(lexer.has("step") ? {type: "step"} : step)], "postprocess": data => data[0].value},
150
+ {"name": "keywords", "symbols": [(lexer.has("given") ? {type: "given"} : given)], "postprocess": data => data[0].value},
151
+ {"name": "keywords", "symbols": [(lexer.has("when") ? {type: "when"} : when)], "postprocess": data => data[0].value},
152
+ {"name": "keywords", "symbols": [(lexer.has("then") ? {type: "then"} : then)], "postprocess": data => data[0].value},
153
+ {"name": "keywords", "symbols": [(lexer.has("repeatStep") ? {type: "repeatStep"} : repeatStep)], "postprocess": data => data[0].value},
128
154
  {"name": "keywords", "symbols": [(lexer.has("colon") ? {type: "colon"} : colon)], "postprocess": data => data[0].value},
129
155
  {"name": "keywords", "symbols": [(lexer.has("example") ? {type: "example"} : example)], "postprocess": data => data[0].value},
130
156
  {"name": "keywords", "symbols": [(lexer.has("examples") ? {type: "examples"} : examples)], "postprocess": data => data[0].value},
package/src/steps.js CHANGED
@@ -4,6 +4,12 @@ import { log } from './logger.js';
4
4
 
5
5
  var steps = [];
6
6
 
7
+ const typeName = {
8
+ given : 'Given',
9
+ then : 'Then',
10
+ when : 'When',
11
+ };
12
+
7
13
  const expressionFactory = new ExpressionFactory(new ParameterTypeRegistry());
8
14
 
9
15
  export const addStepDefinition = (expression,f) => {
@@ -31,7 +37,14 @@ export const findStepDefinitionMatch = (step) => {
31
37
  const stepDefinitionMatches = findStepDefinitionMatches(step);
32
38
 
33
39
  if (!stepDefinitionMatches || (stepDefinitionMatches.length == 0)) {
34
- throw new Error('Step not defined: \''+step.type.name+' '+step.text+'\'');
40
+ throw new Error(`Undefined. Implement with the following snippet:
41
+
42
+ ${typeName[step.type.type]}('${step.text}', (state,params,data) => {
43
+ // Write code here that turns the phrase above into concrete actions
44
+ throw new Error('Not yet implemented!');
45
+ return state;
46
+ });
47
+ `);
35
48
  }
36
49
 
37
50
  if (stepDefinitionMatches.length > 1) {
@@ -1,9 +1,13 @@
1
1
  import { defineConfig } from 'vitest/config'
2
2
  import vitestCucumberPlugin from 'vitest-cucumber-plugin';
3
3
 
4
- export default defineConfig({
5
- plugins: [vitestCucumberPlugin()],
6
- test: {
7
- include : [ '**/*.feature' ],
8
- },
9
- })
4
+ export default defineConfig(({ mode }) => {
5
+ const level = (mode === 'test-debug') ? 'debug' : 'warn';
6
+ return {
7
+ plugins: [vitestCucumberPlugin()],
8
+ test: {
9
+ include : [ '**/*.feature' ],
10
+ cucumber : { log : { level } },
11
+ },
12
+ }
13
+ });