mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
These changes originally from #6652, but pulled out to be merged separately. `outputBuffer` is a simpler way of asserting tests against the CLI output instead of working directly withe Jest mock function. `output.isTTY` is also now mutable, so that we can write tests for both cases when the output is different based on TTY-ness (for example, see the updated `vc whoami` tests in this PR).
28 lines
884 B
TypeScript
28 lines
884 B
TypeScript
import { client } from '../mocks/client';
|
|
import { useUser } from '../mocks/user';
|
|
import whoami from '../../src/commands/whoami';
|
|
|
|
describe('whoami', () => {
|
|
it('should reject invalid arguments', async () => {
|
|
client.setArgv('--invalid');
|
|
await expect(whoami(client)).rejects.toThrow(
|
|
'unknown or unexpected option: --invalid'
|
|
);
|
|
});
|
|
|
|
it('should print the Vercel username', async () => {
|
|
const user = useUser();
|
|
const exitCode = await whoami(client);
|
|
expect(exitCode).toEqual(0);
|
|
expect(client.outputBuffer).toEqual(`> ${user.username}\n`);
|
|
});
|
|
|
|
it('should print only the Vercel username when output is not a TTY', async () => {
|
|
const user = useUser();
|
|
client.output.isTTY = false;
|
|
const exitCode = await whoami(client);
|
|
expect(exitCode).toEqual(0);
|
|
expect(client.outputBuffer).toEqual(`${user.username}\n`);
|
|
});
|
|
});
|