Skip to content

Commit

Permalink
chore: bump playwright to 1.32.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt committed Mar 28, 2023
2 parents 7171e10 + a007e9c commit 0d9ce4a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 122 deletions.
2 changes: 1 addition & 1 deletion ct-web-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@sand4rt/experimental-ct-web": "*",
"@playwright/test": "^1.31.0",
"@playwright/test": "^1.32.1",
"typescript": "^4.9.5",
"vite": "^4.1.4"
}
Expand Down
2 changes: 1 addition & 1 deletion ct-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@sand4rt/experimental-ct-web": "*",
"@playwright/test": "^1.31.0",
"@playwright/test": "^1.32.1",
"typescript": "^4.9.5",
"vite": "^4.1.4"
}
Expand Down
6 changes: 3 additions & 3 deletions ct-web/src/components/Button.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export class Button extends HTMLElement {
_title!: string;
static _title: string;

constructor() {
super();
this.attachShadow({ mode: 'open' });
}

set title(title: string) {
static set title(title: string) {
this._title = title;
}

get title() {
static get title() {
return this._title;
}

Expand Down
4 changes: 2 additions & 2 deletions playwright-ct-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sand4rt/experimental-ct-web",
"version": "1.0.7",
"version": "1.0.8",
"description": "Playwright Component Testing for Web Components",
"homepage": "https://playwright.dev",
"repository": {
Expand Down Expand Up @@ -43,7 +43,7 @@
}
},
"devDependencies": {
"@playwright/test": "^1.31.0",
"@playwright/test": "^1.32.1",
"vite": "^4.1.4"
},
"peerDependencies": {
Expand Down
34 changes: 17 additions & 17 deletions playwright-ct-web/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ const listeners = new Map();
/**
* @param {{[key: string]: FrameworkComponent}} components
*/
export function register(components) {
export function pwRegister(components) {
for (const [name, value] of Object.entries(components))
registry.set(name, value);
}

/**
* @param {HTMLElement} webComponent
*/
function updateProps(webComponent, props = {}) {
function __pwUpdateProps(webComponent, props = {}) {
for (const [key, value] of Object.entries(props))
webComponent[key] = value;
}

/**
* @param {HTMLElement} webComponent
*/
function removeEvents(webComponent, events = {}) {
function __pwRemoveEvents(webComponent, events = {}) {
for (const [key] of Object.entries(events)) {
webComponent.removeEventListener(key, listeners.get(key));
listeners.delete(key);
Expand All @@ -37,7 +37,7 @@ function removeEvents(webComponent, events = {}) {
/**
* @param {HTMLElement} webComponent
*/
function updateEvents(webComponent, events = {}) {
function __pwUpdateEvents(webComponent, events = {}) {
for (const [key, listener] of Object.entries(events)) {
const fn = event => listener(/** @type {CustomEvent} */ (event).detail);
webComponent.addEventListener(key, fn);
Expand All @@ -48,14 +48,14 @@ function updateEvents(webComponent, events = {}) {
/**
* @param {HTMLElement} webComponent
*/
function updateSlots(webComponent, slots = {}) {
function __pwUpdateSlots(webComponent, slots = {}) {
for (const [key, value] of Object.entries(slots)) {
let slotElements;
if (typeof value !== 'object')
slotElements = [createSlot(value)];
slotElements = [__pwCreateSlot(value)];

if (Array.isArray(value))
slotElements = value.map(createSlot);
slotElements = value.map(__pwCreateSlot);

if (!slotElements)
throw new Error(`Invalid slot with name: \`${key}\` supplied to \`mount()\``);
Expand Down Expand Up @@ -85,7 +85,7 @@ function updateSlots(webComponent, slots = {}) {
* @param {any} value
* @return {?HTMLElement}
*/
function createSlot(value) {
function __pwCreateSlot(value) {
return /** @type {?HTMLElement} */ (
document
.createRange()
Expand All @@ -97,7 +97,7 @@ function createSlot(value) {
/**
* @param {Component} component
*/
function createComponent(component) {
function __pwCreateComponent(component) {
let Component = registry.get(component.type);
if (!Component) {
// Lookup by shorthand.
Expand All @@ -123,10 +123,10 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
if (component.kind !== 'object')
throw new Error('JSX mount notation is not supported');

const webComponent = createComponent(component);
updateProps(webComponent, component.options?.props);
updateSlots(webComponent, component.options?.slots);
updateEvents(webComponent, component.options?.on);
const webComponent = __pwCreateComponent(component);
__pwUpdateProps(webComponent, component.options?.props);
__pwUpdateSlots(webComponent, component.options?.slots);
__pwUpdateEvents(webComponent, component.options?.on);

for (const hook of window['__pw_hooks_before_mount'] || [])
await hook({ hooksConfig });
Expand All @@ -144,10 +144,10 @@ window.playwrightUpdate = async (rootElement, component) => {
const webComponent = /** @type {?HTMLElement} */ (rootElement.firstChild);
if (!webComponent) throw new Error('Component was not mounted');

updateProps(webComponent, component.options?.props);
updateSlots(webComponent, component.options?.slots);
removeEvents(webComponent, component.options?.on);
updateEvents(webComponent, component.options?.on);
__pwUpdateProps(webComponent, component.options?.props);
__pwUpdateSlots(webComponent, component.options?.slots);
__pwRemoveEvents(webComponent, component.options?.on);
__pwUpdateEvents(webComponent, component.options?.on);
};

window.playwrightUnmount = async (rootElement) => {
Expand Down
Loading

0 comments on commit 0d9ce4a

Please sign in to comment.