Skip to content

Commit

Permalink
Fixed settings types (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkrechik committed May 25, 2024
1 parent 1373457 commit c6123c1
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 58 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.1.0
* Extension updates:

* Development Tech Debt updates:
1. Corrected options default values, handling and typings.

## 3.0.1
* Fixed regression issue with non-English languages formatting

Expand All @@ -8,7 +14,7 @@
3. Improved table pipes formatting.
4. Added an icon for feature files.

* Development Tech Dept updates:
* Development Tech Debt updates:
1. Upgraded to the latest versions of all VSCode libraries, enhancing extension speed, security, and the development/debugging experience.
2. Upgraded to the latest version of TypeScript, making the application more error-resistant due to improved typings.
3. Transitioned from Chai+Mocha to Jest.
Expand Down
2 changes: 1 addition & 1 deletion gserver/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function findIndentation(line: string, settings: Settings) {
}

function findFormat(line: string, settings: Settings) {
const settingsFormatConf = settings.formatConfOverride || {};
const settingsFormatConf = settings.formatConfOverride;
const mergedConfig = Object
.entries(settingsFormatConf)
.reduce((acc, [key, value]) => {
Expand Down
14 changes: 1 addition & 13 deletions gserver/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,10 @@ function watchStepsFiles(settings: Settings) {
});
}

function getStepsArray(steps: BaseSettings['steps']) {
// Set empty array as steps if they were not provided
if (!steps) {
return [];
}
if (Array.isArray(steps)) {
return steps;
}
return [steps];
}

function getSettingsFromBase(baseSettings: BaseSettings) {
const settings: Settings = {
...baseSettings,
steps: getStepsArray(baseSettings.steps),
pages: baseSettings.pages || {},
steps: new Array<string>().concat(baseSettings.steps),
};
return settings;
}
Expand Down
2 changes: 1 addition & 1 deletion gserver/src/steps.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class StepsHandler {

handleCustomParameters(step: string): string {
const { customParameters } = this.settings;
if (!customParameters) {
if (!customParameters.length) {
return step;
}
customParameters.forEach((p: CustomParameter) => {
Expand Down
48 changes: 24 additions & 24 deletions gserver/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ export interface FormatConf {
}

export interface BaseSettings {
steps?: StepSettings,
pages?: PagesSettings,
syncfeatures?: boolean | string,
strictGherkinCompletion?: boolean,
strictGherkinValidation?: boolean,
smartSnippets?: boolean,
stepsInvariants?: boolean,
customParameters?: CustomParameter[],
skipDocStringsFormat?: boolean,
formatConfOverride?: FormatConf,
onTypeFormat?: boolean,
customParameters: CustomParameter[],
formatConfOverride: FormatConf,
gherkinDefinitionPart?: string,
onTypeFormat: boolean,
pages: PagesSettings,
pureTextSteps: boolean
skipDocStringsFormat: boolean,
smartSnippets: boolean,
stepRegExSymbol?: string
pureTextSteps?: boolean
steps: string | string[],
stepsInvariants: boolean,
strictGherkinCompletion: boolean,
strictGherkinValidation: boolean,
syncfeatures: boolean | string,
}

export interface Settings {
steps: StepSettings,
pages: PagesSettings,
syncfeatures?: boolean | string,
strictGherkinCompletion?: boolean,
strictGherkinValidation?: boolean,
smartSnippets?: boolean,
stepsInvariants?: boolean,
customParameters?: CustomParameter[],
skipDocStringsFormat?: boolean,
formatConfOverride?: FormatConf,
onTypeFormat?: boolean,
customParameters: CustomParameter[],
formatConfOverride: FormatConf,
gherkinDefinitionPart?: string,
onTypeFormat: boolean,
pages: PagesSettings,
pureTextSteps: boolean
skipDocStringsFormat: boolean,
smartSnippets: boolean,
stepRegExSymbol?: string
pureTextSteps?: boolean
steps: StepSettings,
stepsInvariants: boolean,
strictGherkinCompletion: boolean,
strictGherkinValidation: boolean,
syncfeatures: boolean | string,
}
4 changes: 2 additions & 2 deletions gserver/test/cucumberExpressions.steps.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//https://github.com/cucumber/cucumber-expressions

import StepsHandler from '../src/steps.handler';
import { defaultSettings } from './data/defaultSettings';

const settings = {
pages: {},
...defaultSettings,
steps: ['/data/steps/cucumberExpressions.steps.js'],
syncfeatures: '/data/features/cucumberExpressions.feature',
smartSnippets: true,
stepsInvariants: true,
strictGherkinCompletion: true,
customParameters: [],
};

const stepsDefinitionNum = 8;
Expand Down
18 changes: 18 additions & 0 deletions gserver/test/data/defaultSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// VSCode will assign some default values to the setitngs based on the package.json defaults
import { CustomParameter, PagesSettings } from '../../src/types';

// So, imitate this behaviour for the tests
export const defaultSettings = {
customParameters: new Array<CustomParameter>(),
formatConfOverride: {},
onTypeFormat: false,
pages: {} as PagesSettings,
pureTextSteps: false,
skipDocStringsFormat: false,
smartSnippets: false,
steps: new Array<string>(),
stepsInvariants: false,
strictGherkinCompletion: false,
strictGherkinValidation: false,
syncfeatures: 'test/features/*.feature',
}
10 changes: 4 additions & 6 deletions gserver/test/format.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { format, clearText } from '../src/format';
import { Settings } from '../src/types';
import { getFileContent } from '../src/util';
import { defaultSettings } from './data/defaultSettings';

const generalSettings: Settings = {
steps: [],
pages: {},
const generalSettings = {
...defaultSettings,
skipDocStringsFormat: true,
formatConfOverride: {
But: 3,
Expand All @@ -19,8 +18,7 @@ const generalSettings: Settings = {
};

const ruleSettings = {
steps: [],
pages: {},
...defaultSettings,
};

describe('format', () => {
Expand Down
3 changes: 2 additions & 1 deletion gserver/test/pages.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import PagesHandler from '../src/pages.handler';
import { defaultSettings } from './data/defaultSettings';

const settings = {
steps: [],
...defaultSettings,
pages: {
page: '/data/page.objects.js',
page2: '/data/*.java',
Expand Down
6 changes: 3 additions & 3 deletions gserver/test/steps.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import StepsHandler from '../src/steps.handler';
import { GherkinType } from '../src/gherkin';
import { getFileContent } from '../src/util';
import { defaultSettings } from './data/defaultSettings';

const settings = {
...defaultSettings,
steps: ['/data/steps/test.steps*.js'],
pages: {},
syncfeatures: '/data/features/test.feature',
smartSnippets: true,
stepsInvariants: true,
Expand Down Expand Up @@ -277,9 +278,8 @@ describe('validateConfiguration', () => {

describe('Documentation parser', () => {
const sDocumentation = new StepsHandler(__dirname, {
...defaultSettings,
steps: ['/data/steps/test.documentation*.js'],
pages: {},
customParameters: [],
});

it('should extract JSDOC properties when available', () => {
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@
"array",
"string"
],
"required": false
"required": false,
"default": []
},
"cucumberautocomplete.pages": {
"description": "Object, which consists of 'page name' => 'page object file path' pairs",
"type": "object",
"required": false
"required": false,
"default": {}
},
"cucumberautocomplete.syncfeatures": {
"description": "Will get steps using count from glob-style path or from '**/*.feature' if true",
Expand Down Expand Up @@ -148,14 +150,12 @@
"cucumberautocomplete.gherkinDefinitionPart": {
"description": "Provide step definition name part of regex(ex. '@(given|when|then|step)\\(' in case of python-like steps. Please ensure, that they are placed in regex match '()' braces",
"type": "string",
"required": false,
"default": false
"required": false
},
"cucumberautocomplete.stepRegExSymbol": {
"description": "Provide step regex symbol. Ex. it would be \"'\" for When('I do something') definition",
"type": "string",
"required": false,
"default": false
"required": false
},
"cucumberautocomplete.pureTextSteps": {
"description": "Using steps definitions as a text strings with custom cucumber expressions support",
Expand All @@ -173,7 +173,9 @@
"lint": "eslint ./gclient/src ./gserver/src --ext .ts,.tsx",
"lint:fix": "eslint ./gclient/src ./gserver/src --ext .ts,.tsx --fix",
"postinstall": "cd gclient && npm install && cd ../gserver && npm install && cd ..",
"vscode:prepublish": "npm run compile",
"publish": "vsce publish",
"login": "vsce login",
"test:server": "jest",
"test": "npm run test:server"
},
Expand Down

0 comments on commit c6123c1

Please sign in to comment.