Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use oclif/test v4 #630

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.2.0",
"@oclif/test": "^3.2.15",
"@oclif/test": "^4",
"@salesforce/cli-plugins-testkit": "^5.3.6",
"@salesforce/dev-scripts": "^10.1.0",
"@salesforce/plugin-command-reference": "^3.0.85",
Expand Down
55 changes: 24 additions & 31 deletions test/commands/alias/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,38 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { expect, test } from '@oclif/test';
import { expect } from 'chai';
import { runCommand } from '@oclif/test';
import { TestContext } from '@salesforce/core/testSetup';

describe('alias list', () => {
const $$ = new TestContext();
describe('no existing aliases', () => {
test
.stdout()
.command(['alias list'])
.it('shows no results', (ctx) => {
expect(ctx.stdout).to.contain('No results');
});
it('shows no results', async () => {
$$.stubAliases({});
const { stdout, result } = await runCommand('alias list');
expect(stdout).to.contain('No results');
expect(result).to.be.empty;
});

test
.stdout()
.command(['alias list', '--json'])
.it('shows no results with --json', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.status).to.equal(0);
expect(response.result.length).to.equal(0);
});
});
it('shows no results with --json', async () => {
$$.stubAliases({});
const { stdout, result } = await runCommand('alias list --json');
const response = JSON.parse(stdout);
expect(response.status).to.equal(0);
expect(response.result.length).to.equal(0);
expect(result).to.be.empty;
});

describe('existing aliases', () => {
beforeEach(async () => {
it('shows existing aliases', async () => {
$$.stubAliases({ Coffee: 'espresso' });
const { result } = await runCommand('alias list');
expect(result).to.deep.equal([
{
alias: 'Coffee',
value: 'espresso',
},
]);
});

test
.stdout()
.command(['alias list', '--json'])
.it('shows results', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.result).to.deep.equal([
{
alias: 'Coffee',
value: 'espresso',
},
]);
});
});
});
27 changes: 13 additions & 14 deletions test/commands/alias/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { expect, test } from '@oclif/test';
import { expect } from 'chai';
import { runCommand } from '@oclif/test';

describe('alias set', () => {
test
.stdout()
.command(['alias set', 'Coffee=espresso', '--json'])
.it('returns new alias', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.result).to.deep.equal([
{
alias: 'Coffee',
success: true,
value: 'espresso',
},
]);
});
it('returns new alias', async () => {
const { stdout } = await runCommand('alias set Coffee=espresso --json');
const response = JSON.parse(stdout);
expect(response.result).to.deep.equal([
{
alias: 'Coffee',
success: true,
value: 'espresso',
},
]);
});
});
43 changes: 19 additions & 24 deletions test/commands/alias/unset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { expect, test } from '@oclif/test';
import { expect } from 'chai';
import { runCommand } from '@oclif/test';
import { TestContext } from '@salesforce/core/testSetup';

describe('alias unset', () => {
Expand All @@ -18,28 +19,22 @@ describe('alias unset', () => {
$$.SANDBOX.restore();
});

test
.stdout()
.command(['alias unset', 'Coffee', '--json'])
.it('removes alias', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.result).to.deep.equal([
{
alias: 'Coffee',
success: true,
value: 'espresso',
},
]);
});
it('removes alias', async () => {
const { result } = await runCommand('alias unset Coffee --json');
expect(result).to.deep.equal([
{
alias: 'Coffee',
success: true,
value: 'espresso',
},
]);
});

test
.stdout()
.command(['alias unset', 'Coffee', 'Bacon', '--json'])
.it('removes multiple aliases', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.result).to.deep.equal([
{ alias: 'Coffee', success: true, value: 'espresso' },
{ alias: 'Bacon', success: true, value: 'breakfast' },
]);
});
it('removes multiple aliases', async () => {
const { result } = await runCommand('alias unset Coffee Bacon --json');
expect(result).to.deep.equal([
{ alias: 'Coffee', success: true, value: 'espresso' },
{ alias: 'Bacon', success: true, value: 'breakfast' },
]);
});
});
Loading
Loading