Skip to content

Commit

Permalink
Add serialization locks around copy/paste to workaround a lack of cli…
Browse files Browse the repository at this point in the history
…pboard isolation
  • Loading branch information
Xon committed Aug 29, 2024
1 parent 336bbd3 commit 4939cdd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
31 changes: 23 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"autoprefixer": "^10.4.20",
"bundlesize": "^0.18.2",
"chai": "^5.1.1",
"cross-process-lock": "^2.1.1",
"csso-cli": "^4.0.2",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand Down
18 changes: 18 additions & 0 deletions test-e2e/test-suit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, type Locator, type Page } from '@playwright/test';
import { lock } from 'cross-process-lock';
import { writeFileSync, existsSync } from 'fs';

export class TestSuit {
readonly testId: string;
Expand Down Expand Up @@ -176,4 +178,20 @@ export class TestSuit {
async expectedItemCount(count: number): Promise<void> {
await expect(this.items).toHaveCount(count);
}

// eslint-disable-next-line class-methods-use-this
async crossProcessLock(func: () => Promise<void>): Promise<void> {
// playwright lacks clipboard isolation, so use a lock to ensure other tests don't modify the clipboard at the same time
// https://github.com/microsoft/playwright/issues/13097#issuecomment-1445271511
const name = 'test-results/clipboard';
if (!existsSync(name)) {
writeFileSync(name, '', 'utf8');
}
const unlock = await lock(name, { waitTimeout: 30000 });
try {
await func();
} finally {
await unlock();
}
}
}
6 changes: 4 additions & 2 deletions test-e2e/tests/select-multiple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,10 @@ describe(`Choices - select multiple`, () => {
await suite.startWithClick();
await suite.expectVisibleDropdown();

await page.evaluate(`navigator.clipboard.writeText('${country}')`);
await suite.ctrlV();
await suite.crossProcessLock(async () => {
await page.evaluate(`navigator.clipboard.writeText('${country}')`);
await suite.ctrlV();
});

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
Expand Down
6 changes: 4 additions & 2 deletions test-e2e/tests/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,10 @@ describe(`Choices - select one`, () => {
await suite.startWithClick();
await suite.expectVisibleDropdown();

await page.evaluate(`navigator.clipboard.writeText('${country}')`);
await suite.ctrlV();
await suite.crossProcessLock(async () => {
await page.evaluate(`navigator.clipboard.writeText('${country}')`);
await suite.ctrlV();
});

const choice = suite.selectableChoices.first();
await expect(choice).toHaveText(city);
Expand Down

0 comments on commit 4939cdd

Please sign in to comment.