vitest-cucumber-plugin 0.5.3 → 0.5.5

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,5 @@
1
+ * v0.5.5 : Changed dynamic import statements to static ones so that Vitest watch works correctly
2
+ * v0.5.4 : Added vue test
1
3
  * v0.5.3 : Provide code snippets when a step definition is not found
2
4
  * v0.5.2 : Throw an error if a step file import fails instead of logging it
3
5
  * v0.5.1 : Added info level logging for tracing state through steps. Also added a log file option.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-cucumber-plugin",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Plugin for Vitest which allows for tests to be written in Cucumber format.",
5
5
  "keywords": [
6
6
  "vite",
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@cucumber/cucumber-expressions": "^16.1.2",
23
+ "glob": "^10.2.2",
23
24
  "lodash": "^4.17.21",
24
25
  "moo": "^0.5.2",
25
26
  "nearley": "^2.20.1",
@@ -2,8 +2,11 @@ import _ from 'lodash/fp.js';
2
2
  import { log } from '../logger.js';
3
3
  import { generateExample, generateScenarioOutline, generateRule } from './index.js';
4
4
  import { escape, shouldSkip } from './util.js';
5
+ import { glob } from 'glob';
5
6
 
6
- export const generateFeature = (config,feature) => {
7
+ const findJsFiles = async () => glob('features/**/*.js');
8
+
9
+ export const generateFeature = async (config,feature) => {
7
10
  const name = feature.name;
8
11
  const statements = feature.statements;
9
12
 
@@ -27,6 +30,14 @@ export const generateFeature = (config,feature) => {
27
30
  const configStr = JSON.stringify(config);
28
31
  const tagsStr = JSON.stringify(feature.tags);
29
32
 
33
+ const jsFilesImportReducer = (imports,file) => {
34
+ file = file.slice('features/'.length);
35
+ return imports+`
36
+ import './${file}';`;
37
+ };
38
+ const jsFiles = await findJsFiles();
39
+ const jsFilesImport = _.reduce(jsFilesImportReducer,'',jsFiles);
40
+
30
41
  const code = `import { expect, test, describe, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
31
42
  import {
32
43
  Test,
@@ -38,36 +49,10 @@ import {
38
49
  applyAfterStepHooks,
39
50
  } from 'vitest-cucumber-plugin';
40
51
  import { readdir } from 'node:fs/promises';
41
- import { log, logConfig } from 'vitest-cucumber-plugin';
52
+ import { log, logConfig } from 'vitest-cucumber-plugin';${jsFilesImport}
42
53
 
43
54
  logConfig(${JSON.stringify(config.log)});
44
55
 
45
- const importDirectory = async (directory) => {
46
- log.debug('importDirectory directory: '+directory);
47
- try {
48
- const files = await readdir(directory);
49
-
50
- for (const file of files) {
51
- const filename = directory+'/'+file;
52
- log.debug('importDirectory import: '+filename);
53
- await import(filename);
54
- }
55
- } catch (e) {
56
- if (e.code === "ENOENT") {
57
- return;
58
- }
59
- throw e;
60
- }
61
- };
62
-
63
- const importSupportFiles = async (config) => importDirectory(config.root+'/features/support');
64
-
65
- await importSupportFiles(${configStr});
66
-
67
- const importStepDefinitions = async (config) => importDirectory(config.root+'/features/step_definitions');
68
-
69
- await importStepDefinitions(${configStr});
70
-
71
56
  var state = {};
72
57
 
73
58
  beforeAll(async () => {
package/src/index.js CHANGED
@@ -16,10 +16,10 @@ import {
16
16
 
17
17
  const featureRegex = /\.feature$/;
18
18
 
19
- const compileFeatureToJS = (config,featureSrc) => {
19
+ const compileFeatureToJS = async (config,featureSrc) => {
20
20
  const feature = parse(featureSrc);
21
21
 
22
- const code = generateFeature(config,feature);
22
+ const code = await generateFeature(config,feature);
23
23
 
24
24
  return code;
25
25
  }
@@ -79,7 +79,7 @@ export default function vitestCucumberPlugin() {
79
79
  },
80
80
  transform : async (src,id) => {
81
81
  if (featureRegex.test(id)) {
82
- const code = compileFeatureToJS(config,src);
82
+ const code = await compileFeatureToJS(config,src);
83
83
 
84
84
  log.debug('transform '+id+' -> '+code);
85
85
 
@@ -0,0 +1,25 @@
1
+ import { Given, When, Then } from 'vitest-cucumber-plugin';
2
+ import Test from '../../src/test.vue';
3
+ import { mount, get } from '../support/components.js';
4
+ import { expect } from 'vitest';
5
+ import _ from 'lodash/fp.js';
6
+
7
+ Given('I have a test component', (state,params,data) => {
8
+ return _.set('test',mount(Test),state);
9
+ });
10
+
11
+ When('I do nothing', (state,params,data) => state);
12
+
13
+ Then('the test component text is {string}', (state,[ text ],data) => {
14
+ const testComponent = get(state.test);
15
+ const textElement = testComponent.get('.text');
16
+ expect(textElement.text()).toBe(text);
17
+ return state;
18
+ });
19
+
20
+ When('I push the button', (state,params,data) => {
21
+ const testComponent = get(state.test);
22
+ const buttonElement = testComponent.get('button');
23
+ buttonElement.trigger('click');
24
+ return state;
25
+ });
@@ -0,0 +1,19 @@
1
+ import * as testUtils from '@vue/test-utils';
2
+ import { v4 as uuid } from 'uuid';
3
+ import _ from 'lodash/fp.js';
4
+
5
+ const components = {};
6
+
7
+ const mount = (vue,options) => {
8
+ const id = uuid();
9
+ const mountOptions = {};
10
+ components[id] = testUtils.mount(vue,mountOptions);
11
+ return { id, options };
12
+ };
13
+
14
+ const get = (component) => components[component.id];
15
+
16
+ export {
17
+ mount,
18
+ get,
19
+ };
@@ -0,0 +1,10 @@
1
+ Feature: Vue component tests example
2
+ Scenario: Initial state
3
+ Given I have a test component
4
+ When I do nothing
5
+ Then the test component text is "Hello World!"
6
+
7
+ Scenario: Button pressed
8
+ Given I have a test component
9
+ When I push the button
10
+ Then the test component text is "Button pressed!"