Skip to content

Commit

Permalink
Merge pull request #44 from mcarvin8/feat/shorten-cmd
Browse files Browse the repository at this point in the history
Shorten Command to Allow Non-Unit Test (NUT)
  • Loading branch information
mcarvin8 authored Oct 21, 2024
2 parents 9fc0c62 + f3cea45 commit 9252334
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 24 deletions.
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
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ sf plugins install [email protected]

The `apex-code-coverage-transformer` has 1 command:

- `sf apex-code-coverage transformer transform`
- `sf acc-transformer transform`

This command needs to be ran somewhere inside your Salesforce DX git repository, whether in the root folder (recommended) or in a subfolder. This plugin will determine the root folder of this repository and read the `sfdx-project.json` file in the root folder. All package directories listed in the `sfdx-project.json` file will be processed when running this plugin.

## `sf apex-code-coverage transformer transform`
## `sf acc-transformer transform`

```
USAGE
$ sf apex-code-coverage transformer transform -j <value> -x <value> -c <value> [--json]
$ sf acc-transformer transform -j <value> -x <value> -c <value> [--json]
FLAGS
-j, --coverage-json=<value> Path to the code coverage JSON file created by the Salesforce CLI deployment or test command.
Expand All @@ -57,7 +57,7 @@ DESCRIPTION
This plugin will convert the code coverage JSON file created by the Salesforce CLI during Apex deployments and test runs into an XML accepted by tools like SonarQube.
EXAMPLES
$ sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"
$ sf acc-transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"
```

## Hook
Expand Down
2 changes: 1 addition & 1 deletion messages/transformer.transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This plugin will convert the code coverage JSON file created by the Salesforce C

# examples

- `sf apex-code-coverage transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"`
- `sf acc-transformer transform -j "coverage.json" -x "coverage.xml" -c "deploy"`

# flags.coverage-json.summary

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"commands": "./lib/commands",
"bin": "sf",
"topicSeparator": " ",
"topics": {
"acc-transformer": {
"description": "description for acc-transformer"
}
},
"hooks": {
"postrun": "./lib/hooks/postrun"
},
Expand All @@ -65,7 +70,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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { writeFile, readFile } from 'node:fs/promises';

import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { DeployCoverageData, TestCoverageData } from '../../../helpers/types.js';
import { transformDeployCoverageReport } from '../../../helpers/transformDeployCoverageReport.js';
import { transformTestCoverageReport } from '../../../helpers/transformTestCoverageReport.js';
import { TransformerTransformResult } from '../../../helpers/types.js';
import { DeployCoverageData, TestCoverageData, TransformerTransformResult } from '../../helpers/types.js';
import { transformDeployCoverageReport } from '../../helpers/transformDeployCoverageReport.js';
import { transformTestCoverageReport } from '../../helpers/transformTestCoverageReport.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('apex-code-coverage-transformer', 'transformer.transform');
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/postrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { Hook } from '@oclif/core';

import TransformerTransform from '../commands/apex-code-coverage/transformer/transform.js';
import TransformerTransform from '../commands/acc-transformer/transform.js';
import { ConfigFile } from '../helpers/types.js';
import { getRepoRoot } from '../helpers/getRepoRoot.js';

Expand Down
86 changes: 86 additions & 0 deletions test/commands/acc-transformer/transform.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

import { copyFile, writeFile, readFile, rm, mkdir } from 'node:fs/promises';
import { strictEqual } from 'node:assert';
import { resolve } from 'node:path';

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

describe('acc-transformer transform NUTs', () => {
let session: TestSession;
const baselineClassPath = resolve('test/baselines/classes/AccountProfile.cls');
const baselineTriggerPath = resolve('test/baselines/triggers/AccountTrigger.trigger');
const deployCoverageNoExts = resolve('test/deploy_coverage_no_file_exts.json');
const deployCoverageWithExts = resolve('test/deploy_coverage_with_file_exts.json');
const testCoverage = resolve('test/test_coverage.json');
const baselineXmlPath = resolve('test/coverage_baseline.xml');
const testXmlPath1 = resolve('coverage1.xml');
const testXmlPath2 = resolve('coverage2.xml');
const testXmlPath3 = resolve('coverage3.xml');

const configFile = {
packageDirectories: [{ path: 'force-app', default: true }, { path: 'packaged' }],
namespace: '',
sfdcLoginUrl: 'https://login.salesforce.com',
sourceApiVersion: '58.0',
};
const configJsonString = JSON.stringify(configFile, null, 2);

before(async () => {
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
await writeFile('sfdx-project.json', configJsonString);
await mkdir('force-app/main/default/classes', { recursive: true });
await mkdir('packaged/triggers', { recursive: true });
await copyFile(baselineClassPath, 'force-app/main/default/classes/AccountProfile.cls');
await copyFile(baselineTriggerPath, 'packaged/triggers/AccountTrigger.trigger');
});

after(async () => {
await session?.clean();
await rm('sfdx-project.json');
await rm('force-app/main/default/classes/AccountProfile.cls');
await rm('packaged/triggers/AccountTrigger.trigger');
await rm('force-app', { recursive: true });
await rm('packaged', { recursive: true });
await rm(testXmlPath1);
await rm(testXmlPath2);
await rm(testXmlPath3);
});

it('runs transform on the deploy coverage file without file extensions.', async () => {
const command = `acc-transformer transform --coverage-json "${deployCoverageNoExts}" --xml "${testXmlPath1}"`;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;

expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath1}`);
});

it('runs transform on the deploy coverage file with file extensions.', async () => {
const command = `acc-transformer transform --coverage-json "${deployCoverageWithExts}" --xml "${testXmlPath2}"`;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;

expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath2}`);
});

it('runs transform on the test coverage file.', async () => {
const command = `acc-transformer transform --coverage-json "${testCoverage}" --xml "${testXmlPath3}"`;
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout;

expect(output.replace('\n', '')).to.equal(`The coverage XML has been written to ${testXmlPath3}`);
});
it('confirm the 2 XML files created in the previous tests are the same as the baseline.', async () => {
const xmlContent1 = await readFile(testXmlPath1, 'utf-8');
const xmlContent2 = await readFile(testXmlPath2, 'utf-8');
const baselineXmlContent = await readFile(baselineXmlPath, 'utf-8');
strictEqual(
xmlContent1,
baselineXmlContent,
`File content is different between ${testXmlPath1} and ${baselineXmlPath}`
);
strictEqual(
xmlContent2,
baselineXmlContent,
`File content is different between ${testXmlPath2} and ${baselineXmlPath}`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { resolve } from 'node:path';
import { TestContext } from '@salesforce/core/lib/testSetup.js';
import { expect } from 'chai';
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
import TransformerTransform from '../../../src/commands/apex-code-coverage/transformer/transform.js';
import TransformerTransform from '../../../src/commands/acc-transformer/transform.js';

describe('main', () => {
const $$ = new TestContext();
Expand Down

0 comments on commit 9252334

Please sign in to comment.