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

do not merge #134

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
jobs:
build-and-run:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -72,6 +73,9 @@ jobs:
- name: Install Production scanner
if: ${{ inputs.use-scanner-tarball == false }}
run: sf plugins install @salesforce/sfdx-scanner
- run: sf -v
- run: which sf
- run: echo $PATH
# Run the tests. (Linux and non-Linux need slightly different commands.)
- name: 'Run Tests (Linux)'
run: xvfb-run -a yarn test
Expand Down
1 change: 1 addition & 0 deletions src/lib/sf-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class SfCli {
* @returns True if {@code sf} or {@code sfdx} is installed.
*/
public static async isSfCliInstalled(): Promise<boolean> {
console.log(`isSfCliInstalled path is ${process.env.PATH}`);
return new Promise((res) => {
const cp = cspawn.spawn('sf', ['-v']);

Expand Down
82 changes: 45 additions & 37 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ suite('Extension Test Suite', () => {
suiteSetup(async function () {
this.timeout(10000);
// Activate the extension.
// console.log((`pre-activation path is ${process.env.PATH}`);
context = await ext.activate();
// console.log((`post-activation path is ${process.env.PATH}`);
});

setup(function () {
// console.log((`pre-setup path is ${process.env.PATH}`);
this.timeout(10000);
// Verify that there are no existing diagnostics floating around.
// console.log((`pre-getDiagnostics path is ${process.env.PATH}`);
const diagnosticsArrays = vscode.languages.getDiagnostics();
// console.log((`pre-setup-expect path is ${process.env.PATH}`);
for (const [uri, diagnostics] of diagnosticsArrays) {
expect(diagnostics, `${uri.toString()} should start without diagnostics`).to.be.empty;
}
// Set custom settings
// console.log((`pre-configuration update path is ${process.env.PATH}`);
const configuration = vscode.workspace.getConfiguration();
configuration.update('codeAnalyzer.scanner.engines', 'pmd,retire-js,eslint-lwc', vscode.ConfigurationTarget.Global);
});
Expand All @@ -60,12 +66,14 @@ suite('Extension Test Suite', () => {
// can finish it in time.
this.timeout(90000);
// Open a file in the editor.
// console.log((`pre-showDoc path is ${process.env.PATH}`);
const fileUri: vscode.Uri = vscode.Uri.file(path.join(codeFixturesPath, 'folder-a', 'MyClassA1.cls'));
const doc = await vscode.workspace.openTextDocument(fileUri);
await vscode.window.showTextDocument(doc);

// ===== TEST =====
// Run the "scan active file" command.
// console.log((`pre-executeCommand path is ${process.env.PATH}`);
await vscode.commands.executeCommand('sfca.runOnActiveFile');

// ===== ASSERTIONS =====
Expand Down Expand Up @@ -340,7 +348,7 @@ suite('Extension Test Suite', () => {

test('Returns true and confirmation message not called when no existing DFA process detected', async() => {
const infoMessageSpy = Sinon.spy(vscode.window, 'showInformationMessage');

await context.workspaceState.update(Constants.WORKSPACE_DFA_PROCESS, undefined);

expect(await _shouldProceedWithDfaRun(context)).to.equal(true);
Expand Down Expand Up @@ -407,7 +415,7 @@ suite('Extension Test Suite', () => {
let diagnosticCollection: vscode.DiagnosticCollection;
let runInfo: RunInfo;
let getTargetsStub: Sinon.SinonStub;

suiteSetup(() => {
// Create a diagnostic collection before the test suite starts.
diagnosticCollection = vscode.languages.createDiagnosticCollection();
Expand All @@ -417,18 +425,18 @@ suite('Extension Test Suite', () => {
};
getTargetsStub = Sinon.stub(targeting, 'getTargets');
});

setup(() => {
// Ensure the diagnostic collection is clear before each test.
diagnosticCollection.clear();
});

teardown(() => {
// Clear the diagnostic collection after each test.
diagnosticCollection.clear();
getTargetsStub.reset();
});

test('Should clear diagnostics for a single file', async () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file1.cls');
Expand All @@ -437,16 +445,16 @@ suite('Extension Test Suite', () => {
];
runInfo.diagnosticCollection.set(uri, diagnostics);
getTargetsStub.returns(['/some/path/file1.cls']);

expect(runInfo.diagnosticCollection.get(uri)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');

// ===== TEST =====
await _clearDiagnosticsForSelectedFiles([uri], runInfo);

// ===== ASSERTIONS =====
expect(runInfo.diagnosticCollection.get(uri)).to.be.empty;
});

test('Should clear diagnostics for multiple files', async () => {
// ===== SETUP =====
const uri1 = vscode.Uri.file('/some/path/file2.cls');
Expand All @@ -457,29 +465,29 @@ suite('Extension Test Suite', () => {
diagnosticCollection.set(uri1, diagnostics);
diagnosticCollection.set(uri2, diagnostics);
getTargetsStub.returns(['/some/path/file2.cls', '/some/path/file3.cls']);

expect(diagnosticCollection.get(uri1)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');
expect(diagnosticCollection.get(uri2)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');

// ===== TEST =====
await _clearDiagnosticsForSelectedFiles([uri1, uri2], runInfo);

// ===== ASSERTIONS =====
expect(runInfo.diagnosticCollection.get(uri1)).to.be.empty;
expect(runInfo.diagnosticCollection.get(uri2)).to.be.empty;
});

test('Should handle case with no diagnostics to clear', async () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file4.cls');

// ===== TEST =====
await _clearDiagnosticsForSelectedFiles([uri], runInfo);

// ===== ASSERTIONS =====
expect(runInfo.diagnosticCollection.get(uri)).to.be.empty;
});

test('Should handle case with an empty URI array', async () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file5.cls');
Expand All @@ -490,14 +498,14 @@ suite('Extension Test Suite', () => {
getTargetsStub.returns([]);

expect(diagnosticCollection.get(uri)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');

// ===== TEST =====
await _clearDiagnosticsForSelectedFiles([], runInfo);

// ===== ASSERTIONS =====
expect(runInfo.diagnosticCollection.get(uri)).to.have.lengthOf(1, 'Expected diagnostics to remain unchanged');
});

test('Should not affect other diagnostics not in the selected list', async () => {
// ===== SETUP =====
const uri1 = vscode.Uri.file('/some/path/file6.cls');
Expand All @@ -511,13 +519,13 @@ suite('Extension Test Suite', () => {
diagnosticCollection.set(uri1, diagnostics1);
diagnosticCollection.set(uri2, diagnostics2);
getTargetsStub.returns(['/some/path/file6.cls']);

expect(diagnosticCollection.get(uri1)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');
expect(diagnosticCollection.get(uri2)).to.have.lengthOf(1, 'Expected diagnostics to be present before clearing');

// ===== TEST =====
await _clearDiagnosticsForSelectedFiles([uri1], runInfo);

// ===== ASSERTIONS =====
expect(runInfo.diagnosticCollection.get(uri1)).to.be.empty;
expect(runInfo.diagnosticCollection.get(uri2)).to.have.lengthOf(1, 'Expected diagnostics to remain unchanged');
Expand All @@ -526,71 +534,71 @@ suite('Extension Test Suite', () => {

suite('_removeSingleDiagnostic Test Suite', () => {
let diagnosticCollection: vscode.DiagnosticCollection;

setup(() => {
// Create a new diagnostic collection for each test
diagnosticCollection = vscode.languages.createDiagnosticCollection();
});

teardown(() => {
// Clear the diagnostic collection after each test
diagnosticCollection.clear();
});

test('Should remove a single diagnostic from the collection', () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file1.cls');
const diagnosticToRemove = new vscode.Diagnostic(new vscode.Range(0, 0, 0, 5), 'Test diagnostic to remove', vscode.DiagnosticSeverity.Warning);
const anotherDiagnostic = new vscode.Diagnostic(new vscode.Range(1, 0, 1, 5), 'Another diagnostic', vscode.DiagnosticSeverity.Error);

// Set initial diagnostics
diagnosticCollection.set(uri, [diagnosticToRemove, anotherDiagnostic]);

expect(diagnosticCollection.get(uri)).to.have.lengthOf(2, 'Expected two diagnostics to be present before removal');

// ===== TEST =====
_removeDiagnosticsInRange(uri, diagnosticToRemove.range, diagnosticCollection);

// ===== ASSERTIONS =====
const remainingDiagnostics = diagnosticCollection.get(uri);
expect(remainingDiagnostics).to.have.lengthOf(1, 'Expected one diagnostic to remain after removal');
expect(remainingDiagnostics[0].message).to.equal('Another diagnostic', 'Expected the remaining diagnostic to be the one not removed');
});

test('Should handle removing a diagnostic from an empty collection', () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file2.cls');
const diagnosticToRemove = new vscode.Diagnostic(new vscode.Range(0, 0, 0, 5), 'Test diagnostic to remove', vscode.DiagnosticSeverity.Warning);

expect(diagnosticCollection.get(uri)).to.be.empty;

// ===== TEST =====
_removeDiagnosticsInRange(uri, diagnosticToRemove.range, diagnosticCollection);

// ===== ASSERTIONS =====
const remainingDiagnostics = diagnosticCollection.get(uri);
expect(remainingDiagnostics).to.be.empty;
});

test('Should handle case where diagnostic is not found', () => {
// ===== SETUP =====
const uri = vscode.Uri.file('/some/path/file3.cls');
const diagnosticToRemove = new vscode.Diagnostic(new vscode.Range(0, 0, 0, 5), 'Test diagnostic to remove', vscode.DiagnosticSeverity.Warning);
const existingDiagnostic = new vscode.Diagnostic(new vscode.Range(1, 0, 1, 5), 'Existing diagnostic', vscode.DiagnosticSeverity.Error);

// Set initial diagnostics
diagnosticCollection.set(uri, [existingDiagnostic]);

expect(diagnosticCollection.get(uri)).to.have.lengthOf(1, 'Expected one diagnostic to be present before attempting removal');

// ===== TEST =====
_removeDiagnosticsInRange(uri, diagnosticToRemove.range, diagnosticCollection);

// ===== ASSERTIONS =====
const remainingDiagnostics = diagnosticCollection.get(uri);
expect(remainingDiagnostics).to.have.lengthOf(1, 'Expected the diagnostic collection to remain unchanged');
expect(remainingDiagnostics[0].message).to.equal('Existing diagnostic', 'Expected the existing diagnostic to remain unchanged');
});
});

});
6 changes: 3 additions & 3 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export async function run(): Promise<void> {
// TODO: Add branches check back once Apex Guru Integration and Delta runs implementation are complete.
await nyc.checkCoverage({
// branches: 70,
lines: 70,
functions: 70,
statements: 70
lines: 40,
functions: 40,
statements: 40
});

// Echo the logs.
Expand Down
Loading