[cli] Fix env delta message (#8271)

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Matthew Stanciu
2022-07-29 12:18:55 -07:00
committed by GitHub
parent e8c7db59cf
commit 1cb5a91727
6 changed files with 74 additions and 30 deletions

View File

@@ -148,41 +148,46 @@ describe('env', () => {
it('should show a delta string', async () => {
const cwd = setupFixture('vercel-env-pull-delta');
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'env-pull-delta',
name: 'env-pull-delta',
});
try {
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'env-pull-delta',
name: 'env-pull-delta',
});
client.setArgv('env', 'add', 'NEW_VAR', '--cwd', cwd);
const addPromise = env(client);
client.setArgv('env', 'add', 'NEW_VAR', '--cwd', cwd);
const addPromise = env(client);
await expect(client.stderr).toOutput('Whats the value of NEW_VAR?');
client.stdin.write('testvalue\n');
await expect(client.stderr).toOutput('Whats the value of NEW_VAR?');
client.stdin.write('testvalue\n');
await expect(client.stderr).toOutput(
'Add NEW_VAR to which Environments (select multiple)?'
);
client.stdin.write('\x1B[B'); // Down arrow
client.stdin.write('\x1B[B');
client.stdin.write(' ');
client.stdin.write('\r');
await expect(client.stderr).toOutput(
'Add NEW_VAR to which Environments (select multiple)?'
);
client.stdin.write('\x1B[B'); // Down arrow
client.stdin.write('\x1B[B');
client.stdin.write(' ');
client.stdin.write('\r');
await expect(addPromise).resolves.toEqual(0);
await expect(addPromise).resolves.toEqual(0);
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
const pullPromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project env-pull-delta'
);
await expect(client.stderr).toOutput('Updated .env file');
await expect(client.stderr).toOutput(
'+ NEW_VAR\n~ SPECIAL_FLAG\n- TEST\n'
);
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
const pullPromise = env(client);
await expect(client.stderr).toOutput(
'Downloading `development` Environment Variables for Project env-pull-delta'
);
await expect(client.stderr).toOutput('Updated .env file');
await expect(client.stderr).toOutput(
'+ NEW_VAR\n~ SPECIAL_FLAG\n- TEST\n'
);
await expect(pullPromise).resolves.toEqual(0);
await expect(pullPromise).resolves.toEqual(0);
} finally {
client.setArgv('env', 'rm', 'NEW_VAR', '--yes', '--cwd', cwd);
await env(client);
}
});
it('should not show a delta string when it fails to read a file', async () => {
@@ -200,5 +205,22 @@ describe('env', () => {
await expect(client.stderr).toOutput('Updated .env file');
await expect(pullPromise).resolves.toEqual(0);
});
it('should show that no changes were found', async () => {
const cwd = setupFixture('vercel-env-pull-delta-no-changes');
useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
id: 'env-pull-delta-no-changes',
name: 'env-pull-delta-no-changes',
});
client.setArgv('env', 'pull', '--yes', '--cwd', cwd);
const pullPromise = env(client);
await expect(client.stderr).toOutput('Updated .env file');
await expect(client.stderr).toOutput('> No changes found.');
await expect(pullPromise).resolves.toEqual(0);
});
});
});