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

fix: run Playwright tests in all browsers #6876

Closed
wants to merge 9 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
2 changes: 1 addition & 1 deletion .github/workflows/ci-validate-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

env:
PLAYWRIGHT_BROWSERS_PATH: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix toolbar focus functions",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "prerelease"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "allow calendar getYear() to accept additional options for DateTimeFormatOptions",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "prerelease"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update Playwright",
"packageName": "@microsoft/fast-ssr",
"email": "[email protected]",
"dependentChangeType": "none"
}
4 changes: 3 additions & 1 deletion packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export class DateFormatter {
// (undocumented)
getWeekdays(format?: WeekdayFormat, locale?: string): string[];
// (undocumented)
getYear(year?: number, format?: YearFormat, locale?: string): string;
getYear(year?: number, format?: YearFormat, locale?: string, options?: Intl.DateTimeFormatOptions): string;
locale: string;
monthFormat: MonthFormat;
weekdayFormat: WeekdayFormat;
Expand Down Expand Up @@ -2117,6 +2117,8 @@ export class FASTToolbar extends FASTElement {
// @internal
direction: Direction;
// @internal
focus(): void;
// @internal
focusinHandler(e: FocusEvent): boolean | void;
// @internal
keydownHandler(e: KeyboardEvent): boolean | void;
Expand Down
2 changes: 1 addition & 1 deletion packages/web-components/fast-foundation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"@custom-elements-manifest/to-markdown": "^0.1.0",
"@microsoft/api-extractor": "7.24.2",
"@microsoft/tsdoc-config": "^0.13.4",
"@playwright/test": "^1.25.2",
"@playwright/test": "~1.40.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@storybook/addon-docs": "6.5.10",
"@storybook/addon-essentials": "6.5.10",
Expand Down
39 changes: 20 additions & 19 deletions packages/web-components/fast-foundation/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import type { Locator, PlaywrightTestConfig } from "@playwright/test";
import { expect } from "@playwright/test";
import { devices, expect } from "@playwright/test";

const config: PlaywrightTestConfig = {
projects: [{ name: "chromium" }, { name: "firefox" }, { name: "webkit" }],
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"],
deviceScaleFactor: 1,
launchOptions: { args: ["--force-device-scale-factor=1"] },
},
},
{
name: "firefox",
use: devices["Desktop Firefox"],
},
{
name: "webkit",
use: devices["Desktop Safari"],
},
],
reporter: "list",
testMatch: /.*\.pw\.spec\.ts$/,
retries: 3,
retries: process.env.CI ? 3 : 0,
fullyParallel: process.env.CI ? false : true,
timeout: process.env.CI ? 10000 : 30000,
use: {
Expand Down Expand Up @@ -60,20 +77,4 @@ expect.extend({
expected ${recieved} to have boolean attribute \`${name}\``,
};
},

async hasAttribute(recieved: Locator, attribute: string) {
if (await recieved.isVisible()) {
await (await recieved.elementHandle())?.waitForElementState("stable");
}

const pass = await recieved.evaluate(
(node, attribute) => node.hasAttribute(attribute),
attribute
);

return {
message: () => `expected ${recieved} to have attribute \`${attribute}\``,
pass,
};
},
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
declare global {
namespace PlaywrightTest {
interface Matchers<R> {
hasAttribute(a: string): Promise<R>;
toHaveBooleanAttribute(a: string): Promise<R>;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.describe("Accordion item", () => {
`;
});

await expect(element).not.hasAttribute("headinglevel");
await expect(element).not.toHaveAttribute("headinglevel");

await expect(element).toHaveJSProperty("headinglevel", 2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ test.describe("Accordion", () => {
node.setAttribute("expand-mode", "multi");
});

await expect(firstItem.locator("button")).not.hasAttribute("aria-disabled");
await expect(firstItem.locator("button")).not.toHaveAttribute("aria-disabled");
});

test("should set the first item as expanded if no child is expanded by default in single mode", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe("Breadcrumb item", () => {

const anchor = element.locator("a");

await expect(element).not.hasAttribute("href");
await expect(element).not.toHaveAttribute("href");

await expect(element).toHaveJSProperty("href", undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ test.describe("Breadcrumb", () => {

await expect(
element.locator("fast-breadcrumb-item:nth-of-type(2) a")
).not.hasAttribute("aria-current");
).not.toHaveAttribute("aria-current");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,24 @@ test.describe("Calendar", () => {
`;
});

expect(
await element.evaluate((node: FASTCalendar) =>
node.dateFormatter.getYear(node.year)
)
).toBe("พ.ศ. 2564");
let year = await element.evaluate((node: FASTCalendar) =>
node.dateFormatter.getYear(node.year)
);

expect(year).toContain("2564");

// Webkit on Windows only returns "2564" for the Buddhist calendar,
// so check again with `era` option.
// Possibly related: https://bugs.webkit.org/show_bug.cgi?id=265818
if (year === "2564") {
year = await element.evaluate((node: FASTCalendar) =>
node.dateFormatter.getYear(node.year, node.yearFormat, node.locale, {
era: "short",
})
);
}

expect(year).toBe("พ.ศ. 2564");
});

test("should not be RTL for languages that are not Arabic or Hebrew", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,24 @@ export class DateFormatter {
* @param year - The year to localize
* @param format - The formatting for the year
* @param locale - The locale data used for formatting
* @param options - Additional options to pass to Intl.DateTimeFormat
* @returns - A localized string for the year
* @public
*/
public getYear(
year: number = this.date.getFullYear(),
format: YearFormat = this.yearFormat,
locale: string = this.locale
locale: string = this.locale,
options?: Intl.DateTimeFormatOptions
): string {
return this.getDate({ month: 2, day: 2, year }, { year: format }, locale);
return this.getDate(
{ month: 2, day: 2, year },
{
year: format,
...(options ?? {}),
},
locale
);
}

/**
Expand Down
Loading
Loading