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

test(quantic): support e2e testing with LWS and with Locker Service with Playwright #4711

Merged
merged 26 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
df27efb
added logic to support creating two testing orgs, one with LWS and on…
mmitiche Nov 25, 2024
9714af9
file reverted
mmitiche Nov 25, 2024
41276a3
file reverted
mmitiche Nov 25, 2024
29ed5a9
starting to run plawright tests on quantic E2E workflow
mmitiche Nov 25, 2024
6e0aaea
install script fixed
mmitiche Nov 25, 2024
6b7e9b2
handling cache loging added
mmitiche Nov 26, 2024
181ed10
issue fixed
mmitiche Nov 26, 2024
3c4ee33
improved quantic e2e workflow
mmitiche Nov 26, 2024
8510ae5
unused line deleted
mmitiche Nov 26, 2024
b20a669
Merge branch 'master' of https://github.com/coveo/ui-kit into SFINT-5796
mmitiche Nov 26, 2024
b45baa7
unused line deleted
mmitiche Nov 26, 2024
855d144
falling test on purpose
mmitiche Nov 26, 2024
f872da7
test fixed
mmitiche Nov 27, 2024
00a5804
test fixed
mmitiche Nov 27, 2024
b711d5a
updated artifact
mmitiche Nov 27, 2024
14848f7
updated artifact
mmitiche Nov 27, 2024
d55028e
readme file updated
mmitiche Nov 27, 2024
af41bb2
Merge branch 'master' into SFINT-5796
mmitiche Nov 27, 2024
b141929
readme file updated
mmitiche Nov 27, 2024
2d1fbc0
Merge branch 'SFINT-5796' of https://github.com/coveo/ui-kit into SFI…
mmitiche Nov 27, 2024
fda5c2c
Update packages/quantic/README.md
mmitiche Nov 28, 2024
4d54953
Update packages/quantic/scripts/build/util/scratchOrgDefUtils.ts
mmitiche Dec 2, 2024
d1d7c4e
Update packages/quantic/scripts/build/util/scratchOrgDefUtils.ts
mmitiche Dec 2, 2024
42b7e22
Update packages/quantic/scripts/build/util/scratchOrgDefUtils.ts
mmitiche Dec 2, 2024
ce8954a
Merge branch 'master' of https://github.com/coveo/ui-kit into SFINT-5796
mmitiche Dec 3, 2024
726d120
Merge branch 'master' into SFINT-5796
mmitiche Dec 4, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Quantic E2E tests'
name: 'Quantic Cypress E2E tests'
description: 'Runs Cypress tests for Quantic'
inputs:
github-token:
Expand Down
20 changes: 20 additions & 0 deletions .github/actions/e2e-quantic-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Quantic Playwright E2E tests'
description: 'Runs Playwright tests for Quantic'
runs:
using: composite
steps:
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: packages/quantic/.env
key: quantic-playwright-env-${{ github.sha }}
- name: Run Playwright Tests
run: |
npx playwright install --with-deps
npx playwright test
shell: bash
working-directory: ./packages/quantic
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
name: quantic-playwright-report
path: packages/quantic/playwright-report
retention-days: 5
7 changes: 6 additions & 1 deletion .github/actions/e2e-quantic-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ runs:
shell: bash
- run: |
echo "${{ inputs.jwtkey }}" > server.key
npx --no-install ts-node scripts/build/deploy-community.ts --ci
npx --no-install ts-node scripts/build/deploy-community.ts --ci --scratch-org-def-path=./config/lws-disabled-scratch-def.json
npx --no-install ts-node scripts/build/deploy-community.ts --ci --scratch-org-def-path=./config/lws-enabled-scratch-def.json
rm server.key
shell: bash
working-directory: ./packages/quantic
Expand All @@ -28,3 +29,7 @@ runs:
with:
path: packages/quantic/cypress/plugins/config
key: quantic-cypress-config-${{ github.sha }}
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: packages/quantic/.env
key: quantic-playwright-env-${{ github.sha }}
26 changes: 21 additions & 5 deletions .github/workflows/e2e-quantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
with:
clientid: ${{ secrets.SFDX_AUTH_CLIENT_ID }}
jwtkey: ${{ secrets.SFDX_AUTH_JWT_KEY }}
e2e-quantic-test:
name: 'Run e2e tests on Quantic'
e2e-quantic-cypress-test:
name: 'Run Cypress e2e tests on Quantic'
needs: e2e-quantic-setup
runs-on: ubuntu-latest
strategy:
Expand All @@ -44,12 +44,25 @@ jobs:

- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: ./.github/actions/setup
- uses: ./.github/actions/e2e-quantic
- uses: ./.github/actions/e2e-quantic-cypress
with:
spec: ${{ matrix.spec }}
e2e-quantic-playwright-test:
name: 'Run Playwright e2e tests on Quantic'
needs: e2e-quantic-cypress-test
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit

- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: ./.github/actions/setup
- uses: ./.github/actions/e2e-quantic-playwright
e2e-quantic-cleanup:
if: cancelled() || failure() || success()
needs: e2e-quantic-test
needs: e2e-quantic-playwright-test
runs-on: ubuntu-latest
steps:
- name: Harden Runner
Expand All @@ -60,5 +73,8 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: ./.github/actions/setup
- uses: ./.github/actions/setup-sfdx
- run: npx --no-install ts-node packages/quantic/scripts/build/delete-org.ts
- run: |
npx --no-install ts-node scripts/build/delete-org.ts --scratch-org-def-path=./config/lws-disabled-scratch-def.json
npx --no-install ts-node scripts/build/delete-org.ts --scratch-org-def-path=./config/lws-enabled-scratch-def.json
shell: bash
working-directory: ./packages/quantic
64 changes: 52 additions & 12 deletions packages/quantic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,64 @@ Or you can run the individual commands below.
- Make sure you are in the `packages/quantic` root folder.
- Run this command to create the default scratch org. `npm run scratch:create`.
- In VS Code, press Command + Shift P, enter sfdx, and select SFDX: Create a Default Scratch Org.
- You can also run this command from the command line. `sf org create scratch --set-default --definition-file config/project-scratch-def.json --alias "LWC"`
- `LWC` is an alias for the scratch org that you can use in other Salesforce CLI commands. You can create any alias that you like.
- You can also run this command from the command line. `sf org create scratch --set-default --definition-file config/lws-enabled-scratch-def.json --alias Quantic__LWS_enabled`
- `Quantic__LWS_enabled` is an alias for the scratch org that you can use in other Salesforce CLI commands. You can create any alias that you like.

#### Deploy the Quantic code

- Run this command from the command line. `sf project deploy start --source-dir force-app/main`.

## Testing

### Deploy the Quantic Examples Community
### Deploy the Quantic Examples Communities

Example components are available as a Salesforce community (Digital Experience) allowing you to experiment with Quantic components.
Example components are available as Salesforce communities (Digital Experiences), allowing you to experiment with Quantic components in two separate environments: one with Lightning Web Security (LWS) enabled and one with LWS disabled.

To setup the community in the `LWC` scratch org, run:
To set up both communities in scratch orgs, run:

```bash
npm run setup:examples
```

This script creates, configures, and deploys everything required to have fully working examples. The community URL is provided at the end of the script output, as in the following example:
This script creates, configures, and deploys everything required to have fully working examples in **two scratch orgs**:

- An org with **LWS enabled**.
- An org with **LWS disabled**.

At the end of the script, the URLs for the two communities are provided, as in the following example:

```
...

The 'Quantic Examples' community is ready, you can access it at the following URL:
https://your-salesforce-scratch-org-instance.force.com/examples
The 'Quantic Examples' community (LWS enabled) is ready, you can access it at the following URL:
https://your-salesforce-lws-enabled-scratch-org-instance.force.com/examples

The 'Quantic Examples' community (LWS disabled) is ready, you can access it at the following URL:
https://your-salesforce-lws-disabled-scratch-org-instance.force.com/examples

To open Cypress, run:
npm run e2e:watch
```

Once the community has been deployed, you can deploy the `main` or `example` components only when needed. To do so, run:
Once the community has been deployed, you can deploy the `main` or `example` components to a specific org only when needed by running the corresponding commands:

```bash
npm run deploy:main --target-org Quantic__LWS_enabled
npm run deploy:examples --target-org Quantic__LWS_enabled
```

You can replace Quantic\_\_LWS_enabled with your target org alias. For example:

```bash
npm run deploy:main
npm run deploy:examples
npm run deploy:main --target-org MyCustomOrg
npm run deploy:examples --target-org MyCustomOrg
```

### Run Cypress for Quantic Components

**Note** Before attempting to run [Cypress](https://docs.cypress.io) tests, make sure the `Quantic Examples` community is deployed as described in the previous section.

**Note** Cypress tests run on the org with **LWS enabled**, aliased as `Quantic__LWS_enabled`.

To learn how to add tests, see [adding tests](./docs/adding-tests.md).

- All the tests will need to be under folder `cypress/integration`.
Expand All @@ -119,6 +135,30 @@ To get the [detailed report](./docs/detailed-reporting.md), run:
npm run e2e:detailed
```

### Run Playwright for Quantic Components

**Note** Before attempting to run [Playwright](https://playwright.dev/) tests, make sure the `Quantic Examples` community is deployed as described in the previous section in both orgs, the one where LWS is enabled and the one where it is disabled.

**Note** For more information on how to add tests, please refer to our [Quantic Testing Strategy](https://github.com/coveo/ui-kit/blob/master/packages/quantic/decisions/0001-testing-strategy.md), which provides detailed guidelines on testing Quantic components.

To run Playwright tests, run:

```bash
npm run e2e:playwright:
```

To run Playwright tests only for the scratch org where LWS is enabled, run:

```bash
npm run e2e:playwright:lws-enabled
```

To run Playwright tests only for the scratch org where LWS is disabled, run:

```bash
npm run e2e:playwright:lws-disabled
```

### Run LWC unit tests for Quantic Components

To run LWC unit tests directly in your console, run:
Expand Down
22 changes: 22 additions & 0 deletions packages/quantic/config/lws-disabled-scratch-def.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"orgName": "Quantic__LWS_disabled",
"edition": "Developer",
"features": ["Communities"],
"settings": {
"experienceBundleSettings": {
"enableExperienceBundleMetadata": true
},
"communitiesSettings": {
"enableNetworksEnabled": true
},
"languageSettings": {
"enableTranslationWorkbench": true,
"enableEndUserLanguages": true
},
"securitySettings": {
"sessionSettings": {
"lockerServiceNext": false
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"orgName": "quantic local",
"orgName": "Quantic__LWS_enabled",
"edition": "Developer",
"features": ["Communities"],
"settings": {
Expand All @@ -12,6 +12,11 @@
"languageSettings": {
"enableTranslationWorkbench": true,
"enableEndUserLanguages": true
},
"securitySettings": {
"sessionSettings": {
"lockerServiceNext": true
}
}
}
}
8 changes: 5 additions & 3 deletions packages/quantic/docs/adding-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Let's say you just finished coding a `quantic-greeting` component, which display
<!-- Which outputs: Hello Alex! -->
```

**Note**: The following example assumes all steps are performed on a scratch org aliased as `Quantic__LWS_enabled`.

## Update the Quantic Examples Community

Now, say that you wish to make this component available in the `Quantic Examples` community. Further, say you want to add end to end tests to prevent any regression. To achieve that, you want a community page containing your example component, and a configuration panel allowing users to modify the component's options. In this case, you want to test the `name` option.
Expand Down Expand Up @@ -99,21 +101,21 @@ Next, execute the following steps:
1. Deploy the example components to your org.

```bash
npm run deploy:examples
npm run deploy:examples --target-org Quantic__LWS_enabled
```

2. Open the community builder, then create a `Quantic Greeting` page and drop your `exampleQuanticGreeting` component into it. Don't forget to also update the community home page to add a link to your page.

3. Publish your changes and validate that everything works as expected.

```
sf community publish --target-org LWC --name "Quantic Examples"
sf community publish --target-org Quantic__LWS_enabled --name "Quantic Examples"
```

It is now time to backup the changes you made to the community. Run:

```bash
sf project retrieve start --target-org LWC --manifest quantic-examples-community/package.xml --output-dir temp --wait 10
sf project retrieve start --target-org Quantic__LWS_enabled --manifest quantic-examples-community/package.xml --output-dir temp --wait 10
```

Executing this command will download the community metadata from your org and save it as `temp/unpackaged.zip`.
Expand Down
14 changes: 9 additions & 5 deletions packages/quantic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
"e2e:watch": "cypress open --browser chrome --e2e",
"e2e": "cypress run --browser chrome",
"e2e:detailed": "cypress run --browser chrome --headless --reporter cypress/reporters/detailed-reporter.js",
"scratch:create": "sf org create scratch --set-default --definition-file config/project-scratch-def.json --alias \"LWC\"",
"setup:examples": "../../node_modules/.bin/ts-node scripts/build/deploy-community.ts",
"deploy:main": "sf project deploy start --target-org LWC --source-dir force-app/main",
"deploy:examples": "sf project deploy start --target-org LWC --source-dir force-app/examples",
"scratch:dev": "npm run scratch:create && npm run deploy:main && npm run setup:examples",
"e2e:playwright": "npx playwright test",
"e2e:playwright:lws-enabled": "npx playwright test --project=LWS-enabled",
"e2e:playwright:lws-disabled": "npx playwright test --project=LWS-disabled",
"scratch:create": "sf org create scratch --set-default --definition-file config/lws-enabled-scratch-def.json --alias Quantic__LWS_enabled",
"setup:examples": "npm run create:lws-enabled && npm run create:lws-disabled",
"create:lws-enabled": "../../node_modules/.bin/ts-node scripts/build/deploy-community.ts --scratch-org-def-path=./config/lws-enabled-scratch-def.json",
"create:lws-disabled": "../../node_modules/.bin/ts-node scripts/build/deploy-community.ts --scratch-org-def-path=./config/lws-disabled-scratch-def.json",
"deploy:main": "sf project deploy start --source-dir force-app/main --target-org",
"deploy:examples": "sf project deploy start --source-dir force-app/examples --target-org",
"prebuild:doc": "mkdirp docs/out",
"build:doc": "jsdoc -c jsdoc-config.json",
"publish:sfdx": "../../node_modules/.bin/ts-node scripts/build/create-package.ts --remove-translations",
Expand Down
26 changes: 12 additions & 14 deletions packages/quantic/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@ export default defineConfig({
: [['html'], ['list']],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASE_URL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {...devices['Desktop Chrome']},
name: 'LWS-enabled',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.Quantic__LWS_enabled_URL,
},
},
{
name: 'LWS-disabled',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.Quantic__LWS_disabled_URL,
},
},
// {
// name: 'firefox',
// use: {...devices['Desktop Firefox']},
// },
// {
// name: 'webkit',
// use: {...devices['Desktop Safari']},
// },
],
});
14 changes: 10 additions & 4 deletions packages/quantic/scripts/build/delete-org.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {StepLogger, StepsRunner} from './util/log';
import {
getOrgNameFromScratchDefFile,
getScratchOrgDefPath,
} from './util/scratchOrgDefUtils';
import * as sfdx from './util/sfdx-commands';

interface Options {
Expand All @@ -22,11 +26,13 @@ const resetOrgAlias = async (log: StepLogger, options: Options) => {
};

(async function () {
const options = {
alias: 'LWC',
};

try {
const scratchOrgDefPath = getScratchOrgDefPath(process.argv);
const orgName = getOrgNameFromScratchDefFile(scratchOrgDefPath);
const options = {
alias: orgName,
};

await new StepsRunner()
.add(async (log) => await deleteScratchOrg(log, options))
.add(async (log) => await resetOrgAlias(log, options))
Expand Down
Loading
Loading