From 7bfa0dc477d657397dc0ad76778b8dd6481bf9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristina=20Ca=C3=B1izales?= <113132642+CristiCanizales@users.noreply.github.com> Date: Wed, 27 Sep 2023 14:04:08 -0300 Subject: [PATCH 1/4] Cristi/unit tests (#579) * chore: new unit tests * chore: try with lts-1 and lts* * chore: delete old workflow and change references --- .github/workflows/onPushToMain.yml | 4 +- .github/workflows/testCommitExceptMain.yml | 9 ----- .github/workflows/unitTests.yml | 46 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) delete mode 100644 .github/workflows/testCommitExceptMain.yml create mode 100644 .github/workflows/unitTests.yml diff --git a/.github/workflows/onPushToMain.yml b/.github/workflows/onPushToMain.yml index 461b4a26..9f072264 100644 --- a/.github/workflows/onPushToMain.yml +++ b/.github/workflows/onPushToMain.yml @@ -6,7 +6,9 @@ on: jobs: tests: - uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main + uses: ./.github/workflows/unitTests.yml + with: + branch: main release: runs-on: ubuntu-latest needs: diff --git a/.github/workflows/testCommitExceptMain.yml b/.github/workflows/testCommitExceptMain.yml deleted file mode 100644 index 82b7f8a1..00000000 --- a/.github/workflows/testCommitExceptMain.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: unit tests -on: - push: - branches-ignore: [main] - workflow_dispatch: - -jobs: - unit-tests: - uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main \ No newline at end of file diff --git a/.github/workflows/unitTests.yml b/.github/workflows/unitTests.yml new file mode 100644 index 00000000..d8c1f5cc --- /dev/null +++ b/.github/workflows/unitTests.yml @@ -0,0 +1,46 @@ +name: Unit Tests +on: + push: + branches-ignore: [main] + workflow_dispatch: + workflow_call: + inputs: + branch: + type: string + required: false + +jobs: + unit-tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + nodeVersion: [lts/-1, lts/*] + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node_version }} + cache: yarn + - uses: google/wireit@setup-github-actions-caching/v1 + - name: Cache node modules + id: cache-nodemodules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: "**/node_modules" + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }} + + - uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main + if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }} + - run: yarn build + - uses: nick-fields/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd + env: + SF_DISABLE_TELEMETRY: true + name: yarn test + with: + max_attempts: 2 + command: yarn test + timeout_minutes: 60 \ No newline at end of file From d96478d04674c0d63447ffed2bfe6c20b4514c1b Mon Sep 17 00:00:00 2001 From: Dale Bustad Date: Wed, 27 Sep 2023 10:28:22 -0700 Subject: [PATCH 2/4] fix: language server would crash if main class could not be identified (#578) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes forcedotcom/salesforcedx-vscode#4994. Co-authored-by: Cristina CaƱizales <113132642+CristiCanizales@users.noreply.github.com> --- .../src/javascript/__tests__/compiler.test.ts | 30 +++++++++++++++++++ .../src/javascript/type-mapping.ts | 21 +++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/packages/lwc-language-server/src/javascript/__tests__/compiler.test.ts b/packages/lwc-language-server/src/javascript/__tests__/compiler.test.ts index eb1c1a3f..5466182d 100644 --- a/packages/lwc-language-server/src/javascript/__tests__/compiler.test.ts +++ b/packages/lwc-language-server/src/javascript/__tests__/compiler.test.ts @@ -33,6 +33,21 @@ export default class Foo extends LightningElement { @api property = true; } `; +const codeWithoutDefaultExportSingleClass = ` +import { api, LightningElement } from 'lwc'; +class Foo extends LightningElement { + @api foo; +} +`; +const codeWithoutDefaultExportMultipleClasses = ` +import { api, LightningElement } from 'lwc'; +class Foo extends LightningElement { + @api foo; +} +class Bar extends LightningElement { + @api bar; +} +`; it('can get metadata from a simple component', async () => { await compileSource(codeOk, 'foo.js'); @@ -46,6 +61,21 @@ it('displays an error for a component with syntax error', async () => { expect(diagnostic.message).toMatch('Unexpected token (4:17)'); }); +it('returns empty metadata for a script without a clear main component class', async () => { + const result = await compileSource(codeWithoutDefaultExportMultipleClasses, 'foo.js'); + expect(result.metadata?.decorators).toHaveLength(0); + expect(result.metadata?.classMembers).toHaveLength(0); + expect(result.metadata?.exports).toHaveLength(0); +}); + +it('returns metadata for a script with one component class, even when not exported', async () => { + const result = await compileSource(codeWithoutDefaultExportSingleClass, 'foo.js'); + console.log(result); + expect(result.metadata?.decorators).toHaveLength(1); + expect(result.metadata?.classMembers).toHaveLength(1); + expect(result.metadata?.exports).toHaveLength(0); +}); + it('displays an error for a component with other errors', async () => { const result = await compileSource(codeError, 'foo.js'); expect(result.metadata).toBeUndefined(); diff --git a/packages/lwc-language-server/src/javascript/type-mapping.ts b/packages/lwc-language-server/src/javascript/type-mapping.ts index f99b7628..d037f0cb 100644 --- a/packages/lwc-language-server/src/javascript/type-mapping.ts +++ b/packages/lwc-language-server/src/javascript/type-mapping.ts @@ -541,9 +541,24 @@ function getExports(lwcExports: LwcExport[]): InternalModuleExports[] { * LWC language server to analyze code in a user's IDE. */ export function mapLwcMetadataToInternal(lwcMeta: ScriptFile): InternalMetadata { - const mainClassObj = lwcMeta.classes.find(classObj => { - return classObj.id == lwcMeta.mainClass.refId; - }); + let mainClassObj; + if (lwcMeta.mainClass) { + mainClassObj = lwcMeta.classes.find(classObj => { + return classObj.id == lwcMeta.mainClass.refId; + }); + } else if (lwcMeta.classes.length === 1) { + mainClassObj = lwcMeta.classes[0]; + } + + // If we are unable to identify the main class object from the provided metadata, + // it will not be possible calculate decorators, members, etc. + if (!mainClassObj) { + return { + decorators: [], + classMembers: [], + exports: [], + }; + } const defaultExport = lwcMeta.exports.filter((exp) => exp.defaultExport)[0]; const declarationLoc = externalToInternalLoc(defaultExport?.location ?? mainClassObj.location); From 53c027c6c316c7773d396077c64c15d4fd90d9a8 Mon Sep 17 00:00:00 2001 From: Release Bot Date: Wed, 27 Sep 2023 17:35:23 +0000 Subject: [PATCH 3/4] chore(release): v4.7.1 [skip ci] --- lerna.json | 2 +- packages/aura-language-server/package.json | 4 ++-- packages/lightning-lsp-common/package.json | 2 +- packages/lwc-language-server/package.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lerna.json b/lerna.json index 4493f65a..100073fb 100644 --- a/lerna.json +++ b/lerna.json @@ -4,5 +4,5 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "4.7.0" + "version": "4.7.1" } diff --git a/packages/aura-language-server/package.json b/packages/aura-language-server/package.json index a3fa3e57..d295131d 100644 --- a/packages/aura-language-server/package.json +++ b/packages/aura-language-server/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/aura-language-server", - "version": "4.7.0", + "version": "4.7.1", "description": "Language server for Aura components.", "main": "lib/aura-indexer/indexer.js", "typings": "lib/shared.d.ts", @@ -24,7 +24,7 @@ "package": "yarn pack" }, "dependencies": { - "@salesforce/lightning-lsp-common": "4.7.0", + "@salesforce/lightning-lsp-common": "4.7.1", "acorn": "^6.0.0", "acorn-loose": "^6.0.0", "acorn-walk": "^6.0.0", diff --git a/packages/lightning-lsp-common/package.json b/packages/lightning-lsp-common/package.json index bcec50e0..04cd3dec 100644 --- a/packages/lightning-lsp-common/package.json +++ b/packages/lightning-lsp-common/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/lightning-lsp-common", - "version": "4.7.0", + "version": "4.7.1", "description": "Common components for lwc-language-server and aura-language-server.", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/lwc-language-server/package.json b/packages/lwc-language-server/package.json index fd89a6ab..a7c4cfab 100644 --- a/packages/lwc-language-server/package.json +++ b/packages/lwc-language-server/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/lwc-language-server", - "version": "4.7.0", + "version": "4.7.1", "description": "Language server for Lightning Web Components.", "main": "lib/indexer.js", "license": "BSD-3-Clause", @@ -31,7 +31,7 @@ "@lwc/template-compiler": "2.50.0", "@salesforce/apex": "0.0.12", "@salesforce/label": "0.0.12", - "@salesforce/lightning-lsp-common": "4.7.0", + "@salesforce/lightning-lsp-common": "4.7.1", "@salesforce/resourceurl": "0.0.12", "@salesforce/schema": "0.0.12", "@salesforce/user": "0.0.12", From 7a59e3a6ab81b7207f43eff4fc5b033d120377d1 Mon Sep 17 00:00:00 2001 From: gbockus-sf <76090802+gbockus-sf@users.noreply.github.com> Date: Tue, 17 Oct 2023 01:15:04 -0500 Subject: [PATCH 4/4] chore: update validate GHA to enable edit check --- .github/workflows/validatePR.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validatePR.yml b/.github/workflows/validatePR.yml index 3836312a..54015f91 100644 --- a/.github/workflows/validatePR.yml +++ b/.github/workflows/validatePR.yml @@ -1,8 +1,9 @@ name: validate pr on: pull_request: + types: [opened, reopened, edited, synchronize] branches: [main] jobs: pr-validation: - uses: salesforcecli/github-workflows/.github/workflows/validatePR.yml@main \ No newline at end of file + uses: salesforcecli/github-workflows/.github/workflows/validatePR.yml@main