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

Shorten command to atgd and add non-unit test #22

Merged
merged 2 commits into from
Oct 21, 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
10 changes: 0 additions & 10 deletions .github/workflows/non-release-build.yml

This file was deleted.

13 changes: 11 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ permissions:
jobs:
unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main

nuts:
needs: unit-tests
uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main
secrets: inherit
strategy:
matrix:
os: [windows-latest]
fail-fast: false
with:
os: ${{ matrix.os }}
release:
needs: [unit-tests]
needs: [unit-tests, nuts]
name: Release
runs-on: ubuntu-latest
steps:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test
on:
push:
branches-ignore:
- main
jobs:
unit-tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main
nuts:
needs: unit-tests
uses: salesforcecli/github-workflows/.github/workflows/nut.yml@main
secrets: inherit
strategy:
matrix:
os: [windows-latest]
fail-fast: false
with:
os: ${{ matrix.os }}
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ AccountTriggerHandlerTest OpportunityTriggerHandlerTest PrepareMySandboxTest Quo

The command's output is designed to be used with the Salesforce CLI (`sf`) deployment command. So when you want to deploy or validate Apex metadata, you can wrap this command with the deploy command to dynamically build the list of specified tests:


```
sf project deploy start -x package/package.xml -l RunSpecifiedTests -t $(sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD")
sf project deploy start -x package/package.xml -l RunSpecifiedTests -t $(sf atgd delta --from "HEAD~1" --to "HEAD")
```

**NOTE:** The test classes will only be added to the output if they are found in one of your package directories as listed in the `sfdx-project.json` in the `--to` commit's file-tree. If the test class name was not found in any package directory, a warning will be printed to the terminal. The plugin will not fail if no test classes are included in the final output. The output and text file will simply be empty if no delta test classes were found in any commit message or no test classes were validated against a package directory.
Expand All @@ -55,17 +54,17 @@ sf plugins install apex-tests-git-delta@x.y.z

The `apex-tests-git-delta` has 1 command:

- `sf apex-tests-git-delta delta`
- `sf atgd delta`

This command needs to be ran somewhere inside your Salesforce DX git repository, whether it's the root folder (recommended) or a subfolder.

This command will determine the root folder of the repo and look for the `sfdx-project.json` file in the root folder.

## `sf apex-tests-git-delta delta`
## `sf atgd delta`

```
USAGE
$ sf apex-tests-git-delta delta -f <value> -t <value> [--json]
$ sf atgd delta -f <value> -t <value> [--json]

FLAGS
-f, --from=<value> Commit SHA from where the commit message log is done. This SHA's commit message will not be included in the results.
Expand All @@ -78,5 +77,5 @@ DESCRIPTION
Given 2 git commits, this plugin will parse all of the commit messages between this range and return the delta Apex test class string. This can be used to execute delta deployments.

EXAMPLES
$ sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD"
$ sf atgd delta --from "HEAD~1" --to "HEAD"
```
2 changes: 1 addition & 1 deletion messages/delta.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Given 2 git commits, this plugin will parse all of the commit messages between t

# examples

- `sf apex-tests-git-delta delta --from "HEAD~1" --to "HEAD"`
- `sf atgd delta --from "HEAD~1" --to "HEAD"`

# flags.from.summary

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"commands": "./lib/commands",
"bin": "sf",
"topicSeparator": " ",
"topics": {
"atgd": {
"description": "description for atgd"
}
},
"devPlugins": [
"@oclif/plugin-help"
],
Expand All @@ -58,7 +63,7 @@
"clean": "sf-clean",
"clean-all": "sf-clean all",
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json oclif.lock",
"compile": "sf-compile",
"compile": "wireit",
"docs": "sf-docs",
"format": "sf-format",
"lint": "wireit",
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions test/commands/delta/delta.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

import { rm } from 'node:fs/promises';

import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';

import { createTemporaryCommit } from './createTemporaryCommit.js';
import { setupTestRepo } from './setupTestRepo.js';

describe('atgd NUTs', () => {
let session: TestSession;
let tempDir: string;
const originalDir = process.cwd();

before(async () => {
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
tempDir = await setupTestRepo();
await createTemporaryCommit(
'chore: initial commit with Apex::TestClass00::Apex',
'force-app/main/default/classes/SandboxTest.cls',
'dummy 1'
);
await createTemporaryCommit(
'chore: initial commit with Apex::SandboxTest::Apex',
'force-app/main/default/classes/TestClass3.cls',
'dummy 11'
);
await createTemporaryCommit(
'chore: adding new tests Apex::TestClass3 TestClass4::Apex',
'packaged/classes/TestClass4.cls',
'dummy 2'
);
});

after(async () => {
await session?.clean();
process.chdir(originalDir);
await rm(tempDir, { recursive: true });
});

it('runs delta command and returns the tests.', async () => {
const command = 'atgd delta --from "HEAD~2" --to "HEAD"';
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;

expect(output.replace('\n', '')).to.equal('SandboxTest TestClass3 TestClass4');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { rm } from 'node:fs/promises';
import { TestContext } from '@salesforce/core/lib/testSetup.js';
import { expect } from 'chai';
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
import ApexTestDelta from '../../../src/commands/apex-tests-git-delta/delta.js';
import ApexTestDelta from '../../../src/commands/atgd/delta.js';
import { createTemporaryCommit } from './createTemporaryCommit.js';
import { setupTestRepo } from './setupTestRepo.js';

describe('return the delta tests between git commits', () => {
describe('atgd unit test', () => {
const $$ = new TestContext();
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
let tempDir: string;
Expand Down
42 changes: 42 additions & 0 deletions test/commands/delta/empty.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

import { rm } from 'node:fs/promises';

import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';

import { createTemporaryCommit } from './createTemporaryCommit.js';
import { setupTestRepo } from './setupTestRepo.js';

describe('atgd empty string NUT', () => {
let session: TestSession;
let fromSha: string;
let toSha: string;
let tempDir: string;
const originalDir = process.cwd();

before(async () => {
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
tempDir = await setupTestRepo();
fromSha = await createTemporaryCommit(
'chore: initial commit',
'force-app/main/default/classes/SandboxTest.cls',
'dummy 1'
);
await createTemporaryCommit('chore: add a class', 'force-app/main/default/classes/TestClass3.cls', 'dummy 11');
toSha = await createTemporaryCommit('chore: add some tests', 'packaged/classes/TestClass4.cls', 'dummy 2');
});

after(async () => {
await session?.clean();
process.chdir(originalDir);
await rm(tempDir, { recursive: true });
});

it('runs delta command and returns no tests.', async () => {
const command = `atgd delta --from "${fromSha}" --to "${toSha}"`;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;

expect(output.replace('\n', '')).to.equal('');
});
});
4 changes: 2 additions & 2 deletions test/commands/delta/empty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { rm } from 'node:fs/promises';
import { TestContext } from '@salesforce/core/lib/testSetup.js';
import { expect } from 'chai';
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
import ApexTestDelta from '../../../src/commands/apex-tests-git-delta/delta.js';
import ApexTestDelta from '../../../src/commands/atgd/delta.js';
import { createTemporaryCommit } from './createTemporaryCommit.js';
import { setupTestRepo } from './setupTestRepo.js';

describe('scan commit messages without the regex and return an empty string.', () => {
describe('atgd unit test - empty string', () => {
const $$ = new TestContext();
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
let fromSha: string;
Expand Down
4 changes: 2 additions & 2 deletions test/commands/delta/warnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { rm } from 'node:fs/promises';
import { TestContext } from '@salesforce/core/lib/testSetup.js';
import { expect } from 'chai';
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
import ApexTestDelta from '../../../src/commands/apex-tests-git-delta/delta.js';
import ApexTestDelta from '../../../src/commands/atgd/delta.js';
import { createTemporaryCommit } from './createTemporaryCommit.js';
import { setupTestRepo } from './setupTestRepo.js';

describe('confirm warnings are generated when files cannot be found in a package directory.', () => {
describe('atgd unit test - warnings', () => {
const $$ = new TestContext();
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
let fromSha: string;
Expand Down