Skip to content

Commit

Permalink
fix: update command nut template (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Sep 22, 2022
1 parent aa7542e commit b0c4fce
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 399 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.1.2",
"@oclif/test": "^2.0.3",
"@salesforce/cli-plugins-testkit": "^1.5.0",
"@oclif/test": "^2.1.1",
"@salesforce/cli-plugins-testkit": "^2.4.1",
"@salesforce/dev-config": "^3.0.0",
"@salesforce/dev-scripts": "^2",
"@salesforce/plugin-command-reference": "^2.1.1",
Expand Down Expand Up @@ -128,4 +128,4 @@
"publishConfig": {
"access": "public"
}
}
}
5 changes: 1 addition & 4 deletions templates/test/command.nut.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
*/
<% } %>
import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
import { expect } from 'chai';

describe('<%- cmd %> NUTs', () => {
let session: TestSession;

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});
session = await TestSession.create();
});

after(async () => {
Expand Down
23 changes: 18 additions & 5 deletions test/commands/dev/generate/command.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
import { expect } from 'chai';
import { exec } from 'shelljs';
import { PackageJson } from '../../../../src/types';
import { readJson, fileExists } from '../../../../src/util';

async function setup(repo: string): Promise<TestSession> {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
const session = await TestSession.create({
project: {
gitClone: repo,
Expand Down Expand Up @@ -44,7 +42,7 @@ describe('dev generate command NUTs', () => {
const command = `dev generate command --name ${name} --force --nuts --unit`;

before(async () => {
execCmd(command, { ensureExitCode: 0, cli: 'sf', cwd: session.project.dir });
execCmd(command, { ensureExitCode: 0, cli: 'sf', cwd: session.project.dir, silent: true });
});

it('should generate a command that can be executed', () => {
Expand All @@ -64,7 +62,15 @@ describe('dev generate command NUTs', () => {
const nutFile = path.join(session.project.dir, 'test', 'commands', ...parts, `${cmd}.nut.ts`);
expect(fileExists(nutFile)).to.be.true;

const result = exec('yarn test:nuts', { cwd: session.project.dir, silent: true });
const result = exec('yarn test:nuts', {
cwd: session.project.dir,
silent: true,
env: {
...process.env,
TESTKIT_EXECUTABLE_PATH: pluginExecutable,
},
});

expect(result.code).to.equal(0);
expect(result.stdout).include(`${name.replace(/:/g, ' ')} NUTs`);
});
Expand Down Expand Up @@ -150,7 +156,14 @@ describe('dev generate command NUTs', () => {
const nutFile = path.join(session.project.dir, 'test', 'commands', ...parts, `${cmd}.nut.ts`);
expect(fileExists(nutFile)).to.be.true;

const result = exec('yarn test:nuts', { cwd: session.project.dir, silent: true });
const result = exec('yarn test:nuts', {
cwd: session.project.dir,
silent: true,
env: {
...process.env,
TESTKIT_EXECUTABLE_PATH: pluginExecutable,
},
});
expect(result.code).to.equal(0);
expect(result.stdout).include(`${name.replace(/:/g, ' ')} NUTs`);
});
Expand Down
2 changes: 0 additions & 2 deletions test/commands/dev/generate/hook.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
import { expect } from 'chai';
import { PackageJson } from '../../../../src/types';
import { readJson, fileExists } from '../../../../src/util';
Expand All @@ -15,7 +14,6 @@ describe('dev generate hook NUTs', () => {
let session: TestSession;

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({
project: {
gitClone: 'https://github.com/salesforcecli/plugin-template-sf.git',
Expand Down
Loading

0 comments on commit b0c4fce

Please sign in to comment.