Files
vercel/packages/cli/test/unit/commands/inspect.test.ts
Chris Barber b52df7a533 [cli] Add vc deploy --no-wait and vc inspect --wait (#9802)
There's a need to allow `vc deploy` to not block and not wait for the deployment to finish, yet return the URL.

```
$ vc deploy --no-wait
Vercel CLI 28.18.5
🔍  Inspect: https://vercel.com/chrisbarber/next13fun/L8X4oxp5LGcmy51yVptXwMK7n4wt [1s]
📝  Note: Deployment is still processing...
  Production: https://next13fun-kecpx6za2-chrisbarber.vercel.app [1s]
```

Normally this deployment takes around 30 seconds, but the `--no-wait` flag causes the command to exit in less than 2 seconds.

The next step is to add the ability for `vc inspect` to wait as well as specify the maximum time to wait (defaults to 3 minutes, same as `vc rollback`).

```
$ vc inspect --wait --timeout 1m https://next13fun-kecpx6za2-chrisbarber.vercel.app
Vercel CLI 28.18.5
> Fetched deployment "next13fun-ov2r4pvdz-chrisbarber.vercel.app" in chrisbarber [23s]

  General

    id		dpl_9VUuV23EGeoqWf7akEeL8rP1c8cb
    name	next13fun
    status	● Ready
    url		https://next13fun-ov2r4pvdz-chrisbarber.vercel.app
    created	Thu Apr 13 2023 12:25:07 GMT-0500 (Central Daylight Time) [24s ago]
<snip>
```

Also added the ability to pipe the URL into `vc inspect`:

```
echo https://next13fun-ov2r4pvdz-chrisbarber.vercel.app | vc inspect
```

Combined, it allows us to support cool things like:

```
$ vc inspect $(vc deploy --prod --no-wait) --wait
```
2023-04-17 15:43:05 +00:00

90 lines
3.0 KiB
TypeScript

import { client } from '../../mocks/client';
import { useUser } from '../../mocks/user';
import { useDeployment } from '../../mocks/deployment';
import inspect from '../../../src/commands/inspect';
import sleep from '../../../src/util/sleep';
describe('inspect', () => {
it('should print out deployment information', async () => {
const user = useUser();
const deployment = useDeployment({ creator: user });
client.setArgv('inspect', deployment.url);
const exitCode = await inspect(client);
await expect(client.stderr).toOutput(
`> Fetched deployment "${deployment.url}" in ${user.username}`
);
expect(exitCode).toEqual(0);
});
it('should print out deployment information for piped URL', async () => {
const user = useUser();
const deployment = useDeployment({ creator: user });
client.stdin.isTTY = false;
client.stdin.write(deployment.url);
client.stdin.end();
const exitCode = await inspect(client);
await expect(client.stderr).toOutput(
`> Fetched deployment "${deployment.url}" in ${user.username}`
);
expect(exitCode).toEqual(0);
});
it('should strip the scheme of a url', async () => {
const user = useUser();
const deployment = useDeployment({ creator: user });
client.setArgv('inspect', `http://${deployment.url}`);
const exitCode = await inspect(client);
expect(exitCode).toEqual(0);
await expect(client.stderr).toOutput(
`> Fetched deployment "${deployment.url}" in ${user.username}`
);
});
it('should print error when deployment not found', async () => {
const user = useUser();
useDeployment({ creator: user });
client.setArgv('inspect', 'bad.com');
await expect(inspect(client)).rejects.toThrow(
`Can't find the deployment "bad.com" under the context "${user.username}"`
);
});
it('should print error if timeout is invalid', async () => {
const user = useUser();
useDeployment({ creator: user });
client.setArgv('inspect', 'foo.com', '--timeout', 'bar');
const exitCode = await inspect(client);
expect(exitCode).toEqual(1);
await expect(client.stderr).toOutput(`Invalid timeout "bar"`);
});
it('should wait for a deployment to finish', async () => {
const user = useUser();
const deployment = useDeployment({ creator: user, state: 'BUILDING' });
client.setArgv('inspect', deployment.url, '--wait');
let exitCode: number | null = null;
const startTime = Date.now();
const runInspect = async () => {
exitCode = await inspect(client);
await expect(client.stderr).toOutput(
`> Fetched deployment "${deployment.url}" in ${user.username}`
);
};
const slowlyDeploy = async () => {
await sleep(1234);
expect(exitCode).toBeNull();
deployment.readyState = 'READY';
};
await Promise.all<void>([runInspect(), slowlyDeploy()]);
expect(exitCode).toEqual(0);
const delta = Date.now() - startTime;
expect(delta).toBeGreaterThan(1234);
});
});