Skip to content

Commit

Permalink
feat!: shorten command to add non-unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Oct 7, 2024
1 parent 9fc0c62 commit 1fb6711
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 23 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/non-release-build.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: tests

on:
push:
branches-ignore: [main]
workflow_dispatch:

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: [ubuntu-latest, windows-latest]
fail-fast: false
with:
os: ${{ matrix.os }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ node_modules

oclif.manifest.json

oclif.lock
oclif.lock

stderr*.txt
stdout*.txt
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 @@ -57,6 +57,11 @@
"devPlugins": [
"@oclif/plugin-help"
],
"topics": {
"acc-transformer": {
"description": "description for transformer command."
}
},
"flexibleTaxonomy": true
},
"scripts": {
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
72 changes: 72 additions & 0 deletions test/commands/transformer/transform.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { copyFile, writeFile, rm, mkdir } from 'node:fs/promises';
import { resolve } from 'node:path';

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

describe('acc transformer 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: 'test/baselines', default: true }],
namespace: '',
sfdcLoginUrl: 'https://login.salesforce.com',
sourceApiVersion: '58.0',
};
const configJsonString = JSON.stringify(configFile, null, 2);

before(async () => {
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');
});

before(async () => {
session = await TestSession.create({ devhubAuthStrategy: 'NONE' });
});

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}`);
});
});
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 1fb6711

Please sign in to comment.