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 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
@@ -1,3 +1,4 @@
1
+ * v0.5.1 : Added info level logging for tracing state through steps. Also added a log file option.
1
2
  * v0.5.0 : Implemented Doc Strings. Plugin is now feature complete.
2
3
  * v0.1.8 : Implemented Rule keyword
3
4
  * v0.1.7 : Implemented Hooks API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-cucumber-plugin",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Plugin for Vitest which allows for tests to be written in Cucumber format.",
5
5
  "keywords": [
6
6
  "vite",
@@ -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, setLogLevel } from 'vitest-cucumber-plugin';
41
+ import { log, logConfig } from 'vitest-cucumber-plugin';
42
42
 
43
- setLogLevel('${config.logLevel}');
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.debug('applyHooks name: '+hook.name+' new state: '+JSON.stringify(state));
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, setLogLevel } from './logger.js';
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 { setLogLevel, log };
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, logLevel : 'warn' },_.get('test.cucumber',resolvedConfig))
70
- setLogLevel(config.logLevel);
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 const log = pino();
4
+ export var log = pino();
4
5
 
5
6
  log.level = 'warn';
6
7
 
7
- export const setLogLevel = (logLevel) => { log.level = logLevel };
8
+ export const logConfig = (config) => {
9
+ if (_.has('file',config)) {
10
+ log = pino(config,config.file);
11
+ } else {
12
+ log = pino(config);
13
+ }
14
+ };
@@ -4,6 +4,6 @@ import vitestCucumberPlugin from 'vitest-cucumber-plugin';
4
4
  export default defineConfig({
5
5
  plugins: [vitestCucumberPlugin()],
6
6
  test: {
7
- include : [ '**/*.feature' ]
7
+ include : [ '**/*.feature' ],
8
8
  },
9
9
  })
@@ -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') ? '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
- plugins: [vitestCucumberPlugin()],
6
- test: {
7
- include : [ '**/*.feature' ],
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
- plugins: [vitestCucumberPlugin()],
6
- test: {
7
- include : [ '**/*.feature' ],
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
- plugins: [vitestCucumberPlugin()],
6
- test: {
7
- include : [ '**/*.feature' ]
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
+ });