diff --git a/.gitignore b/.gitignore index 5e08964..68bf04c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,9 @@ dist # Logs logs *.log -npm-debug.log* yarn-debug.log* yarn-error.log* +npm-debug.log* # Runtime data pids diff --git a/.vscodeignore b/.vscodeignore index 76275cb..6a5853f 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -10,8 +10,8 @@ vsc-extension-quickstart.md **/tsconfig.json **/tslint.json **/*.map -**/*.ts node_modules +**/*.ts out/ src/ tsconfig.json diff --git a/LICENSE b/LICENSE index 8b303d1..25d217e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Piotr Porzuczek +Copyright (c) 2022 Piotr Porzuczek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ceb61e0..5bf078a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Jest-cucumber code generator for VS Code. This plugin allows you to generate tests that match those generated by [Jest-cucumber](https://github.com/bencompton/jest-cucumber) -The plug-in, which allows you to generate unit tests in Gherkin format, is an innovative way to approach unit tests. The technique is typically used for end-to-end testing, but by implementing it in unit tests, developers can get a more structured approach to their tests, which can speed up overall software development. Another benefit of using Gherkin for unit testing is that it can help ensure that all necessary test cases are included in tests. This is because a natural language, as opposed to a programming language, encourages a declarative writing style that helps make sure that all relevant details are included in each test case. This can save when a programmer is trying to track down why a particular test failed. Overall, using the Gherkin unit test generation plugin is an innovative way to improve the efficiency and effectiveness of unit tests. +Plugin allows you to generate unit tests in Gherkin format, is an innovative way to approach unit tests. The technique is typically used for end-to-end testing, but by implementing it in unit tests, developers can get a more structured approach to their tests, which can speed up overall software development. Another benefit of using Gherkin for unit testing is that it can help ensure that all necessary test cases are included in tests. This is because a natural language, as opposed to a programming language, encourages a declarative writing style that helps make sure that all relevant details are included in each test case. This can save when a programmer is trying to track down why a particular test failed. Overall, using the Gherkin unit test generation plugin is an innovative way to improve the efficiency and effectiveness of unit tests. [Install from marketplace](https://marketplace.visualstudio.com/items?itemName=Piotr-Porzuczek.jest-cucumber-code-generator-extension) diff --git a/config/webpack/webpack.config.js b/config/webpack/webpack.config.js index c607f36..6c383cc 100644 --- a/config/webpack/webpack.config.js +++ b/config/webpack/webpack.config.js @@ -10,8 +10,8 @@ const config = { entry: path.resolve(__dirname, '../../', './src/extension.ts'), output: { path: path.resolve(__dirname, '../../', 'dist'), - filename: 'extension.js', libraryTarget: 'commonjs2', + filename: 'extension.js', devtoolModuleFilenameTemplate: '../[resource-path]' }, devtool: 'source-map', diff --git a/package-lock.json b/package-lock.json index 00f8424..eaef842 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2394,7 +2394,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2412,11 +2413,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2429,15 +2432,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2540,7 +2546,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2550,6 +2557,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2562,17 +2570,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2589,6 +2600,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2661,7 +2673,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2671,6 +2684,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2746,7 +2760,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2776,6 +2791,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2793,6 +2809,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2831,11 +2848,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -6697,9 +6716,9 @@ } }, "ws": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", - "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", + "integrity": "sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==", "requires": { "async-limiter": "~1.0.0" } diff --git a/package.json b/package.json index 2e152e3..59ea27b 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "activationEvents": [ "onCommand:extension.generateCodeFromFeature" ], - "icon": "icon.png", "main": "./dist/extension", + "icon": "icon.png", "contributes": { "commands": [ { diff --git a/src/extension.ts b/src/extension.ts index 74222bd..c35cf41 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -38,6 +38,16 @@ function processDocument() { selectionInformation: createSelectionLinesInformation(editor) }; } +function createSelectionLinesInformation(editor) { + return { + count: editor.document.lineCount, + start: editor.selection.start.line + 1, + end: editor.selection.end.line + 1, + text: editor.document.getText( + editor.selection + ) + }; +} function putCommandsInClipboard( documentText, selectionInformation @@ -53,14 +63,4 @@ function putCommandsInClipboard( } function handleError(error) { vscode.window.showErrorMessage(error.message); -} -function createSelectionLinesInformation(editor) { - return { - count: editor.document.lineCount, - start: editor.selection.start.line + 1, - end: editor.selection.end.line + 1, - text: editor.document.getText( - editor.selection - ) - }; } \ No newline at end of file diff --git a/src/modules/formatter.ts b/src/modules/formatter.ts index 3d4b34c..85107ef 100644 --- a/src/modules/formatter.ts +++ b/src/modules/formatter.ts @@ -2,15 +2,16 @@ import { js } from 'js-beautify'; -function format(commands, wrap) { - const newLine = '\r\n'; - let commandsAsText = commands.join(newLine); - if (wrap) { - commandsAsText = wrapInDefineFeature( - commandsAsText).join(newLine); +function formatJavascript(commands) { + const formatedJavascript = js( + commands, + { + indent_size: 2, + space_in_empty_parent: true } - - return formatJavascript(commandsAsText); + ); + + return formatedJavascript; } function wrapInDefineFeature(commandsAsText) { const commandsInDefineFeature = [ @@ -21,16 +22,15 @@ function wrapInDefineFeature(commandsAsText) { return commandsInDefineFeature; } -function formatJavascript(commands) { - const formatedJavascript = js( - commands, - { - indent_size: 2, - space_in_empty_parent: true +function format(commands, wrap) { + const newLine = '\r\n'; + let commandsAsText = commands.join(newLine); + if (wrap) { + commandsAsText = wrapInDefineFeature( + commandsAsText).join(newLine); } - ); - - return formatedJavascript; + + return formatJavascript(commandsAsText); } export default { diff --git a/src/modules/generator.ts b/src/modules/generator.ts index 17e9e34..cfa400c 100644 --- a/src/modules/generator.ts +++ b/src/modules/generator.ts @@ -18,10 +18,6 @@ function generateCommandsFromFeatureAsText( ); } } -function areScenariosPresentIn(feature) { - return feature.scenarios.length + - feature.scenarioOutlines.length > 0; -} function generateCommands( feature, selectionInformation @@ -44,16 +40,20 @@ function generateCommands( ); } } -function isFeatureIn(selectionInformation) { - return selectionInformation.start === 1; +function areScenariosPresentIn(feature) { + return feature.scenarios.length + + feature.scenarioOutlines.length > 0; +} +function isStepIn(selectionInformation) { + return !selectionInformation.text + .toLowerCase().includes('scenario:'); } function isScenarioIn(selectionInformation) { return selectionInformation.text .toLowerCase().includes('scenario:'); } -function isStepIn(selectionInformation) { - return !selectionInformation.text - .toLowerCase().includes('scenario:'); +function isFeatureIn(selectionInformation) { + return selectionInformation.start === 1; } function generateFeatureCommands( feature @@ -98,17 +98,6 @@ function filterScenariosFrom( lineNumber <= end; }); } -function generateCommandsFrom(feature) { - return feature.scenarios - .concat(feature.scenarioOutlines) - .sort((a, b) => - Math.sign(a.lineNumber - b.lineNumber)) - .map(scenario => - generateCodeFromFeature( - feature, - scenario.lineNumber - )); -} function generateStepsCommands( feature, selectionInformation @@ -128,6 +117,17 @@ function generateStepsCommands( false ); } +function generateCommandsFrom(feature) { + return feature.scenarios + .concat(feature.scenarioOutlines) + .sort((a, b) => + Math.sign(a.lineNumber - b.lineNumber)) + .map(scenario => + generateCodeFromFeature( + feature, + scenario.lineNumber + )); +} export default { generateCommandsFromFeatureAsText diff --git a/src/utilities/typings/process.d.ts b/src/utilities/typings/process.d.ts index b9c2733..acd0e86 100644 --- a/src/utilities/typings/process.d.ts +++ b/src/utilities/typings/process.d.ts @@ -1,11 +1,11 @@ declare namespace NodeJS { - export interface Process { + export interface Global { vscode?: any } - export interface ProcessEnv { + export interface Process { vscode?: any } - export interface Global { + export interface ProcessEnv { vscode?: any } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index cad093c..d22d1cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,8 +6,8 @@ "lib": [ "es6" ], - "sourceMap": true, "rootDir": "src", + "sourceMap": true, "strict": false }, "exclude": [