Skip to content

Commit

Permalink
Update functionalities with refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPorzuczek committed Dec 7, 2023
1 parent 2e5c0b5 commit 1da166e
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ dist
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
npm-debug.log*

# Runtime data
pids
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"problemMatcher": "$tsc-watch",
"presentation": {
"reveal": "never"
},
Expand Down
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
node_modules
**/*.ts
out/
src/
tsconfig.json
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Piotr Porzuczek
Copyright (c) 2022 Porzuczek Piotr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 time 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)

Expand All @@ -28,9 +28,15 @@ The plugin allows you to generate code from a file with the extension `.feature`
> Tip: It is important to do it in the file with `.feature` extension.
>
> Command is also available through command pallette.
>

# Join Our Community

[![Stargazers repo roster for @PeterPorzuczek/jest-cucumber-code-generator-extension](https://reporoster.com/stars/PeterPorzuczek/jest-cucumber-code-generator-extension)](https://github.com/PeterPorzuczek/jest-cucumber-code-generator-extension/stargazers)

#### Credits

##### Icon author:
<div>Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>


2 changes: 1 addition & 1 deletion config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"activationEvents": [
"onCommand:extension.generateCodeFromFeature"
],
"icon": "icon.png",
"main": "./dist/extension",
"icon": "icon.png",
"contributes": {
"commands": [
{
Expand Down
20 changes: 10 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ function processDocument() {
selectionInformation: createSelectionLinesInformation(editor)
};
}
function createSelectionLinesInformation(editor) {
return {
text: editor.document.getText(
editor.selection
),
end: editor.selection.end.line + 1,
start: editor.selection.start.line + 1,
count: editor.document.lineCount
};
}
function putCommandsInClipboard(
documentText,
selectionInformation
Expand All @@ -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
)
};
}
36 changes: 18 additions & 18 deletions src/modules/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ 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) {
function wrapInDefinedFeature(commandsAsText) {
const commandsInDefineFeature = [
'defineFeature(feature, test => {',
commandsAsText,
Expand All @@ -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 = wrapInDefinedFeature(
commandsAsText).join(newLine);
}
);

return formatedJavascript;

return formatJavascript(commandsAsText);
}

export default {
Expand Down
40 changes: 20 additions & 20 deletions src/modules/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ function generateCommandsFromFeatureAsText(
);
}
}
function areScenariosPresentIn(feature) {
return feature.scenarios.length +
feature.scenarioOutlines.length > 0;
}
function generateCommands(
feature,
selectionInformation
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/typings/process.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "src",
"sourceMap": true,
"strict": false
},
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"curly": true,
"class-name": true,
"curly": true,
"semicolon": [
true,
"always"
Expand Down

0 comments on commit 1da166e

Please sign in to comment.