Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/commands/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,50 @@ describe('runConfigure', () => {
);
});

it('uses requestTimeoutMs for the pre-write key validation ping', async () => {
const { deps } = makeCapture();
let sawAbort = false;
const fetchImpl = vi.fn(
async (_input: string | URL | Request, init?: RequestInit) =>
new Promise<Response>((_resolve, reject) => {
const signal = init?.signal;
const timeout = setTimeout(() => {
reject(new Error('requestTimeoutMs was not applied to the validation ping'));
}, 50);
signal?.addEventListener(
'abort',
() => {
sawAbort = true;
clearTimeout(timeout);
reject(new DOMException('The operation timed out.', 'TimeoutError'));
},
{ once: true },
);
}),
) as unknown as typeof fetch;

await expect(
runConfigure(
{
profile: 'default',
output: 'text',
debug: false,
fromEnv: true,
requestTimeoutMs: 1,
},
{
...deps,
env: { TESTSPRITE_API_KEY: 'sk' },
credentialsPath,
fetchImpl,
},
),
).rejects.toBeInstanceOf(CLIError);

expect(sawAbort).toBe(true);
expect(readProfile('default', { path: credentialsPath })).toBeUndefined();
});

it('throws VALIDATION_ERROR when --from-env is set but key is missing', async () => {
const { deps } = makeCapture();
await expect(
Expand Down
1 change: 1 addition & 0 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export async function runConfigure(opts: ConfigureOptions, deps: AuthDeps = {}):
baseUrl: facadeBaseUrl(apiUrl),
apiKey,
fetchImpl: deps.fetchImpl,
requestTimeoutMs: opts.requestTimeoutMs,
});
try {
// Tag the validation call with the originating command (when provided) so
Expand Down