Skip to content
Open
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
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14.x'
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v2
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
/test-results/
/playwright-report/
/playwright/.cache/
59 changes: 54 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@oakstudios/mechanical-ragger",
"version": "0.5",
"description": "A layout tool that automatically rags long text by line",
"type": "module",
"main": "./index.js",
"types": "./index.d.ts",
"exports": {
Expand All @@ -29,6 +28,7 @@
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.16.7",
"@playwright/test": "^1.22.0",
"@rollup/plugin-babel": "^5.2.3",
"@rollup/plugin-node-resolve": "^13.0.6",
"@storybook/addon-actions": "^6.4.22",
Expand Down
105 changes: 105 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './tests',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
},
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',

/* 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: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},

{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',

/* Run your local dev server before starting the tests */
webServer: {
command: 'npm run storybook',
port: 6006,
},
};

export default config;
23 changes: 0 additions & 23 deletions src/__tests__/components.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,6 @@ test("the web component is created without errors.", async () => {
expect(el).toHaveProperty("ragger");
});

test("the web component reflects updated content.", async () => {
const container = document.createElement("div");
container.innerHTML = "<mechanical-ragger>one</mechanical-ragger>";
const el = container.querySelector("mechanical-ragger");
el.innerHTML = "two";
// el.shadowRoot seems like it's not thoroughly implemented in JSDOM.
expect(el.shadowRoot).toHaveTextContent("two");
});

test("the web component's slot element inherit styles.", async () => {
const container = document.createElement("div");
const style = (document.createElement(
"style"
).innerHTML = `a { border: 1px solid blue; }`);
container.innerHTML =
"<mechanical-ragger><a href='#'>one</a></mechanical-ragger>";
document.body.append(container, style);
const el = container.querySelector("mechanical-ragger a");
// jsdom doessn't return anything from getComputedStyle beside visibility.
const borderStyle = window.getComputedStyle(el).border;
expect(borderStyle).toEqual("1px solid blue");
});

test("the web component calls unobserve when it's removed from the DOM.", async () => {
const el = document.createElement("mechanical-ragger");
document.body.appendChild(el);
Expand Down
26 changes: 26 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect, Page } from "@playwright/test";

test.beforeEach(async ({ page }) => {
await page.goto(
"http://localhost:6006/iframe.html?id=web-component--slotted-element-styles"
);
});

test.describe("Web Component", () => {
test("should allow slotted elements to be targetted by page CSS", async ({
page,
}) => {
const element = await page.locator("mechanical-ragger a");
await expect(element).toHaveCSS("border-bottom-color", "rgb(255, 0, 0)");
});
test("should propagate content updates to the shadow dom", async ({
page,
}) => {
const ragger = await page.waitForSelector("mechanical-ragger p");
await ragger.evaluate((el) => {
el.innerHTML = "two";
});
const element = await page.locator("mechanical-ragger >>> p");
await expect(element).toHaveText("two");
});
});