Skip to content

Commit

Permalink
chore(internal): add ecosystem test for qs reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored and stainless-bot committed Sep 17, 2024
1 parent 1ec41a7 commit 0199dd8
Show file tree
Hide file tree
Showing 6 changed files with 2,168 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ecosystem-tests/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const projectRunners = {
await installPackage();
await run('node', ['test.js']);
},
'nodenext-tsup': async () => {
await installPackage();
await run('npm', ['run', 'build']);

if (state.live) {
await run('npm', ['run', 'main']);
}
},
'ts-browser-webpack': async () => {
await installPackage();

Expand Down
41 changes: 41 additions & 0 deletions ecosystem-tests/nodenext-tsup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { OpenAI } from 'openai';

const openai = new OpenAI();

function assertEqual(actual: any, expected: any) {
if (actual === expected) {
return;
}

console.error('expected', expected);
console.error('actual ', actual);
throw new Error('expected values to be equal');
}

async function main() {
const completion = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{
role: 'user',
content: 'What is the capital of the United States?',
},
],
});
// smoke test for responses
if (!completion.choices[0]?.message.content) {
console.dir(completion, { depth: 4 });
throw new Error('no response content!');
}

assertEqual(
decodeURIComponent((openai as any).stringifyQuery({ foo: { nested: { a: true, b: 'foo' } } })),
'foo[nested][a]=true&foo[nested][b]=foo',
);
assertEqual(
decodeURIComponent((openai as any).stringifyQuery({ foo: { nested: { a: ['hello', 'world'] } } })),
'foo[nested][a][]=hello&foo[nested][a][]=world',
);
}

main();
Loading

0 comments on commit 0199dd8

Please sign in to comment.