Skip to content

Commit

Permalink
fix(breaking): always return array (#225)
Browse files Browse the repository at this point in the history
## 🧰 Changes

I had DX concerns about the `string[] | string` setup in the
`.convert()` method and talked offline with @erunion and agreed that it
should always return a `string[]`, so this PR makes that change. This is
a breaking change.

## 🧬 QA & Testing

Is this everything? I saw this line below but I think it's unrelated so
I left it, but let me know if I'm wrong about this.


https://github.com/readmeio/httpsnippet/blob/fc92e4000714ec677bbf712fc9537fd616e8ae65/src/targets/index.ts#L41
  • Loading branch information
kanadgupta authored Apr 9, 2024
1 parent 96edde3 commit c755ef0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/fixtures/runCustomFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture)
}

const snippet = new HTTPSnippet(request, opts);
const result = snippet.convert(targetId, clientId, options);
const result = snippet.convert(targetId, clientId, options)[0];
const filePath = path.join(__dirname, '..', 'targets', targetId, clientId, 'fixtures', fixtureFile);
if (process.env.OVERWRITE_EVERYTHING) {
writeFileSync(filePath, String(result));
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,6 @@ export class HTTPSnippet {

const { convert } = target.clientsById[clientId || target.info.default];
const results = this.requests.map(request => convert(request, options));
return results.length === 1 ? results[0] : results;
return results;
}
}
10 changes: 5 additions & 5 deletions src/targets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ describe('request validation', () => {
`${fixture}${extname(targetId, clientId)}`,
);

let result;
let expected;
let result: string[] | false;
let expected: string;

try {
const options: HTTPSnippetOptions = {};
Expand All @@ -88,7 +88,7 @@ describe('request validation', () => {
expected = readFileSync(expectedPath).toString();
const snippet = new HTTPSnippet(request, options);

result = snippet.convert(targetId, clientId);
result = snippet.convert(targetId, clientId)[0];

if (OVERWRITE_EVERYTHING && result) {
writeFileSync(expectedPath, String(result));
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('addTargetClient', () => {

const snippet = new HTTPSnippet(short.log.entries[0].request as Request, {});

const result = snippet.convert('node', 'custom');
const result = snippet.convert('node', 'custom')[0];

expect(result).toBe('This was generated from a custom client.');
});
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('addClientPlugin', () => {

const snippet = new HTTPSnippet(short.log.entries[0].request as Request, {});

const result = snippet.convert('node', 'custom');
const result = snippet.convert('node', 'custom')[0];

expect(result).toBe('This was generated from a custom client.');
});
Expand Down

0 comments on commit c755ef0

Please sign in to comment.