[cli] Add client.cwd to unify all working directory related logic (#10031)

A few commands were still checking on `--cwd` explicitly, which is incorrect since the entrypoint file already handles the directory change.

The new `client.cwd` property is a helper to make writing tests easier. Tests no longer need to `chdir()` explicitly and then revert afterwards.
This commit is contained in:
Nathan Rajlich
2023-05-26 13:42:03 -07:00
committed by GitHub
parent 113b8ac87b
commit ef30a46c03
18 changed files with 1112 additions and 1387 deletions

View File

@@ -0,0 +1,5 @@
---
'vercel': patch
---
Fix `--cwd` flag with a relative path for `env`, `link`, `promote`, and `rollback` subcommands

View File

@@ -133,7 +133,7 @@ const help = () => {
};
export default async function main(client: Client): Promise<number> {
const { output } = client;
const { cwd, output } = client;
// Ensure that `vc build` is not being invoked recursively
if (process.env.__VERCEL_BUILD_RUNNING) {
@@ -165,8 +165,6 @@ export default async function main(client: Client): Promise<number> {
return 2;
}
const cwd = process.cwd();
// Build `target` influences which environment variables will be used
const target = argv['--prod'] ? 'production' : 'preview';
const yes = Boolean(argv['--yes']);

View File

@@ -130,10 +130,9 @@ export default async function main(client: Client) {
return 2;
}
const cwd = argv['--cwd'] || process.cwd();
const subArgs = argv._.slice(1);
const { subcommand, args } = getSubcommand(subArgs, COMMAND_CONFIG);
const { output, config } = client;
const { cwd, output, config } = client;
const target = argv['--environment']?.toLowerCase() || 'development';
if (!isValidEnvTarget(target)) {

View File

@@ -90,7 +90,7 @@ export default async function main(client: Client) {
)} instead`
);
} else {
cwd = process.cwd();
cwd = client.cwd;
}
if (argv['--repo']) {

View File

@@ -88,7 +88,7 @@ export default async (client: Client): Promise<number> => {
autoConfirm: Boolean(argv['--yes']),
client,
commandName: 'promote',
cwd: argv['--cwd'] || process.cwd(),
cwd: client.cwd,
projectNameOrId: argv._[2],
});

View File

@@ -88,7 +88,7 @@ export default async (client: Client): Promise<number> => {
autoConfirm: Boolean(argv['--yes']),
client,
commandName: 'promote',
cwd: argv['--cwd'] || process.cwd(),
cwd: client.cwd,
projectNameOrId: argv._[2],
});

View File

@@ -144,12 +144,6 @@ const main = async () => {
return 1;
}
let cwd = argv['--cwd'];
if (cwd) {
process.chdir(cwd);
}
cwd = process.cwd();
// The second argument to the command can be:
//
// * a path to deploy (as in: `vercel path/`)
@@ -277,6 +271,12 @@ const main = async () => {
argv: process.argv,
});
// The `--cwd` flag is respected for all sub-commands
if (argv['--cwd']) {
client.cwd = argv['--cwd'];
}
const { cwd } = client;
// Gets populated to the subcommand name when a built-in is
// provided, otherwise it remains undefined for an extension
let subcommand: string | undefined = undefined;

View File

@@ -207,4 +207,12 @@ export default class Client extends EventEmitter implements Stdio {
output: this.stderr as NodeJS.WriteStream,
});
}
get cwd(): string {
return process.cwd();
}
set cwd(v: string) {
process.chdir(v);
}
}

View File

@@ -1,3 +1,5 @@
const originalCwd = process.cwd();
// Register Jest matcher extensions for CLI unit tests
import './matchers';
@@ -73,6 +75,8 @@ export class MockClient extends Client {
});
this.scenario = Router();
this.reset();
}
reset() {
@@ -99,11 +103,14 @@ export class MockClient extends Client {
};
this.config = {};
this.localConfig = {};
this.localConfigPath = undefined;
this.scenario = Router();
this.agent?.destroy();
this.agent = undefined;
this.cwd = originalCwd;
}
async startMockServer() {
@@ -156,7 +163,7 @@ beforeAll(async () => {
await client.startMockServer();
});
beforeEach(() => {
afterEach(() => {
client.reset();
});

File diff suppressed because it is too large Load Diff

View File

@@ -141,232 +141,206 @@ describe('deploy', () => {
});
it('should send a tgz file when `--archive=tgz`', async () => {
const cwd = setupUnitFixture('commands/deploy/static');
const originalCwd = process.cwd();
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
});
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
let body: any;
client.scenario.post(`/v13/deployments`, (req, res) => {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
client.scenario.get(`/v10/now/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
let body: any;
client.scenario.post(`/v13/deployments`, (req, res) => {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
client.scenario.get(
`/v10/now/deployments/dpl_archive_test`,
(req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
}
);
client.setArgv('deploy', '--archive=tgz');
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body?.files?.length).toEqual(1);
expect(body?.files?.[0].file).toEqual('.vercel/source.tgz');
} finally {
process.chdir(originalCwd);
}
client.cwd = setupUnitFixture('commands/deploy/static');
client.setArgv('deploy', '--archive=tgz');
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body?.files?.length).toEqual(1);
expect(body?.files?.[0].file).toEqual('.vercel/source.tgz');
});
it('should pass flag to skip custom domain assignment', async () => {
const cwd = setupUnitFixture('commands/deploy/static');
const originalCwd = process.cwd();
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
});
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
let body: any;
client.scenario.post(`/v13/deployments`, (req, res) => {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
let body: any;
client.scenario.post(`/v13/deployments`, (req, res) => {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
client.setArgv('deploy', '--prod', '--skip-domain');
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body).toMatchObject({
target: 'production',
source: 'cli',
autoAssignCustomDomains: false,
version: 2,
});
} finally {
process.chdir(originalCwd);
}
client.cwd = setupUnitFixture('commands/deploy/static');
client.setArgv('deploy', '--prod', '--skip-domain');
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body).toMatchObject({
target: 'production',
source: 'cli',
autoAssignCustomDomains: false,
version: 2,
});
});
it('should upload missing files', async () => {
const cwd = setupUnitFixture('commands/deploy/static');
const originalCwd = process.cwd();
client.cwd = cwd;
// Add random 1mb file
await fs.writeFile(join(cwd, 'data'), randomBytes(bytes('1mb')));
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
});
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'static',
id: 'static',
});
let body: any;
let fileUploaded = false;
client.scenario.post(`/v13/deployments`, (req, res) => {
if (fileUploaded) {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
} else {
const sha = req.body.files[0].sha;
res.status(400).json({
error: {
code: 'missing_files',
message: 'Missing files',
missing: [sha],
},
});
}
});
client.scenario.post('/v2/files', (req, res) => {
// Wait for file to be finished uploading
req.on('data', () => {
// Noop
});
req.on('end', () => {
fileUploaded = true;
res.end();
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
let body: any;
let fileUploaded = false;
client.scenario.post(`/v13/deployments`, (req, res) => {
if (fileUploaded) {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
} else {
const sha = req.body.files[0].sha;
res.status(400).json({
error: {
code: 'missing_files',
message: 'Missing files',
missing: [sha],
},
});
}
});
client.scenario.post('/v2/files', (req, res) => {
// Wait for file to be finished uploading
req.on('data', () => {
// Noop
});
client.scenario.get(
`/v10/now/deployments/dpl_archive_test`,
(req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
}
);
// When stderr is not a TTY we expect 5 progress lines to be printed
client.stderr.isTTY = false;
client.setArgv('deploy', '--archive=tgz');
const uploadingLines: string[] = [];
client.stderr.on('data', data => {
if (data.startsWith('Uploading [')) {
uploadingLines.push(data);
}
req.on('end', () => {
fileUploaded = true;
res.end();
});
client.stderr.resume();
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body?.files?.length).toEqual(1);
expect(body?.files?.[0].file).toEqual('.vercel/source.tgz');
expect(uploadingLines.length).toEqual(5);
expect(
uploadingLines[0].startsWith('Uploading [--------------------]')
).toEqual(true);
expect(
uploadingLines[1].startsWith('Uploading [=====---------------]')
).toEqual(true);
expect(
uploadingLines[2].startsWith('Uploading [==========----------]')
).toEqual(true);
expect(
uploadingLines[3].startsWith('Uploading [===============-----]')
).toEqual(true);
expect(
uploadingLines[4].startsWith('Uploading [====================]')
).toEqual(true);
} finally {
process.chdir(originalCwd);
}
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
client.scenario.get(`/v10/now/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
// When stderr is not a TTY we expect 5 progress lines to be printed
client.stderr.isTTY = false;
client.setArgv('deploy', '--archive=tgz');
const uploadingLines: string[] = [];
client.stderr.on('data', data => {
if (data.startsWith('Uploading [')) {
uploadingLines.push(data);
}
});
client.stderr.resume();
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body?.files?.length).toEqual(1);
expect(body?.files?.[0].file).toEqual('.vercel/source.tgz');
expect(uploadingLines.length).toEqual(5);
expect(
uploadingLines[0].startsWith('Uploading [--------------------]')
).toEqual(true);
expect(
uploadingLines[1].startsWith('Uploading [=====---------------]')
).toEqual(true);
expect(
uploadingLines[2].startsWith('Uploading [==========----------]')
).toEqual(true);
expect(
uploadingLines[3].startsWith('Uploading [===============-----]')
).toEqual(true);
expect(
uploadingLines[4].startsWith('Uploading [====================]')
).toEqual(true);
});
});

View File

@@ -11,7 +11,6 @@ import { useUser } from '../../mocks/user';
describe('env', () => {
describe('pull', () => {
it('should handle pulling', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -19,7 +18,9 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv('env', 'pull', '--yes');
const exitCodePromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project vercel-env-pull'
@@ -35,7 +36,6 @@ describe('env', () => {
});
it('should handle pulling from Preview env vars', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -43,15 +43,9 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
client.setArgv(
'env',
'pull',
'--yes',
'--cwd',
cwd,
'--environment',
'preview'
);
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv('env', 'pull', '--yes', '--environment', 'preview');
const exitCodePromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `preview` Environment Variables for Project vercel-env-pull'
@@ -70,7 +64,6 @@ describe('env', () => {
});
it('should handle pulling from specific Git branch', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -78,12 +71,12 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv(
'env',
'pull',
'--yes',
'--cwd',
cwd,
'--environment',
'preview',
'--git-branch',
@@ -114,7 +107,6 @@ describe('env', () => {
});
it('should handle alternate filename', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -122,7 +114,9 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
client.setArgv('env', 'pull', 'other.env', '--yes', '--cwd', cwd);
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv('env', 'pull', 'other.env', '--yes');
const exitCodePromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project vercel-env-pull'
@@ -138,7 +132,6 @@ describe('env', () => {
});
it('should use given environment', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -146,15 +139,9 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
client.setArgv(
'env',
'pull',
'--environment',
'production',
'--cwd',
cwd
);
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv('env', 'pull', '--environment', 'production');
const exitCodePromise = env(client);
await expect(client.stderr).toOutput(
`Downloading \`production\` Environment Variables for Project vercel-env-pull`
@@ -172,7 +159,6 @@ describe('env', () => {
});
it('should throw an error when it does not recognize given environment', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -180,15 +166,14 @@ describe('env', () => {
id: 'vercel-env-pull',
name: 'vercel-env-pull',
});
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv(
'env',
'pull',
'.env.production',
'--environment',
'something-invalid',
'--cwd',
cwd
'something-invalid'
);
const exitCodePromise = env(client);
@@ -200,7 +185,6 @@ describe('env', () => {
});
it('should expose production system env variables', async () => {
const cwd = setupUnitFixture('vercel-env-pull');
useUser();
useTeams('team_dummy');
useProject({
@@ -209,8 +193,9 @@ describe('env', () => {
name: 'vercel-env-pull',
autoExposeSystemEnvs: true,
});
client.setArgv('env', 'pull', 'other.env', '--yes', '--cwd', cwd);
const cwd = setupUnitFixture('vercel-env-pull');
client.cwd = cwd;
client.setArgv('env', 'pull', 'other.env', '--yes');
const exitCodePromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project vercel-env-pull'
@@ -228,6 +213,7 @@ describe('env', () => {
it('should show a delta string', async () => {
const cwd = setupUnitFixture('vercel-env-pull-delta');
client.cwd = cwd;
try {
useUser();
useTeams('team_dummy');
@@ -237,7 +223,7 @@ describe('env', () => {
name: 'env-pull-delta',
});
client.setArgv('env', 'add', 'NEW_VAR', '--cwd', cwd);
client.setArgv('env', 'add', 'NEW_VAR');
const addPromise = env(client);
await expect(client.stderr).toOutput('Whats the value of NEW_VAR?');
@@ -253,7 +239,7 @@ describe('env', () => {
await expect(addPromise).resolves.toEqual(0);
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
client.setArgv('env', 'pull', '--yes');
const pullPromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project env-pull-delta'
@@ -265,13 +251,12 @@ describe('env', () => {
await expect(pullPromise).resolves.toEqual(0);
} finally {
client.setArgv('env', 'rm', 'NEW_VAR', '--yes', '--cwd', cwd);
client.setArgv('env', 'rm', 'NEW_VAR', '--yes');
await env(client);
}
});
it('should not show a delta string when it fails to read a file', async () => {
const cwd = setupUnitFixture('vercel-env-pull-delta-corrupt');
useUser();
useTeams('team_dummy');
useProject({
@@ -279,15 +264,15 @@ describe('env', () => {
id: 'env-pull-delta-corrupt',
name: 'env-pull-delta-corrupt',
});
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
const cwd = setupUnitFixture('vercel-env-pull-delta-corrupt');
client.cwd = cwd;
client.setArgv('env', 'pull', '--yes');
const pullPromise = env(client);
await expect(client.stderr).toOutput('Updated .env.local file');
await expect(pullPromise).resolves.toEqual(0);
});
it('should show that no changes were found', async () => {
const cwd = setupUnitFixture('vercel-env-pull-delta-no-changes');
useUser();
useTeams('team_dummy');
useProject({
@@ -295,8 +280,8 @@ describe('env', () => {
id: 'env-pull-delta-no-changes',
name: 'env-pull-delta-no-changes',
});
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
client.cwd = setupUnitFixture('vercel-env-pull-delta-no-changes');
client.setArgv('env', 'pull', '--yes');
const pullPromise = env(client);
await expect(client.stderr).toOutput('> No changes found.');
await expect(client.stderr).toOutput('Updated .env.local file');
@@ -305,6 +290,7 @@ describe('env', () => {
it('should correctly render delta string when env variable has quotes', async () => {
const cwd = setupUnitFixture('vercel-env-pull-delta-quotes');
client.cwd = cwd;
try {
useUser();
useTeams('team_dummy');
@@ -329,7 +315,7 @@ describe('env', () => {
]
);
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
client.setArgv('env', 'pull', '--yes');
const pullPromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project env-pull-delta'
@@ -339,13 +325,14 @@ describe('env', () => {
await expect(pullPromise).resolves.toEqual(0);
} finally {
client.setArgv('env', 'rm', 'NEW_VAR', '--yes', '--cwd', cwd);
client.setArgv('env', 'rm', 'NEW_VAR', '--yes');
await env(client);
}
});
it('should correctly render delta string when local env variable has quotes', async () => {
const cwd = setupUnitFixture('vercel-env-pull-delta-quotes');
client.cwd = cwd;
try {
useUser();
useTeams('team_dummy');
@@ -370,7 +357,7 @@ describe('env', () => {
]
);
client.setArgv('env', 'pull', '.env.testquotes', '--yes', '--cwd', cwd);
client.setArgv('env', 'pull', '.env.testquotes', '--yes');
const pullPromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project env-pull-delta'
@@ -380,7 +367,7 @@ describe('env', () => {
await expect(pullPromise).resolves.toEqual(0);
} finally {
client.setArgv('env', 'rm', 'NEW_VAR', '--yes', '--cwd', cwd);
client.setArgv('env', 'rm', 'NEW_VAR', '--yes');
await env(client);
}
});

View File

@@ -9,14 +9,13 @@ import type { Project } from '@vercel-internals/types';
describe('git', () => {
describe('connect', () => {
const originalCwd = process.cwd();
const fixture = (name: string) =>
join(__dirname, '../../fixtures/unit/commands/git/connect', name);
it('connects an unlinked project', async () => {
const cwd = fixture('unlinked');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -62,13 +61,12 @@ describe('git', () => {
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('connects an unlinked project with a remote url', async () => {
const cwd = fixture('unlinked');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -119,34 +117,28 @@ describe('git', () => {
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should fail when there is no git config', async () => {
const cwd = fixture('no-git-config');
try {
process.chdir(cwd);
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'no-git-config',
name: 'no-git-config',
});
client.setArgv('git', 'connect', '--yes');
const exitCode = await git(client);
expect(exitCode).toEqual(1);
await expect(client.stderr).toOutput(
`Error: No local Git repository found. Run \`git clone <url>\` to clone a remote Git repository first.\n`
);
} finally {
process.chdir(originalCwd);
}
client.cwd = fixture('no-git-config');
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'no-git-config',
name: 'no-git-config',
});
client.setArgv('git', 'connect', '--yes');
const exitCode = await git(client);
expect(exitCode).toEqual(1);
await expect(client.stderr).toOutput(
`Error: No local Git repository found. Run \`git clone <url>\` to clone a remote Git repository first.\n`
);
});
it('should fail when there is no remote url', async () => {
const cwd = fixture('no-remote-url');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -163,13 +155,12 @@ describe('git', () => {
);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should fail when the remote url is bad', async () => {
const cwd = fixture('bad-remote-url');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -190,13 +181,12 @@ describe('git', () => {
);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should connect a repo to a project that is not already connected', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -232,13 +222,12 @@ describe('git', () => {
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should replace an old connection with a new one', async () => {
const cwd = fixture('existing-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -285,13 +274,12 @@ describe('git', () => {
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should exit when an already-connected repo is connected', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -324,13 +312,12 @@ describe('git', () => {
expect(exitCode).toEqual(1);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should fail when it cannot find the repository', async () => {
const cwd = fixture('invalid-repo');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -354,13 +341,12 @@ describe('git', () => {
expect(exitCode).toEqual(1);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should connect the default option of multiple remotes', async () => {
const cwd = fixture('multiple-remotes');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -404,19 +390,17 @@ describe('git', () => {
});
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
});
describe('disconnect', () => {
const originalCwd = process.cwd();
const fixture = (name: string) =>
join(__dirname, '../../fixtures/unit/commands/git/connect', name);
it('should disconnect a repository', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -453,13 +437,12 @@ describe('git', () => {
expect(exitCode).toEqual(0);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should fail if there is no repository to disconnect', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -480,13 +463,12 @@ describe('git', () => {
expect(exitCode).toEqual(1);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should connect a given repository', async () => {
const cwd = fixture('no-remote-url');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -522,13 +504,12 @@ describe('git', () => {
await expect(gitPromise).resolves.toEqual(0);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should prompt when it finds a repository', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -571,13 +552,12 @@ describe('git', () => {
await expect(gitPromise).resolves.toEqual(0);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should prompt when it finds multiple remotes', async () => {
const cwd = fixture('multiple-remotes');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -621,13 +601,12 @@ describe('git', () => {
await expect(gitPromise).resolves.toEqual(0);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
it('should continue as normal when input matches single git remote', async () => {
const cwd = fixture('new-connection');
client.cwd = cwd;
try {
process.chdir(cwd);
await fs.rename(join(cwd, 'git'), join(cwd, '.git'));
useUser();
useTeams('team_dummy');
@@ -663,7 +642,6 @@ describe('git', () => {
await expect(gitPromise).resolves.toEqual(0);
} finally {
await fs.rename(join(cwd, '.git'), join(cwd, 'git'));
process.chdir(originalCwd);
}
});
});

View File

@@ -12,12 +12,10 @@ import {
import { tmpdir } from 'os';
describe('link', () => {
const origCwd = process.cwd();
it('should prompt for link', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'cli-'));
client.cwd = cwd;
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
const { project } = useProject({
@@ -50,15 +48,14 @@ describe('link', () => {
expect(projectJson.orgId).toEqual(user.id);
expect(projectJson.projectId).toEqual(project.id);
} finally {
process.chdir(origCwd);
await remove(cwd);
}
});
it('should allow specifying `--project` flag', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'cli-'));
client.cwd = cwd;
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
const { project } = useProject({
@@ -81,15 +78,14 @@ describe('link', () => {
expect(projectJson.orgId).toEqual(user.id);
expect(projectJson.projectId).toEqual(project.id);
} finally {
process.chdir(origCwd);
await remove(cwd);
}
});
it('should allow overwriting existing link', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'cli-'));
client.cwd = cwd;
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
const { project: proj1 } = useProject({
@@ -118,7 +114,6 @@ describe('link', () => {
expect(projectJson.orgId).toEqual(user.id);
expect(projectJson.projectId).toEqual(proj2.id);
} finally {
process.chdir(origCwd);
await remove(cwd);
}
});

View File

@@ -18,179 +18,160 @@ const fixture = (name: string) =>
join(__dirname, '../../fixtures/unit/commands/list', name);
describe('list', () => {
const originalCwd = process.cwd();
let teamSlug: string;
it('should get deployments from a project linked by a directory', async () => {
const cwd = fixture('with-team');
try {
process.chdir(cwd);
const user = useUser();
const team = useTeams('team_dummy');
teamSlug = team[0].slug;
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
const user = useUser();
const team = useTeams('team_dummy');
teamSlug = team[0].slug;
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
client.cwd = fixture('with-team');
await list(client);
await list(client);
const lines = createLineIterator(client.stderr);
const lines = createLineIterator(client.stderr);
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
line = await lines.next();
expect(line.value).toEqual(`Fetching deployments in ${team[0].slug}`);
line = await lines.next();
expect(line.value).toEqual(`Fetching deployments in ${team[0].slug}`);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(team[0].slug);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(team[0].slug);
// skip next line
await lines.next();
// skip next line
await lines.next();
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual([
'Age',
'Deployment',
'Status',
'Duration',
'Username',
]);
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual([
'Age',
'Deployment',
'Status',
'Duration',
'Username',
]);
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
expect(data).toEqual([
`https://${deployment.url}`,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
user.username,
]);
} finally {
process.chdir(originalCwd);
}
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
expect(data).toEqual([
`https://${deployment.url}`,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
user.username,
]);
});
it('should get deployments for linked project where the scope is a user', async () => {
const cwd = fixture('with-team');
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
client.cwd = fixture('with-team');
client.setArgv('-S', user.username);
await list(client);
client.setArgv('-S', user.username);
await list(client);
const lines = createLineIterator(client.stderr);
const lines = createLineIterator(client.stderr);
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
line = await lines.next();
expect(line.value).toEqual(`Fetching deployments in ${user.username}`);
line = await lines.next();
expect(line.value).toEqual(`Fetching deployments in ${user.username}`);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(user.username);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(user.username);
// skip next line
await lines.next();
// skip next line
await lines.next();
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual(['Age', 'Deployment', 'Status', 'Duration']);
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual(['Age', 'Deployment', 'Status', 'Duration']);
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
expect(data).toEqual([
'https://' + deployment.url,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
]);
} finally {
process.chdir(originalCwd);
}
expect(data).toEqual([
'https://' + deployment.url,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
]);
});
it('should get the deployments for a specified project', async () => {
const cwd = fixture('with-team');
try {
process.chdir(cwd);
const user = useUser();
const team = useTeams('team_dummy');
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
const user = useUser();
const team = useTeams('team_dummy');
useProject({
...defaultProject,
id: 'with-team',
name: 'with-team',
});
const deployment = useDeployment({ creator: user });
client.cwd = fixture('with-team');
client.setArgv(deployment.name);
await list(client);
client.setArgv(deployment.name);
await list(client);
const lines = createLineIterator(client.stderr);
const lines = createLineIterator(client.stderr);
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
let line = await lines.next();
expect(line.value).toEqual('Retrieving project…');
line = await lines.next();
expect(line.value).toEqual(
`Fetching deployments in ${teamSlug || team[0].slug}`
);
line = await lines.next();
expect(line.value).toEqual(
`Fetching deployments in ${teamSlug || team[0].slug}`
);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(teamSlug || team[0].slug);
line = await lines.next();
const { org } = pluckIdentifiersFromDeploymentList(line.value!);
expect(org).toEqual(teamSlug || team[0].slug);
// skip next line
await lines.next();
// skip next line
await lines.next();
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
expect(line.value).toEqual('');
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual([
'Age',
'Deployment',
'Status',
'Duration',
'Username',
]);
line = await lines.next();
const header = parseSpacedTableRow(line.value!);
expect(header).toEqual([
'Age',
'Deployment',
'Status',
'Duration',
'Username',
]);
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
expect(data).toEqual([
`https://${deployment.url}`,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
user.username,
]);
} finally {
process.chdir(originalCwd);
}
line = await lines.next();
const data = parseSpacedTableRow(line.value!);
data.shift();
expect(data).toEqual([
`https://${deployment.url}`,
stateString(deployment.state || ''),
getDeploymentDuration(deployment),
user.username,
]);
});
});

View File

@@ -13,20 +13,10 @@ import sleep from '../../../src/util/sleep';
jest.setTimeout(60000);
describe('promote', () => {
it('should error if cwd is invalid', async () => {
client.setArgv('promote', '--cwd', __filename);
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
'Error: Support for single file deployments has been removed.'
);
await expect(exitCodePromise).resolves.toEqual(1);
});
it('should error if timeout is invalid', async () => {
const { cwd } = initPromoteTest();
client.setArgv('promote', '--yes', '--cwd', cwd, '--timeout', 'foo');
client.cwd = cwd;
client.setArgv('promote', '--yes', '--timeout', 'foo');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput('Error: Invalid timeout "foo"');
@@ -35,7 +25,8 @@ describe('promote', () => {
it('should error if invalid deployment ID', async () => {
const { cwd } = initPromoteTest();
client.setArgv('promote', '????', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', '????', '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -46,7 +37,8 @@ describe('promote', () => {
it('should error if deployment not found', async () => {
const { cwd } = initPromoteTest();
client.setArgv('promote', 'foo', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', 'foo', '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput('Fetching deployment "foo" in ');
@@ -59,7 +51,8 @@ describe('promote', () => {
it('should show status when not promoting', async () => {
const { cwd } = initPromoteTest();
client.setArgv('promote', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -72,7 +65,8 @@ describe('promote', () => {
it('should promote by deployment id', async () => {
const { cwd, previousDeployment } = initPromoteTest();
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -90,7 +84,8 @@ describe('promote', () => {
it('should promote by deployment url', async () => {
const { cwd, previousDeployment } = initPromoteTest();
client.setArgv('promote', previousDeployment.url, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.url, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -110,16 +105,17 @@ describe('promote', () => {
const { cwd, previousDeployment, project } = initPromoteTest({
promotePollCount: 10,
});
client.cwd = cwd;
// start the promote
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.setArgv('promote', previousDeployment.id, '--yes');
promote(client);
// need to wait for the promote request to be accepted
await sleep(300);
// get the status
client.setArgv('promote', '--yes', '--cwd', cwd);
client.setArgv('promote', '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -139,8 +135,8 @@ describe('promote', () => {
promotePollCount: 10,
promoteStatusCode: 500,
});
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -157,7 +153,8 @@ describe('promote', () => {
const { cwd, previousDeployment } = initPromoteTest({
promoteJobStatus: 'failed',
});
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -185,7 +182,8 @@ describe('promote', () => {
],
promoteJobStatus: 'failed',
});
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -209,15 +207,8 @@ describe('promote', () => {
const { cwd, previousDeployment } = initPromoteTest({
promotePollCount: 10,
});
client.setArgv(
'promote',
previousDeployment.id,
'--yes',
'--cwd',
cwd,
'--timeout',
'1'
);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes', '--timeout', '1');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -236,15 +227,8 @@ describe('promote', () => {
it('should immediately exit after requesting promote', async () => {
const { cwd, previousDeployment } = initPromoteTest();
client.setArgv(
'promote',
previousDeployment.id,
'--yes',
'--cwd',
cwd,
'--timeout',
'0'
);
client.cwd = cwd;
client.setArgv('promote', previousDeployment.id, '--yes', '--timeout', '0');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(
@@ -261,12 +245,13 @@ describe('promote', () => {
it('should error if deployment belongs to different team', async () => {
const { cwd, previousDeployment } = initPromoteTest();
client.cwd = cwd;
previousDeployment.team = {
id: 'abc',
name: 'abc',
slug: 'abc',
};
client.setArgv('promote', previousDeployment.id, '--yes', '--cwd', cwd);
client.setArgv('promote', previousDeployment.id, '--yes');
const exitCodePromise = promote(client);
await expect(client.stderr).toOutput(

View File

@@ -13,20 +13,10 @@ import sleep from '../../../src/util/sleep';
jest.setTimeout(60000);
describe('rollback', () => {
it('should error if cwd is invalid', async () => {
client.setArgv('rollback', '--cwd', __filename);
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
'Error: Support for single file deployments has been removed.'
);
await expect(exitCodePromise).resolves.toEqual(1);
});
it('should error if timeout is invalid', async () => {
const { cwd } = initRollbackTest();
client.setArgv('rollback', '--yes', '--cwd', cwd, '--timeout', 'foo');
client.cwd = cwd;
client.setArgv('rollback', '--yes', '--timeout', 'foo');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput('Error: Invalid timeout "foo"');
@@ -35,7 +25,8 @@ describe('rollback', () => {
it('should error if invalid deployment ID', async () => {
const { cwd } = initRollbackTest();
client.setArgv('rollback', '????', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', '????', '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -46,7 +37,8 @@ describe('rollback', () => {
it('should error if deployment not found', async () => {
const { cwd } = initRollbackTest();
client.setArgv('rollback', 'foo', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', 'foo', '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -58,7 +50,8 @@ describe('rollback', () => {
it('should show status when not rolling back', async () => {
const { cwd } = initRollbackTest();
client.setArgv('rollback', '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -71,7 +64,8 @@ describe('rollback', () => {
it('should rollback by deployment id', async () => {
const { cwd, previousDeployment } = initRollbackTest();
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.id, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -89,7 +83,8 @@ describe('rollback', () => {
it('should rollback by deployment url', async () => {
const { cwd, previousDeployment } = initRollbackTest();
client.setArgv('rollback', previousDeployment.url, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.url, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -109,16 +104,17 @@ describe('rollback', () => {
const { cwd, previousDeployment, project } = initRollbackTest({
rollbackPollCount: 10,
});
client.cwd = cwd;
// start the rollback
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.setArgv('rollback', previousDeployment.id, '--yes');
rollback(client);
// need to wait for the rollback request to be accepted
await sleep(300);
// get the status
client.setArgv('rollback', '--yes', '--cwd', cwd);
client.setArgv('rollback', '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -138,8 +134,9 @@ describe('rollback', () => {
rollbackPollCount: 10,
rollbackStatusCode: 500,
});
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.setArgv('rollback', previousDeployment.id, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -155,7 +152,8 @@ describe('rollback', () => {
const { cwd, previousDeployment } = initRollbackTest({
rollbackJobStatus: 'failed',
});
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.id, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -183,7 +181,8 @@ describe('rollback', () => {
],
rollbackJobStatus: 'failed',
});
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.id, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(
@@ -207,12 +206,11 @@ describe('rollback', () => {
const { cwd, previousDeployment } = initRollbackTest({
rollbackPollCount: 10,
});
client.cwd = cwd;
client.setArgv(
'rollback',
previousDeployment.id,
'--yes',
'--cwd',
cwd,
'--timeout',
'1'
);
@@ -233,12 +231,11 @@ describe('rollback', () => {
it('should immediately exit after requesting rollback', async () => {
const { cwd, previousDeployment } = initRollbackTest();
client.cwd = cwd;
client.setArgv(
'rollback',
previousDeployment.id,
'--yes',
'--cwd',
cwd,
'--timeout',
'0'
);
@@ -263,7 +260,8 @@ describe('rollback', () => {
name: 'abc',
slug: 'abc',
};
client.setArgv('rollback', previousDeployment.id, '--yes', '--cwd', cwd);
client.cwd = cwd;
client.setArgv('rollback', previousDeployment.id, '--yes');
const exitCodePromise = rollback(client);
await expect(client.stderr).toOutput(

View File

@@ -306,10 +306,9 @@ describe('createGitMeta', () => {
}
});
it('uses the repo url for a connected project', async () => {
const originalCwd = process.cwd();
const directory = fixture('connected-repo');
client.cwd = directory;
try {
process.chdir(directory);
await fs.rename(join(directory, 'git'), join(directory, '.git'));
useUser();
@@ -343,7 +342,6 @@ describe('createGitMeta', () => {
});
} finally {
await fs.rename(join(directory, '.git'), join(directory, 'git'));
process.chdir(originalCwd);
}
});
});