-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from azmy60/e2e-setup
- Loading branch information
Showing
18 changed files
with
377 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'solid-devtools': patch | ||
--- | ||
|
||
Add E2E tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { FrameLocator, Locator, Page, test as base, chromium } from '@playwright/test' | ||
import assert from 'assert' | ||
import path from 'path' | ||
|
||
export const test = base.extend<{ | ||
page: Page | ||
sdtFrame: FrameLocator | Locator | ||
search: Locator | ||
}>({ | ||
context: async ({ baseURL }, use, testInfo) => { | ||
if (testInfo.project.name.includes('Overlay')) { | ||
const context = await chromium.launchPersistentContext('', { baseURL }) | ||
await use(context) | ||
await context.close() | ||
return | ||
} | ||
|
||
const pathToExtension = path.resolve(__dirname, '../packages/extension/dist/') | ||
const context = await chromium.launchPersistentContext('', { | ||
args: [ | ||
'--headless=new', | ||
`--disable-extensions-except=${pathToExtension}`, | ||
`--load-extension=${pathToExtension}`, | ||
], | ||
devtools: true, // will open devtools when new tab is opened | ||
baseURL, | ||
}) | ||
|
||
const page = context.pages().find(page => page.url().includes('about:blank')) | ||
assert(page) | ||
const devtoolsPanel = context | ||
.pages() | ||
.find(page => page.url().includes('devtools://devtools/bundled/devtools_app.html')) | ||
assert(devtoolsPanel) | ||
|
||
// Since we can only initiate DevTools by opening a new tab, we need to go to | ||
// the sandbox in a new tab by clicking a link. | ||
await page.evaluate(baseURL => { | ||
const a = document.createElement('a') | ||
a.href = baseURL | ||
a.target = '_blank' | ||
a.innerText = 'open new tab' | ||
document.body.appendChild(a) | ||
}, baseURL!) | ||
|
||
const pagePromise = context.waitForEvent('page') | ||
await page.getByText('open new tab').click() | ||
const newPage = await pagePromise | ||
// wait for the new page to be interactive | ||
await newPage.getByRole('button').first().click({ trial: true }) | ||
|
||
await devtoolsPanel.close() | ||
await page.close() | ||
|
||
await use(context) | ||
|
||
await context.close() | ||
}, | ||
baseURL: async ({}, use, testInfo) => { | ||
await use(testInfo.project.use.baseURL) | ||
}, | ||
page: async ({ context, baseURL }, use, testInfo) => { | ||
if (testInfo.project.name.includes('Overlay')) { | ||
const page = context.pages()[0]! | ||
await page.goto('/') | ||
await use(page) | ||
return | ||
} | ||
|
||
const page = context.pages().find(page => page.url().includes(baseURL!)) | ||
assert(page) | ||
await use(page) | ||
}, | ||
sdtFrame: async ({ context, page }, use, testInfo) => { | ||
let sdtFrame: FrameLocator | Locator | ||
|
||
if (testInfo.project.name.includes('Overlay')) { | ||
sdtFrame = page.getByTestId('solid-devtools-overlay') | ||
} else { | ||
const devtoolsPanel = context | ||
.pages() | ||
.find(page => page.url().includes('devtools://devtools/bundled/devtools_app.html')) | ||
assert(devtoolsPanel) | ||
|
||
// Undock the devtools into a separate window so we can see the `solid` tab. | ||
await devtoolsPanel.getByLabel('Customize and control DevTools').click() | ||
await devtoolsPanel.getByLabel('Undock into separate window').click() | ||
await devtoolsPanel.getByText('Solid').click() | ||
|
||
// Somehow the window is not sized properly, causes half of the viewport | ||
// to be hidden. Interacting with elements outside the window area | ||
// wouldn't work. | ||
await devtoolsPanel.setViewportSize({ width: 640, height: 660 }) | ||
|
||
sdtFrame = devtoolsPanel.frameLocator('[src^="chrome-extension://"][src$="index.html"]') | ||
} | ||
|
||
await sdtFrame.getByText('Root').first().waitFor() // Wait for all tree nodes to be visible | ||
await use(sdtFrame) | ||
}, | ||
search: async ({ sdtFrame }, use) => { | ||
await use(sdtFrame.getByPlaceholder('Search')) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { expect } from '@playwright/test' | ||
import { test } from './fixtures' | ||
|
||
test('Search node in tree view', async ({ sdtFrame, search }) => { | ||
const selectedNode = sdtFrame.getByRole('treeitem', { selected: true }) | ||
await search.fill('Theme') | ||
|
||
// Press enter to select the matching node | ||
await search.press('Enter') | ||
await expect(selectedNode).toHaveText(/ThemeProvider/) | ||
|
||
// Press enter to go to the next matching node | ||
await search.press('Enter') | ||
await expect(selectedNode).toHaveText(/ThemeExample/) | ||
}) | ||
|
||
test('Picking node using locator', async ({ sdtFrame, page }) => { | ||
const selectedNode = sdtFrame.getByRole('treeitem', { selected: true }) | ||
const zeroIsEven = page.getByText('0 is even!') | ||
|
||
await sdtFrame.getByTitle('Select an element in the page to inspect it').click() | ||
|
||
await zeroIsEven.hover() | ||
await zeroIsEven.click() | ||
|
||
await expect(selectedNode).toHaveText(/Bold/) | ||
}) | ||
|
||
test('Reflected signal in Inspector', async ({ sdtFrame, page }) => { | ||
await sdtFrame.getByText('App').click() | ||
|
||
const count = sdtFrame.getByLabel('count', { exact: true }) | ||
const countButton = page.getByText('Count: 0').first() | ||
|
||
await expect(count).toHaveText(/0/) | ||
await countButton.click() | ||
await expect(count).toHaveText(/1/) | ||
}) | ||
|
||
test('Reflected memos in Inspector', async ({ sdtFrame, page, search }) => { | ||
const todoInput = page.getByPlaceholder('enter todo and click +') | ||
const todoButton = page.getByText('+') | ||
const newTitle = sdtFrame.getByLabel('newTitle', { exact: true }) | ||
const signal = sdtFrame.getByLabel('valuesInASignal signal') | ||
const values = signal.getByLabel('values', { exact: true }) | ||
const title = signal.getByLabel('title', { exact: true }) | ||
const done = signal.getByLabel('done', { exact: true }) | ||
|
||
await search.fill('Todos') | ||
await search.press('Enter') | ||
|
||
await signal.getByLabel(/Expand or collapse/).click() | ||
await expect(values).toHaveText(/Empty Array/) | ||
await expect(newTitle).toBeEmpty() | ||
|
||
await todoInput.fill('Buy groceries') | ||
await expect(newTitle).toHaveText(/Buy groceries/) | ||
await todoButton.click() | ||
await expect(newTitle).toBeEmpty() | ||
|
||
await expect(values).toHaveText('Array [1]') | ||
|
||
await signal.getByLabel('Expand or collapse values', { exact: true }).click() | ||
await signal.getByLabel('Expand or collapse 0').click() | ||
|
||
await expect(title).toHaveText(/Buy groceries/) | ||
await expect(done).toBeChecked({ checked: false }) | ||
await page | ||
.getByRole('checkbox') | ||
.and(page.getByLabel(/Buy groceries/)) | ||
.check() | ||
await expect(done).toBeChecked() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.