diff --git a/package.json b/package.json index 5a8ed2c..89a11bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "httpyac-import", - "version": "0.4.0", + "version": "0.5.0", "description": "CLI to convert Postman collection to httpyac files", "homepage": "https://github.com/matthewturner/httpyac-import", "repository": { @@ -41,4 +41,4 @@ "ts-node": "^10.9.2", "typescript": "^5.5.4" } -} +} \ No newline at end of file diff --git a/src/RequestDefinitionBuilder.ts b/src/RequestDefinitionBuilder.ts index 66abd3e..809da02 100644 --- a/src/RequestDefinitionBuilder.ts +++ b/src/RequestDefinitionBuilder.ts @@ -4,21 +4,25 @@ export class RequestDefinitionBuilder { _definition: string; _item: Item _ignoreHeaders: string[]; + _requestSeparator: string; constructor() { this._definition = ''; this._ignoreHeaders = []; + this._requestSeparator = '\n\n\n'; } from(item: Item): RequestDefinitionBuilder { this._item = item; + this.includeSeparatorIf(this._definition.length > this._requestSeparator.length); + return this; } includeSeparatorIf(condition: boolean): RequestDefinitionBuilder { if (condition) { - this._definition += '\n\n\n'; + this._definition += this._requestSeparator; } return this; diff --git a/src/tests/RequestDefinitionBuilder.test.ts b/src/tests/RequestDefinitionBuilder.test.ts index 99f60ef..9077026 100644 --- a/src/tests/RequestDefinitionBuilder.test.ts +++ b/src/tests/RequestDefinitionBuilder.test.ts @@ -242,6 +242,17 @@ describe('Request Definition Builder', () => { expect(actual).toBe('\n\n\n'); }); + test('Adds separator if target item has changed', () => { + const target = new RequestDefinitionBuilder() + .from(getRequest) + .appendName() + .from(getRequest); + + const actual = target.toString(); + + expect(actual).toBe('### Get Comment\n\n\n'); + }); + test('Builds output in order', () => { const event1 = new Event({ listen: 'test', script: { exec: ['console.log("something");'] } }); getRequest.events.add(event1);