Skip to content

Commit

Permalink
Auto add separator on context change (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner authored Sep 14, 2024
1 parent 41ca416 commit e421a19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -41,4 +41,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
}
}
}
6 changes: 5 additions & 1 deletion src/RequestDefinitionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/tests/RequestDefinitionBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e421a19

Please sign in to comment.