vitest-cucumber-plugin 0.5.0 → 0.5.1
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 +8 -1
- package/RELEASE_NOTES.md +1 -0
- package/package.json +1 -1
- package/src/generate/feature.js +2 -2
- package/src/hooks.js +13 -1
- package/src/index.js +8 -4
- package/src/logger.js +9 -2
- package/tests/comments/vite.config.js +1 -1
- package/tests/data-tables/vite.config.js +10 -6
- package/tests/doc-strings/vite.config.js +10 -6
- package/tests/hooks/vite.config.js +10 -6
- package/tests/is-it-friday/vite.config.js +10 -6
package/README.md
CHANGED
|
@@ -24,12 +24,19 @@ export default defineConfig({
|
|
|
24
24
|
test: {
|
|
25
25
|
include : [ '**/*.feature' ],
|
|
26
26
|
cucumber : {
|
|
27
|
-
tags : "<tags boolean expression>"
|
|
27
|
+
tags : "<tags boolean expression>", // Use this to filter the test via boolean tags expression
|
|
28
|
+
log : {
|
|
29
|
+
level : "<'fatal', 'error', 'warn', 'info', 'debug', 'trace' or 'silent'>",
|
|
30
|
+
file : "<log path>", // Write the logs to a file instead of stdio (the default)
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
})
|
|
31
35
|
```
|
|
32
36
|
|
|
37
|
+
Setting the log level to 'info' will cause the plugin to generate logs useful for tracking the state through
|
|
38
|
+
the steps. You can pipe the logs through pino-pretty to make them more human readable.
|
|
39
|
+
|
|
33
40
|
### Writing tests
|
|
34
41
|
|
|
35
42
|
Put feature files into the 'features/' directory and step definitions into the 'features/step_definitions/' directory.
|
package/RELEASE_NOTES.md
CHANGED
package/package.json
CHANGED
package/src/generate/feature.js
CHANGED
|
@@ -38,9 +38,9 @@ import {
|
|
|
38
38
|
applyAfterStepHooks,
|
|
39
39
|
} from 'vitest-cucumber-plugin';
|
|
40
40
|
import { readdir } from 'node:fs/promises';
|
|
41
|
-
import { log,
|
|
41
|
+
import { log, logConfig } from 'vitest-cucumber-plugin';
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
logConfig(${JSON.stringify(config.log)});
|
|
44
44
|
|
|
45
45
|
const importDirectory = async (directory) => {
|
|
46
46
|
log.debug('importDirectory directory: '+directory);
|
package/src/hooks.js
CHANGED
|
@@ -11,6 +11,16 @@ const allHooks = {
|
|
|
11
11
|
afterStep : [],
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const hookNames = {
|
|
15
|
+
beforeAll : 'BeforeAll',
|
|
16
|
+
before : 'Before',
|
|
17
|
+
beforeStep : 'BeforeStep',
|
|
18
|
+
afterAll : 'AfterAll',
|
|
19
|
+
after : 'After',
|
|
20
|
+
afterStep : 'AfterStep',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
14
24
|
const applyHooks = async (hooksName,state,tags) => {
|
|
15
25
|
const hooks = allHooks[hooksName];
|
|
16
26
|
log.debug('applyHooks: '+hooksName+' state: '+JSON.stringify(state));
|
|
@@ -23,8 +33,10 @@ const applyHooks = async (hooksName,state,tags) => {
|
|
|
23
33
|
|
|
24
34
|
log.debug('applyHooks match? '+result+' tags: '+JSON.stringify(tags));
|
|
25
35
|
if (result) {
|
|
36
|
+
const origState = state;
|
|
26
37
|
state = await hook.f(state);
|
|
27
|
-
log.
|
|
38
|
+
log.info(hookNames[hooksName]+'(\''+hook.name+'\') ('+JSON.stringify(origState)+') => '+
|
|
39
|
+
JSON.stringify(state));
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
return state;
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _ from 'lodash/fp.js';
|
|
|
2
2
|
import { addStepDefinition, findStepDefinitionMatch } from './steps.js';
|
|
3
3
|
import { parameterizeText } from './parameterize.js';
|
|
4
4
|
import { generateFeature } from './generate/index.js';
|
|
5
|
-
import { log,
|
|
5
|
+
import { log, logConfig } from './logger.js';
|
|
6
6
|
import { parse } from './parse.js';
|
|
7
7
|
import { tagsFunction } from './tags.js';
|
|
8
8
|
import {
|
|
@@ -35,7 +35,7 @@ export {
|
|
|
35
35
|
applyAfterStepHooks,
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export { log, logConfig };
|
|
39
39
|
|
|
40
40
|
export const Given = addStepDefinition;
|
|
41
41
|
export const When = addStepDefinition;
|
|
@@ -48,6 +48,9 @@ export const Test = (state,step) => {
|
|
|
48
48
|
const extraData = step.dataTable ? step.dataTable : (step.docString ? step.docString.text : null );
|
|
49
49
|
|
|
50
50
|
const newState = stepDefinitionMatch.stepDefinition.f(state,stepDefinitionMatch.parameters,extraData);
|
|
51
|
+
log.info(step.type.name+'(\''+stepDefinitionMatch.stepDefinition.expression+'\') ('+
|
|
52
|
+
JSON.stringify(state)+','+JSON.stringify(stepDefinitionMatch.parameters)+','+JSON.stringify(extraData)+
|
|
53
|
+
') => '+JSON.stringify(newState));
|
|
51
54
|
log.debug('Test newState: '+JSON.stringify(newState));
|
|
52
55
|
|
|
53
56
|
return newState;
|
|
@@ -66,8 +69,9 @@ export default function vitestCucumberPlugin() {
|
|
|
66
69
|
return {
|
|
67
70
|
name : 'vitest-cucumber-transform',
|
|
68
71
|
configResolved : (resolvedConfig) => {
|
|
69
|
-
config = _.defaults({ root : resolvedConfig.root,
|
|
70
|
-
|
|
72
|
+
config = _.defaults({ root : resolvedConfig.root, log : { level : 'warn' } },
|
|
73
|
+
_.get('test.cucumber',resolvedConfig))
|
|
74
|
+
logConfig(config.log);
|
|
71
75
|
|
|
72
76
|
config = _.set('tagsFunction',tagsFunction(_.get('tags',config)),config);
|
|
73
77
|
|
package/src/logger.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import _ from 'lodash/fp.js';
|
|
1
2
|
import pino from 'pino';
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
+
export var log = pino();
|
|
4
5
|
|
|
5
6
|
log.level = 'warn';
|
|
6
7
|
|
|
7
|
-
export const
|
|
8
|
+
export const logConfig = (config) => {
|
|
9
|
+
if (_.has('file',config)) {
|
|
10
|
+
log = pino(config,config.file);
|
|
11
|
+
} else {
|
|
12
|
+
log = pino(config);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export default defineConfig(({ mode }) => {
|
|
5
|
+
const level = (mode === 'test-debug') ? 'info' : 'warn';
|
|
6
|
+
return {
|
|
7
|
+
plugins: [vitestCucumberPlugin()],
|
|
8
|
+
test: {
|
|
9
|
+
include : [ '**/*.feature' ],
|
|
10
|
+
cucumber : { log : { level } },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export default defineConfig(({ mode }) => {
|
|
5
|
+
const logLevel = (mode === 'test-debug') ? 'info' : 'warn';
|
|
6
|
+
return {
|
|
7
|
+
plugins: [vitestCucumberPlugin()],
|
|
8
|
+
test: {
|
|
9
|
+
include : [ '**/*.feature' ],
|
|
10
|
+
cucumber : { logLevel },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export default defineConfig(({ mode }) => {
|
|
5
|
+
const level = (mode === 'test-debug') ? 'info' : 'warn';
|
|
6
|
+
return {
|
|
7
|
+
plugins: [vitestCucumberPlugin()],
|
|
8
|
+
test: {
|
|
9
|
+
include : [ '**/*.feature' ],
|
|
10
|
+
cucumber : { log : { level } },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export default defineConfig(({ mode }) => {
|
|
5
|
+
const level = (mode === 'test-debug') ? 'info' : 'warn';
|
|
6
|
+
return {
|
|
7
|
+
plugins: [vitestCucumberPlugin()],
|
|
8
|
+
test: {
|
|
9
|
+
include : [ '**/*.feature' ],
|
|
10
|
+
cucumber : { log : { level } },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
});
|