vitest-cucumber-plugin 0.1.6 → 0.1.7
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 +9 -5
- package/RELEASE_NOTES.md +1 -0
- package/package.json +1 -1
- package/src/generate/example.js +1 -1
- package/src/generate/examples.js +3 -3
- package/src/generate/feature.js +43 -9
- package/src/generate/tests.js +7 -2
- package/src/hooks.js +66 -0
- package/src/index.js +23 -6
- package/tests/background/features/support/hooks.js +3 -0
- package/tests/background/vite.config.js +1 -1
- package/tests/hooks/features/after-all.feature +5 -0
- package/tests/hooks/features/after.feature +5 -0
- package/tests/hooks/features/before-all.feature +14 -0
- package/tests/hooks/features/before-step.feature +6 -0
- package/tests/hooks/features/before.feature +14 -0
- package/tests/hooks/features/step_definitions/steps.js +28 -0
- package/tests/hooks/features/support/hooks.js +75 -0
- package/tests/hooks/features/support/tags-hooks.js +11 -0
- package/tests/hooks/features/tags.feature +14 -0
- package/tests/hooks/package-lock.json +1204 -0
- package/tests/hooks/package.json +11 -0
- package/tests/hooks/vite.config.js +9 -0
- package/tests/keyword-aliases/features/support/hooks.js +6 -0
- package/tests/tags/features/support/hooks.js +6 -0
package/README.md
CHANGED
|
@@ -22,7 +22,10 @@ import vitestCucumberPlugin from 'vitest-cucumber-plugin';
|
|
|
22
22
|
export default defineConfig({
|
|
23
23
|
plugins: [vitestCucumberPlugin()],
|
|
24
24
|
test: {
|
|
25
|
-
include : [ '**/*.feature' ]
|
|
25
|
+
include : [ '**/*.feature' ],
|
|
26
|
+
cucumber : {
|
|
27
|
+
tags : "<tags boolean expression>"
|
|
28
|
+
}
|
|
26
29
|
},
|
|
27
30
|
})
|
|
28
31
|
```
|
|
@@ -46,8 +49,9 @@ there are a few differences in how step definitions are written.
|
|
|
46
49
|
|
|
47
50
|
The function signatures for Given, When and Then callbacks have been modified in order to make the step definitions
|
|
48
51
|
more friendly for functional programming. Specifically, the callback functions differ in that they
|
|
49
|
-
now have
|
|
50
|
-
|
|
52
|
+
now have three parameters. The first parameter is a state object which was returned by the previous step. The
|
|
53
|
+
second is an array of parameters values. The third is a data table or a doc string. The callback functions then
|
|
54
|
+
return a new state object which is passed to the next step definition in the chain.
|
|
51
55
|
|
|
52
56
|
For example, here is how you'd write step definitions in Cucumber:
|
|
53
57
|
```
|
|
@@ -70,7 +74,7 @@ When('I ask whether it\'s Friday yet', function () {
|
|
|
70
74
|
this.actualAnswer = isItFriday(this.today);
|
|
71
75
|
});
|
|
72
76
|
|
|
73
|
-
Then('I should be told {string}', function (expectedAnswer) {
|
|
77
|
+
Then('I should be told {string}', function (expectedAnswer, dataTable) {
|
|
74
78
|
assert.strictEqual(this.actualAnswer, expectedAnswer);
|
|
75
79
|
});
|
|
76
80
|
```
|
|
@@ -93,7 +97,7 @@ When('I ask whether it\'s Friday yet', function (state) {
|
|
|
93
97
|
return _.set('answer',(state.today === 'Friday') ? 'TGIF' : 'Nope',state);
|
|
94
98
|
});
|
|
95
99
|
|
|
96
|
-
Then('I should be told {string}', function (state,[ answer ]) {
|
|
100
|
+
Then('I should be told {string}', function (state,[ answer ], dataTable) {
|
|
97
101
|
expect(state.answer).toBe(answer);
|
|
98
102
|
});
|
|
99
103
|
```
|
package/RELEASE_NOTES.md
CHANGED
package/package.json
CHANGED
package/src/generate/example.js
CHANGED
|
@@ -9,7 +9,7 @@ export const generateExample = (config,example) => {
|
|
|
9
9
|
|
|
10
10
|
const steps = _.has('background.steps',example) ? _.concat(example.background.steps,example.steps) : example.steps;
|
|
11
11
|
|
|
12
|
-
tests += generateTests(steps);
|
|
12
|
+
tests += generateTests(steps,{},example.tags);
|
|
13
13
|
|
|
14
14
|
const skip = shouldSkip(config,example.tags) ? '.skip' : '';
|
|
15
15
|
|
package/src/generate/examples.js
CHANGED
|
@@ -14,12 +14,12 @@ const createParameterMap = (parameters,values) => {
|
|
|
14
14
|
return parameterMap.map;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const generateAllTests = (steps,parameters,parameterValues) => {
|
|
17
|
+
const generateAllTests = (steps,parameters,parameterValues,tags) => {
|
|
18
18
|
const allTests = _.reduce((allTests,values) => {
|
|
19
19
|
const parameterMap = createParameterMap(parameters,values);
|
|
20
20
|
log.debug('parameterMap : '+JSON.stringify(parameterMap));
|
|
21
21
|
|
|
22
|
-
const tests = generateTests(steps,parameterMap,' ');
|
|
22
|
+
const tests = generateTests(steps,parameterMap,tags,' ');
|
|
23
23
|
|
|
24
24
|
return { tests : allTests.tests + `
|
|
25
25
|
describe('${allTests.index}',() => {${tests}
|
|
@@ -40,7 +40,7 @@ export const generateExamples = (config,steps,examplesStatement) => {
|
|
|
40
40
|
|
|
41
41
|
const skip = shouldSkip(config,examplesStatement.tags) ? '.skip' : '';
|
|
42
42
|
|
|
43
|
-
const allTests = generateAllTests(steps,parameters,parameterValues);
|
|
43
|
+
const allTests = generateAllTests(steps,parameters,parameterValues,examplesStatement.tags);
|
|
44
44
|
const code = `
|
|
45
45
|
// tags : ${JSON.stringify(examplesStatement.tags)}
|
|
46
46
|
describe${skip}('${escape(examplesStatement.type.name)}: ${escape(examplesStatement.name)}', () => {${allTests}
|
package/src/generate/feature.js
CHANGED
|
@@ -23,23 +23,57 @@ export const generateFeature = (config,feature) => {
|
|
|
23
23
|
|
|
24
24
|
const skip = shouldSkip(config,feature.tags) ? '.skip' : '';
|
|
25
25
|
const configStr = JSON.stringify(config);
|
|
26
|
+
const tagsStr = JSON.stringify(feature.tags);
|
|
26
27
|
|
|
27
|
-
const code = `import { expect, test, describe } from 'vitest';
|
|
28
|
-
import {
|
|
28
|
+
const code = `import { expect, test, describe, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
|
|
29
|
+
import {
|
|
30
|
+
Test,
|
|
31
|
+
applyBeforeAllHooks,
|
|
32
|
+
applyBeforeHooks,
|
|
33
|
+
applyBeforeStepHooks,
|
|
34
|
+
applyAfterAllHooks,
|
|
35
|
+
applyAfterHooks,
|
|
36
|
+
applyAfterStepHooks,
|
|
37
|
+
} from 'vitest-cucumber-plugin';
|
|
29
38
|
import { readdir } from 'node:fs/promises';
|
|
39
|
+
import { log, setLogLevel } from 'vitest-cucumber-plugin';
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await
|
|
41
|
+
setLogLevel('${config.logLevel}');
|
|
42
|
+
|
|
43
|
+
const importDirectory = async (directory) => {
|
|
44
|
+
log.debug('importDirectory directory: '+directory);
|
|
45
|
+
try {
|
|
46
|
+
const files = await readdir(directory);
|
|
47
|
+
|
|
48
|
+
for (const file of files) {
|
|
49
|
+
const filename = directory+'/'+file;
|
|
50
|
+
log.debug('importDirectory import: '+filename);
|
|
51
|
+
await import(filename);
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
log.debug('importDirectory error: '+e);
|
|
37
55
|
}
|
|
38
56
|
};
|
|
39
57
|
|
|
58
|
+
const importSupportFiles = async (config) => importDirectory(config.root+'/features/support');
|
|
59
|
+
|
|
60
|
+
await importSupportFiles(${configStr});
|
|
61
|
+
|
|
62
|
+
const importStepDefinitions = async (config) => importDirectory(config.root+'/features/step_definitions');
|
|
63
|
+
|
|
40
64
|
await importStepDefinitions(${configStr});
|
|
41
65
|
|
|
42
|
-
|
|
66
|
+
var state = {};
|
|
67
|
+
|
|
68
|
+
beforeAll(async () => {
|
|
69
|
+
state = await applyBeforeAllHooks(state,${tagsStr});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterAll(async () => {
|
|
73
|
+
state = await applyAfterAllHooks(state,${tagsStr});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// tags : ${tagsStr}
|
|
43
77
|
describe${skip}('${escape(feature.type.name)}: ${escape(name)}', () => {
|
|
44
78
|
${testStatements}});
|
|
45
79
|
`;
|
package/src/generate/tests.js
CHANGED
|
@@ -3,11 +3,16 @@ import { escape } from './util.js';
|
|
|
3
3
|
import { parameterizeText } from '../parameterize.js';
|
|
4
4
|
import { log } from '../logger.js';
|
|
5
5
|
|
|
6
|
-
export const generateTests = (steps,parameterMap,extraIndent) => {
|
|
6
|
+
export const generateTests = (steps,parameterMap,tags,extraIndent) => {
|
|
7
7
|
log.debug('generateTests steps : '+JSON.stringify(steps));
|
|
8
|
+
const tagsStr = JSON.stringify(tags);
|
|
8
9
|
const indent = extraIndent ? extraIndent : '';
|
|
9
10
|
let tests = `
|
|
10
|
-
${indent}
|
|
11
|
+
${indent} beforeAll(async () => { state = await applyBeforeHooks(state,${tagsStr}); });
|
|
12
|
+
${indent} beforeEach(async () => { state = await applyBeforeStepHooks(state,${tagsStr}); });
|
|
13
|
+
${indent} afterAll(async () => { state = await applyAfterHooks(state,${tagsStr}); });
|
|
14
|
+
${indent} afterEach(async () => { state = await applyAfterStepHooks(state,${tagsStr}); });
|
|
15
|
+
`;
|
|
11
16
|
|
|
12
17
|
_.forEach((step) => {
|
|
13
18
|
const parameterizedText = ( parameterMap ? parameterizeText(step.text,parameterMap) : step.text);
|
package/src/hooks.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { log } from './logger.js';
|
|
2
|
+
import _ from 'lodash/fp.js';
|
|
3
|
+
import { tagsFunction } from './tags.js';
|
|
4
|
+
|
|
5
|
+
const allHooks = {
|
|
6
|
+
beforeAll : [],
|
|
7
|
+
before : [],
|
|
8
|
+
beforeStep : [],
|
|
9
|
+
afterAll : [],
|
|
10
|
+
after : [],
|
|
11
|
+
afterStep : [],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const applyHooks = async (hooksName,state,tags) => {
|
|
15
|
+
const hooks = allHooks[hooksName];
|
|
16
|
+
log.debug('applyHooks: '+hooksName+' state: '+JSON.stringify(state));
|
|
17
|
+
for (let i = 0; i < hooks.length; i++) {
|
|
18
|
+
let hook = hooks[i];
|
|
19
|
+
|
|
20
|
+
log.debug('applyHooks name: '+hook.name+' state: '+JSON.stringify(state));
|
|
21
|
+
|
|
22
|
+
const result = hook.tagsFunction(tags);
|
|
23
|
+
|
|
24
|
+
log.debug('applyHooks match? '+result+' tags: '+JSON.stringify(tags));
|
|
25
|
+
if (result) {
|
|
26
|
+
state = await hook.f(state);
|
|
27
|
+
log.debug('applyHooks name: '+hook.name+' new state: '+JSON.stringify(state));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return state;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const addHook = (hooksName,opts,f) => {
|
|
34
|
+
if (_.isFunction(opts)) {
|
|
35
|
+
opts = { name : '', f : opts };
|
|
36
|
+
} else if (_.isString(opts)) {
|
|
37
|
+
opts = { name : opts, f };
|
|
38
|
+
} else if (_.isObject(opts)) {
|
|
39
|
+
opts.f = f;
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error('Unknown options argument: '+JSON.stringify(opts));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
opts = _.set('tagsFunction',tagsFunction(opts.tags),opts);
|
|
45
|
+
|
|
46
|
+
log.debug('addHook hooksName: '+hooksName+' name: '+opts.name);
|
|
47
|
+
allHooks[hooksName] = _.concat(allHooks[hooksName],opts);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const BeforeAll = (opts,f) => { addHook('beforeAll',opts,f) };
|
|
51
|
+
export const applyBeforeAllHooks = (state,tags) => applyHooks('beforeAll',state,tags);
|
|
52
|
+
|
|
53
|
+
export const Before = (opts,f) => { addHook('before',opts,f) };
|
|
54
|
+
export const applyBeforeHooks = (state,tags) => applyHooks('before',state,tags);
|
|
55
|
+
|
|
56
|
+
export const BeforeStep = (opts,f) => { addHook('beforeStep',opts,f) };
|
|
57
|
+
export const applyBeforeStepHooks = (state,tags) => applyHooks('beforeStep',state,tags);
|
|
58
|
+
|
|
59
|
+
export const AfterAll = (opts,f) => { addHook('afterAll',opts,f) };
|
|
60
|
+
export const applyAfterAllHooks = (state,tags) => applyHooks('afterAll',state,tags);
|
|
61
|
+
|
|
62
|
+
export const After = (opts,f) => { addHook('after',opts,f) };
|
|
63
|
+
export const applyAfterHooks = (state,tags) => applyHooks('after',state,tags);
|
|
64
|
+
|
|
65
|
+
export const AfterStep = (opts,f) => { addHook('afterStep',opts,f) };
|
|
66
|
+
export const applyAfterStepHooks = (state,tags) => applyHooks('afterStep',state,tags);
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,14 @@ import { generateFeature } from './generate/index.js';
|
|
|
5
5
|
import { log, setLogLevel } from './logger.js';
|
|
6
6
|
import { parse } from './parse.js';
|
|
7
7
|
import { tagsFunction } from './tags.js';
|
|
8
|
+
import {
|
|
9
|
+
BeforeAll, applyBeforeAllHooks,
|
|
10
|
+
Before, applyBeforeHooks,
|
|
11
|
+
AfterAll, applyAfterAllHooks,
|
|
12
|
+
After, applyAfterHooks,
|
|
13
|
+
BeforeStep, applyBeforeStepHooks,
|
|
14
|
+
AfterStep, applyAfterStepHooks,
|
|
15
|
+
} from './hooks.js';
|
|
8
16
|
|
|
9
17
|
const featureRegex = /\.feature$/;
|
|
10
18
|
|
|
@@ -16,6 +24,19 @@ const compileFeatureToJS = (config,featureSrc) => {
|
|
|
16
24
|
return code;
|
|
17
25
|
}
|
|
18
26
|
|
|
27
|
+
export { BeforeAll, Before, AfterAll, After, BeforeStep, AfterStep };
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
applyBeforeAllHooks,
|
|
31
|
+
applyBeforeHooks,
|
|
32
|
+
applyAfterAllHooks,
|
|
33
|
+
applyAfterHooks,
|
|
34
|
+
applyBeforeStepHooks,
|
|
35
|
+
applyAfterStepHooks,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { setLogLevel, log };
|
|
39
|
+
|
|
19
40
|
export const Given = addStepDefinition;
|
|
20
41
|
export const When = addStepDefinition;
|
|
21
42
|
export const Then = addStepDefinition;
|
|
@@ -43,12 +64,8 @@ export default function vitestCucumberPlugin() {
|
|
|
43
64
|
return {
|
|
44
65
|
name : 'vitest-cucumber-transform',
|
|
45
66
|
configResolved : (resolvedConfig) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
config = _.get('test.cucumber',resolvedConfig);
|
|
51
|
-
config = _.set('root',resolvedConfig.root,config);
|
|
67
|
+
config = _.defaults({ root : resolvedConfig.root, logLevel : 'warn' },_.get('test.cucumber',resolvedConfig))
|
|
68
|
+
setLogLevel(config.logLevel);
|
|
52
69
|
|
|
53
70
|
config = _.set('tagsFunction',tagsFunction(_.get('tags',config)),config);
|
|
54
71
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Feature: BeforeAll hooks
|
|
2
|
+
Scenario: BeforeAll hooks are run once
|
|
3
|
+
Given nothing
|
|
4
|
+
When nothing happens
|
|
5
|
+
Then the "beforeAll" property is an array with the values:
|
|
6
|
+
| beforeAll1 |
|
|
7
|
+
| beforeAll2 |
|
|
8
|
+
|
|
9
|
+
Scenario: BeforeAll hooks should be the same this time
|
|
10
|
+
Given nothing
|
|
11
|
+
When nothing happens
|
|
12
|
+
Then the "beforeAll" property is an array with the values:
|
|
13
|
+
| beforeAll1 |
|
|
14
|
+
| beforeAll2 |
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Feature: Before hooks
|
|
2
|
+
Scenario: The Before hooks should have been run
|
|
3
|
+
Given nothing
|
|
4
|
+
When nothing happens
|
|
5
|
+
Then the "before" property is an array with the values:
|
|
6
|
+
| before1 |
|
|
7
|
+
| before2 |
|
|
8
|
+
|
|
9
|
+
Scenario: The After hooks should have cleared out the before property
|
|
10
|
+
Given nothing
|
|
11
|
+
When nothing happens
|
|
12
|
+
Then the "before" property is an array with the values:
|
|
13
|
+
| before1 |
|
|
14
|
+
| before2 |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Given, When, Then, DataTable } from 'vitest-cucumber-plugin';
|
|
2
|
+
import { expect } from 'vitest'
|
|
3
|
+
import _ from 'lodash/fp';
|
|
4
|
+
|
|
5
|
+
Given('nothing',(state) => state);
|
|
6
|
+
Then('nothing happens',(state) => state);
|
|
7
|
+
When('the {string} property is an array with the values:',(state,[ propertyName ],dataTable) => {
|
|
8
|
+
const values = _.flatten(dataTable);
|
|
9
|
+
expect(state[propertyName]).toEqual(values);
|
|
10
|
+
return state;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
When('the {string} property is an array with the integer values:',(state,[ propertyName ],dataTable) => {
|
|
14
|
+
let values = _.flatten(dataTable);
|
|
15
|
+
values = _.map(parseInt)(values);
|
|
16
|
+
expect(state[propertyName]).toEqual(values);
|
|
17
|
+
return state;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
When('the {string} property does not exist',(state,[propertyName]) => {
|
|
21
|
+
expect(_.has('propertyName',state)).toBeFalsy();
|
|
22
|
+
return state;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
When('the {string} property is an empty array',(state,[ propertyName ]) => {
|
|
26
|
+
expect(state[propertyName]).toEqual([]);
|
|
27
|
+
return state;
|
|
28
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BeforeAll, AfterAll, Before, After, BeforeStep, AfterStep } from 'vitest-cucumber-plugin';
|
|
2
|
+
import _ from 'lodash/fp.js';
|
|
3
|
+
|
|
4
|
+
BeforeAll('add beforeAll1',(state) => {
|
|
5
|
+
return _.set('beforeAll',_.concat(_.getOr([],'beforeAll',state),'beforeAll1'),state);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
BeforeAll('add beforeAll2',(state) => {
|
|
9
|
+
return _.set('beforeAll',_.concat(_.getOr([],'beforeAll',state),'beforeAll2'),state);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
AfterAll('check that BeforeAll happened',(state) => {
|
|
13
|
+
if (!_.isEqual(state.beforeAll,['beforeAll1','beforeAll2'])) {
|
|
14
|
+
throw new Error('beforeAll is wrong!');
|
|
15
|
+
}
|
|
16
|
+
return state;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
AfterAll('add afterAll1',(state) => {
|
|
20
|
+
return _.set('afterAll',_.concat(_.getOr([],'afterAll',state),'afterAll1'),state);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
AfterAll('add afterAll2',(state) => {
|
|
24
|
+
return _.set('afterAll',_.concat(_.getOr([],'afterAll',state),'afterAll2'),state);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
AfterAll('check that AfterAll happened',(state) => {
|
|
28
|
+
if (!_.isEqual(state.afterAll,['afterAll1','afterAll2'])) {
|
|
29
|
+
throw new Error('afterAll is wrong!');
|
|
30
|
+
}
|
|
31
|
+
return state;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
Before('add before1',(state) => {
|
|
35
|
+
return _.set('before',_.concat(_.getOr([],'before',state),'before1'),state);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
Before('add before2',(state) => {
|
|
39
|
+
return _.set('before',_.concat(_.getOr([],'before',state),'before2'),state);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
After('check that Before happened',(state) => {
|
|
43
|
+
if (!_.isEqual(state.before,['before1','before2'])) {
|
|
44
|
+
throw new Error('before is wrong!');
|
|
45
|
+
}
|
|
46
|
+
return state;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
After('add after1',(state) => {
|
|
50
|
+
return _.set('after',_.concat(_.getOr([],'after',state),'after1'),state);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
After('add after2',(state) => {
|
|
54
|
+
return _.set('after',_.concat(_.getOr([],'after',state),'after2'),state);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
After('check that After happened',(state) => {
|
|
58
|
+
if (!_.isEqual(state.after,['after1','after2'])) {
|
|
59
|
+
throw new Error('after is wrong!');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
state = _.set('after',[],state);
|
|
63
|
+
state = _.set('before',[],state);
|
|
64
|
+
return state;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
BeforeStep('add index to beforeStep',(state) => {
|
|
68
|
+
const beforeStep = _.getOr([],'beforeStep',state);
|
|
69
|
+
return _.set('beforeStep',_.concat(beforeStep.length,beforeStep),state)
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
AfterStep('remove index from beforeStep',(state) => {
|
|
73
|
+
const beforeStep = _.getOr([],'beforeStep',state);
|
|
74
|
+
return _.set('beforeStep',_.tail(1,beforeStep),state)
|
|
75
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BeforeAll, AfterAll, Before, After, BeforeStep, AfterStep } from 'vitest-cucumber-plugin';
|
|
2
|
+
import _ from 'lodash/fp.js';
|
|
3
|
+
|
|
4
|
+
Before({ tags : '@hooks and not @nobefore', name: 'add before' },(state) => {
|
|
5
|
+
return _.set('beforeTags',_.concat(_.getOr([],'beforeTags',state),'beforeTags'),state);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
After({ tags : '@hooks', name : 'clear beforeTags' },(state) => {
|
|
9
|
+
state = _.set('beforeTags',[],state);
|
|
10
|
+
return state;
|
|
11
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@hooks
|
|
2
|
+
Feature: Hooks can be selectively used with tags
|
|
3
|
+
Scenario: The Before hooks should have been run
|
|
4
|
+
Given nothing
|
|
5
|
+
When nothing happens
|
|
6
|
+
Then the "beforeTags" property is an array with the values:
|
|
7
|
+
| beforeTags |
|
|
8
|
+
|
|
9
|
+
# Disable the Before hook for this Scenario
|
|
10
|
+
@nobefore
|
|
11
|
+
Scenario:
|
|
12
|
+
Given nothing
|
|
13
|
+
When nothing happens
|
|
14
|
+
Then the "beforeTags" property is an empty array
|