Skip to content

Commit

Permalink
@W-14093557@: Moving tests into reusable composite action.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeingold35 committed Sep 18, 2023
1 parent e47d86d commit 0b99831
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 13 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ jobs:
run: npm install --global @salesforce/cli
- name: Install Code Analyzer
run: sfdx plugins:install @salesforce/sfdx-scanner
# Run the tests. (Linux and non-Linux need slightly different commands.)
- name: 'Run Tests (Linux)'
run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- name: 'Run Tests (non-Linux)'
run: yarn test
if: runner.os != 'Linux'
# Lint, to make sure we're following best practices.
- name: 'Lint'
run: yarn lint
# Run the tests
- name: Run tests
uses: ./github-actions/run-tests
# Upload the code coverage from the test as an artifact with
# the name 'code-coverage-[whatever the OS is]'.
- name: Upload coverage artifact
Expand Down
6 changes: 5 additions & 1 deletion code-fixtures/folder-a/MyClassA2.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
public with sharing class MyClassA2 {}
public with sharing class MyClassA2 {
public static boolean someMethod() {
return false;
}
}
13 changes: 13 additions & 0 deletions github-actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Run Extension Tests'
description: 'Run unit and integration tests'
runs:
using: "composite"
steps:
- name: 'Run Tests (Linux)'
run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- name: 'Run Tests (Non-Linux)'
run: yarn test
if: runner.os != 'Linux'
- name: 'Lint'
run: yarn lint
60 changes: 58 additions & 2 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,66 @@ suite('Extension Test Suite', () => {
}
});

test('sfca.runOnSelected', async function() {
// TODO: Add actual tests for `runOnSelected`.
suite('sfca.runOnSelected', () => {
test('One file selected', async function() {
// ===== SETUP =====
// Set the timeout to a frankly absurd value, just to make sure Github Actions
// can finish it in time.
this.timeout(60000);
// Get the URI for a single file.
const targetUri: vscode.Uri = vscode.Uri.file(path.join(codeFixturesPath, 'folder-a', 'MyClassA1.cls'));

// ===== TEST =====
// Run the "scan selected files" command.
// Pass the URI in as the first parameter, since that's what happens on a single-file selection.
await vscode.commands.executeCommand('sfca.runOnSelected', targetUri, []);

// ===== ASSERTIONS =====
// Verify that we added diagnostics.
const diagnosticArrays = vscode.languages.getDiagnostics();
const [resultsUri, diagnostics] = diagnosticArrays.find(uriDiagPair => uriDiagPair[0].toString() === targetUri.toString());
expect(resultsUri, `Expected diagnostics for ${targetUri.toString()}`).to.exist;
expect(diagnostics, `Expected non-empty diagnostics for ${targetUri.toString()}`).to.not.be.empty;
// At present, we expect only violations for PMD's `ApexDoc` rule.
for (const diagnostic of diagnostics) {
expect(diagnostic.source).to.equal('pmd via Code Analyzer', 'Wrong source');
expect(diagnostic.code).to.have.property('value', 'ApexDoc', 'Wrong rule violated');
}
});

test('One folder selected', () => {
// TODO: IMPLEMENT THIS TEST
});

test('Multiple files selected', async function() {
// ===== SETUP =====
// Set the timeout to a frankly absurd value, just to make sure Github Actions
// can finish it in time.
this.timeout(60000);
// Get the URIs for two separate files.
const targetUri1: vscode.Uri = vscode.Uri.file(path.join(codeFixturesPath, 'folder-a', 'MyClassA1.cls'));
const targetUri2: vscode.Uri = vscode.Uri.file(path.join(codeFixturesPath, 'folder-a', 'MyClassA2.cls'));

// ===== TEST =====
// Run the "scan selected files" command.
// Pass the URIs in as the second parameter, since that's what happens on a multi-select pick.
await vscode.commands.executeCommand('sfca.runOnSelected', null, [targetUri1, targetUri2]);

// ===== ASSERTIONS =====
// Verify that we added diagnostics.
const diagnosticArrays = vscode.languages.getDiagnostics();
const [resultsUri1, diagnostics1] = diagnosticArrays.find(uriDiagPair => uriDiagPair[0].toString() === targetUri1.toString());
const [resultsUri2, diagnostics2] = diagnosticArrays.find(uriDiagPair => uriDiagPair[0].toString() === targetUri2.toString());
expect(resultsUri1, `Expected diagnostics for ${targetUri1.toString()}`).to.exist;
expect(resultsUri2, `Expected diagnostics for ${targetUri2.toString()}`).to.exist;
expect(diagnostics1, `Expected non-empty diagnostics for ${targetUri1.toString()}`).to.not.be.empty;
expect(diagnostics2, `Expected non-empty diagnostics for ${targetUri2.toString()}`).to.not.be.empty;
// At present, we expect only violations for PMD's `ApexDoc` rule.
for (const diagnostic of [...diagnostics1, ...diagnostics2]) {
expect(diagnostic.source).to.equal('pmd via Code Analyzer', 'Wrong source');
expect(diagnostic.code).to.have.property('value', 'ApexDoc', 'Wrong rule violated');
}
});
});

test('sfca.runDfaOnSelected', async () => {
Expand Down

0 comments on commit 0b99831

Please sign in to comment.