From 7d2d233770c2e083eed15cf3b621d815a3fe7878 Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 13:36:33 -0500 Subject: [PATCH 1/7] do not merge --- src/test/suite/extension.test.ts | 102 +++++++++++++++++-------------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 752bf26..3d30157 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -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); }); @@ -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 ===== @@ -84,7 +92,7 @@ suite('Extension Test Suite', () => { } }); - suite('sfca.runOnSelected', () => { + suite.skip('sfca.runOnSelected', () => { test('One file selected', async function() { // ===== SETUP ===== // Set the timeout to a frankly absurd value, just to make sure Github Actions @@ -146,12 +154,12 @@ suite('Extension Test Suite', () => { }); }); - test('sfca.runDfaOnSelected', async () => { + test.skip('sfca.runDfaOnSelected', async () => { // TODO: Add actual tests for `runDfaOnSelected`. }); }); - suite('#_runAndDisplayPathless()', () => { + suite.skip('#_runAndDisplayPathless()', () => { suite('Error handling', () => { let commandTelemStub: Sinon.SinonStub; let exceptionTelemStub: Sinon.SinonStub; @@ -213,7 +221,7 @@ suite('Extension Test Suite', () => { }); }); - suite('#_runAndDisplayDfa()', () => { + suite.skip('#_runAndDisplayDfa()', () => { suite('Error handling', () => { let commandTelemStub: Sinon.SinonStub; let exceptionTelemStub: Sinon.SinonStub; @@ -279,7 +287,7 @@ suite('Extension Test Suite', () => { }); }); - suite('#verifyPluginInstallation()', () => { + suite.skip('#verifyPluginInstallation()', () => { teardown(() => { Sinon.restore(); }); @@ -323,7 +331,7 @@ suite('Extension Test Suite', () => { }); }); - suite('#_shouldProceedWithDfaRun()', () => { + suite.skip('#_shouldProceedWithDfaRun()', () => { let ext = vscode.extensions.getExtension('salesforce.sfdx-code-analyzer-vscode'); let context: vscode.ExtensionContext; @@ -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); @@ -358,7 +366,7 @@ suite('Extension Test Suite', () => { }); }); - suite('#_stopExistingDfaRun()', () => { + suite.skip('#_stopExistingDfaRun()', () => { let ext = vscode.extensions.getExtension('salesforce.sfdx-code-analyzer-vscode'); let context: vscode.ExtensionContext; @@ -386,7 +394,7 @@ suite('Extension Test Suite', () => { }); }); - suite('#isValidFileForAnalysis', () => { + suite.skip('#isValidFileForAnalysis', () => { test('Returns true for valid files', async() => { // ===== SETUP ===== and ===== ASSERTIONS ===== expect(_isValidFileForAnalysis(vscode.Uri.file("/some/path/file.apex"))).to.equal(true); @@ -403,11 +411,11 @@ suite('Extension Test Suite', () => { }); }); - suite('_clearDiagnosticsForSelectedFiles Test Suite', () => { + suite.skip('_clearDiagnosticsForSelectedFiles 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(); @@ -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'); @@ -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'); @@ -457,10 +465,10 @@ 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); @@ -468,18 +476,18 @@ suite('Extension Test Suite', () => { 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'); @@ -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'); @@ -511,86 +519,86 @@ 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'); }); }); - suite('_removeSingleDiagnostic Test Suite', () => { + suite.skip('_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'); }); }); - + }); From b58d2e08989fcf54d8e9ac3981436af44f347f14 Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 13:43:40 -0500 Subject: [PATCH 2/7] do not merge --- src/lib/sf-cli.ts | 1 + src/test/suite/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/sf-cli.ts b/src/lib/sf-cli.ts index b9f5e98..cba24e3 100644 --- a/src/lib/sf-cli.ts +++ b/src/lib/sf-cli.ts @@ -16,6 +16,7 @@ export class SfCli { * @returns True if {@code sf} or {@code sfdx} is installed. */ public static async isSfCliInstalled(): Promise { + console.log(`isSfCliInstalled path is ${process.env.PATH}`); return new Promise((res) => { const cp = cspawn.spawn('sf', ['-v']); diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index fa3bfeb..55a5782 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -81,9 +81,9 @@ export async function run(): Promise { // 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. From acfabf986cfda9fe3bd3bd65aaf4e8a535933e1a Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 13:53:04 -0500 Subject: [PATCH 3/7] do not merge --- .github/workflows/run-tests.yml | 3 +++ src/test/suite/issue-demonstration.test.ts | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 src/test/suite/issue-demonstration.test.ts diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e5023b0..6ef2214 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -72,6 +72,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 diff --git a/src/test/suite/issue-demonstration.test.ts b/src/test/suite/issue-demonstration.test.ts new file mode 100644 index 0000000..44ab367 --- /dev/null +++ b/src/test/suite/issue-demonstration.test.ts @@ -0,0 +1,7 @@ +import {expect} from 'chai'; + +suite('demoing issue', () => { + test('path is changed', () => { + expect(process.env.PATH).to.contain('/Users/runner/hostedtoolcache/node/20.17.0/arm64/bin'); + }) +}) From 7d333ba7e3b5137922ccd73b90514a86ceddbb9a Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 13:58:12 -0500 Subject: [PATCH 4/7] do not merge --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6ef2214..31bcf89 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 }} From 2c1257e141b57abaa7827da1bf3617dbdaf1f3d8 Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 14:05:19 -0500 Subject: [PATCH 5/7] do not merge --- src/test/suite/extension.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 3d30157..cfadddb 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -92,7 +92,7 @@ suite('Extension Test Suite', () => { } }); - suite.skip('sfca.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 @@ -154,12 +154,12 @@ suite('Extension Test Suite', () => { }); }); - test.skip('sfca.runDfaOnSelected', async () => { + test('sfca.runDfaOnSelected', async () => { // TODO: Add actual tests for `runDfaOnSelected`. }); }); - suite.skip('#_runAndDisplayPathless()', () => { + suite('#_runAndDisplayPathless()', () => { suite('Error handling', () => { let commandTelemStub: Sinon.SinonStub; let exceptionTelemStub: Sinon.SinonStub; @@ -221,7 +221,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('#_runAndDisplayDfa()', () => { + suite('#_runAndDisplayDfa()', () => { suite('Error handling', () => { let commandTelemStub: Sinon.SinonStub; let exceptionTelemStub: Sinon.SinonStub; @@ -287,7 +287,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('#verifyPluginInstallation()', () => { + suite('#verifyPluginInstallation()', () => { teardown(() => { Sinon.restore(); }); @@ -331,7 +331,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('#_shouldProceedWithDfaRun()', () => { + suite('#_shouldProceedWithDfaRun()', () => { let ext = vscode.extensions.getExtension('salesforce.sfdx-code-analyzer-vscode'); let context: vscode.ExtensionContext; @@ -366,7 +366,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('#_stopExistingDfaRun()', () => { + suite('#_stopExistingDfaRun()', () => { let ext = vscode.extensions.getExtension('salesforce.sfdx-code-analyzer-vscode'); let context: vscode.ExtensionContext; @@ -394,7 +394,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('#isValidFileForAnalysis', () => { + suite('#isValidFileForAnalysis', () => { test('Returns true for valid files', async() => { // ===== SETUP ===== and ===== ASSERTIONS ===== expect(_isValidFileForAnalysis(vscode.Uri.file("/some/path/file.apex"))).to.equal(true); @@ -411,7 +411,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('_clearDiagnosticsForSelectedFiles Test Suite', () => { + suite('_clearDiagnosticsForSelectedFiles Test Suite', () => { let diagnosticCollection: vscode.DiagnosticCollection; let runInfo: RunInfo; let getTargetsStub: Sinon.SinonStub; @@ -532,7 +532,7 @@ suite('Extension Test Suite', () => { }); }); - suite.skip('_removeSingleDiagnostic Test Suite', () => { + suite('_removeSingleDiagnostic Test Suite', () => { let diagnosticCollection: vscode.DiagnosticCollection; setup(() => { From 4fe03117430f3389ad762534ef8f5befed201c1d Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 14:11:26 -0500 Subject: [PATCH 6/7] do not merge --- src/test/suite/issue-demonstration.test.ts | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/test/suite/issue-demonstration.test.ts diff --git a/src/test/suite/issue-demonstration.test.ts b/src/test/suite/issue-demonstration.test.ts deleted file mode 100644 index 44ab367..0000000 --- a/src/test/suite/issue-demonstration.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {expect} from 'chai'; - -suite('demoing issue', () => { - test('path is changed', () => { - expect(process.env.PATH).to.contain('/Users/runner/hostedtoolcache/node/20.17.0/arm64/bin'); - }) -}) From fe1f8b479da6da8d889051a1e2cd7d09a2fd7d4a Mon Sep 17 00:00:00 2001 From: Joshua Feingold Date: Thu, 19 Sep 2024 14:17:04 -0500 Subject: [PATCH 7/7] asdfasdf --- src/test/suite/extension.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index cfadddb..f4705e0 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -30,23 +30,23 @@ suite('Extension Test Suite', () => { suiteSetup(async function () { this.timeout(10000); // Activate the extension. - console.log(`pre-activation path is ${process.env.PATH}`); + // console.log((`pre-activation path is ${process.env.PATH}`); context = await ext.activate(); - console.log(`post-activation path is ${process.env.PATH}`); + // console.log((`post-activation path is ${process.env.PATH}`); }); setup(function () { - console.log(`pre-setup path is ${process.env.PATH}`); + // 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}`); + // console.log((`pre-getDiagnostics path is ${process.env.PATH}`); const diagnosticsArrays = vscode.languages.getDiagnostics(); - console.log(`pre-setup-expect path is ${process.env.PATH}`); + // 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}`); + // 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); }); @@ -66,14 +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}`); + // 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}`); + // console.log((`pre-executeCommand path is ${process.env.PATH}`); await vscode.commands.executeCommand('sfca.runOnActiveFile'); // ===== ASSERTIONS =====