vitest-cucumber-plugin 0.5.4 → 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 +1 -0
- package/package.json +2 -1
- package/src/generate/feature.js +13 -28
- package/src/index.js +3 -3
- package/tests/vue/src/test.vue +1 -0
- package/tests/vue/vite.config.js +1 -1
package/RELEASE_NOTES.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-cucumber-plugin",
|
|
3
|
-
"version": "0.5.
|
|
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",
|
package/src/generate/feature.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
package/tests/vue/src/test.vue
CHANGED
package/tests/vue/vite.config.js
CHANGED
|
@@ -3,7 +3,7 @@ import vitestCucumberPlugin from 'vitest-cucumber-plugin';
|
|
|
3
3
|
import vue from '@vitejs/plugin-vue';
|
|
4
4
|
|
|
5
5
|
export default defineConfig(({ mode }) => {
|
|
6
|
-
const level = (mode === 'test-debug') ? '
|
|
6
|
+
const level = (mode === 'test-debug') ? 'debug' : 'warn';
|
|
7
7
|
return {
|
|
8
8
|
plugins: [vue(),vitestCucumberPlugin()],
|
|
9
9
|
test: {
|