Skip to content

Commit c755ef0

Browse files
authored
fix(breaking): always return array (#225)
## 🧰 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
1 parent 96edde3 commit c755ef0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/fixtures/runCustomFixtures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture)
3131
}
3232

3333
const snippet = new HTTPSnippet(request, opts);
34-
const result = snippet.convert(targetId, clientId, options);
34+
const result = snippet.convert(targetId, clientId, options)[0];
3535
const filePath = path.join(__dirname, '..', 'targets', targetId, clientId, 'fixtures', fixtureFile);
3636
if (process.env.OVERWRITE_EVERYTHING) {
3737
writeFileSync(filePath, String(result));

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,6 @@ export class HTTPSnippet {
334334

335335
const { convert } = target.clientsById[clientId || target.info.default];
336336
const results = this.requests.map(request => convert(request, options));
337-
return results.length === 1 ? results[0] : results;
337+
return results;
338338
}
339339
}

src/targets/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ describe('request validation', () => {
7474
`${fixture}${extname(targetId, clientId)}`,
7575
);
7676

77-
let result;
78-
let expected;
77+
let result: string[] | false;
78+
let expected: string;
7979

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

91-
result = snippet.convert(targetId, clientId);
91+
result = snippet.convert(targetId, clientId)[0];
9292

9393
if (OVERWRITE_EVERYTHING && result) {
9494
writeFileSync(expectedPath, String(result));
@@ -313,7 +313,7 @@ describe('addTargetClient', () => {
313313

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

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

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

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

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

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

0 commit comments

Comments
 (0)