-
Notifications
You must be signed in to change notification settings - Fork 3
feat: migrate js to ts #15
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
Open
quanvu-optimizely
wants to merge
7
commits into
precise-alloy:master
Choose a base branch
from
quanvu-optimizely:features/migrate-js-to-ts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9607d83
feat: migrate js to ts
quanvu-optimizely fb49be4
feat: migrate js to ts
quanvu-optimizely a508680
feat: migrate js to ts
quanvu-optimizely 65f4da1
feat: migrate js to ts
quanvu-optimizely 541d367
feat: migrate js to ts
quanvu-optimizely a674276
feat: migrate js to ts
quanvu-optimizely 2ab5614
feat: add prepare script
quanvu-optimizely File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,101 @@ | ||
| import type { Page, Frame, BrowserContext } from 'playwright'; | ||
| import type { Page as PuppeteerPage } from 'puppeteer'; | ||
| import type { Scenario, Viewport } from 'backstopjs'; | ||
|
|
||
| export interface KeyPressSelector { | ||
| selector: string; | ||
| keyPress: string; | ||
| } | ||
|
|
||
| export interface ScenarioAction { | ||
| frame?: string | string[]; | ||
| check?: string; | ||
| click?: string; | ||
| focus?: string; | ||
| goto?: string; | ||
| hide?: string; | ||
| hover?: string; | ||
| input?: string; | ||
| value?: string; | ||
| file?: string | string[]; | ||
| append?: boolean; | ||
| useFileChooser?: boolean; | ||
| remove?: string; | ||
| press?: string; | ||
| key?: string; | ||
| scroll?: string; | ||
| select?: string; | ||
| label?: string; | ||
| uncheck?: string; | ||
| wait?: number | string; | ||
| url?: string; | ||
| persist?: string; | ||
| path?: string; | ||
| } | ||
|
|
||
| export interface EngineScenario extends Scenario { | ||
| index: string; | ||
| total: number; | ||
| label: string; | ||
| url: string; | ||
| bypassCsp?: boolean; | ||
| cookiePath?: string; | ||
| useCssOverride?: boolean; | ||
| cssOverridePath?: string; | ||
| jsOnReadyPath?: string; | ||
| noScrollTop?: boolean; | ||
| postInteractionWait?: number | string; | ||
| hoverSelector?: string | string[]; | ||
| hoverSelectors?: string | string[]; | ||
| clickSelector?: string | string[]; | ||
| clickSelectors?: string | string[]; | ||
| keyPressSelector?: KeyPressSelector | KeyPressSelector[]; | ||
| keyPressSelectors?: KeyPressSelector | KeyPressSelector[]; | ||
| scrollToSelector?: string; | ||
| actions?: ScenarioAction[]; | ||
| getTestUrl?: (url: string) => string; | ||
| } | ||
|
|
||
| export interface CookieInput { | ||
| name: string; | ||
| value: string; | ||
| domain: string | string[]; | ||
| path?: string; | ||
| expirationDate?: number; | ||
| [k: string]: unknown; | ||
| } | ||
|
|
||
| export interface ActionsContext { | ||
| currentPage: Page; | ||
| scenario: EngineScenario; | ||
| browserContext: BrowserContext; | ||
| } | ||
|
|
||
| export type BrowserScript = () => Promise<void>; | ||
|
|
||
| export type OnBeforeScript = ( | ||
| page: Page, | ||
| scenario: EngineScenario, | ||
| viewport: Viewport, | ||
| isReference: boolean, | ||
| browserContext: BrowserContext | ||
| ) => Promise<void>; | ||
| export type OnReadyScript = OnBeforeScript; | ||
|
|
||
| export type EmbedFiles = (scenario: EngineScenario, page: Page) => Promise<void>; | ||
| export type OverrideCSS = (page: Page, scenario: EngineScenario) => Promise<void>; | ||
| export type LoadCookies = (browserContext: BrowserContext, scenario: EngineScenario) => Promise<void>; | ||
| export type Actions = (context: ActionsContext) => Promise<void>; | ||
| export type ClickAndHoverHelper = (page: Page | Frame, scenario: EngineScenario) => Promise<void>; | ||
|
|
||
| export type PuppetOnBeforeScript = ( | ||
| page: PuppeteerPage, | ||
| scenario: EngineScenario, | ||
| viewport: Viewport, | ||
| isReference: boolean, | ||
| browserContext: unknown | ||
| ) => Promise<void>; | ||
| export type PuppetOnReadyScript = (page: PuppeteerPage, scenario: EngineScenario, vp: Viewport) => Promise<void>; | ||
| export type PuppetOverrideCSS = (page: PuppeteerPage, scenario: EngineScenario) => Promise<void>; | ||
| export type PuppetClickAndHoverHelper = (page: PuppeteerPage, scenario: EngineScenario) => Promise<void>; | ||
| export type PuppetLoadCookies = (page: PuppeteerPage, scenario: EngineScenario) => Promise<void>; |
This file contains hidden or 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,8 @@ | ||
| export {}; | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| visualTestScrollingBottom?: boolean; | ||
| _styleData?: string; | ||
| } | ||
| } |
This file contains hidden or 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
24 changes: 14 additions & 10 deletions
24
...scripts/playwright/clickAndHoverHelper.js → ...scripts/playwright/clickAndHoverHelper.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,43 +1,47 @@ | ||
| module.exports = async (page, scenario) => { | ||
| import type { Page, Frame } from 'playwright'; | ||
| import type { EngineScenario, KeyPressSelector, ClickAndHoverHelper } from '../engine.js'; | ||
|
|
||
| export default (async (page: Page | Frame, scenario: EngineScenario): Promise<void> => { | ||
| const hoverSelector = scenario.hoverSelectors || scenario.hoverSelector; | ||
| const clickSelector = scenario.clickSelectors || scenario.clickSelector; | ||
| const keyPressSelector = scenario.keyPressSelectors || scenario.keyPressSelector; | ||
| const scrollToSelector = scenario.scrollToSelector; | ||
| const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int] | ||
|
|
||
| if (keyPressSelector) { | ||
| for (const keyPressSelectorItem of [].concat(keyPressSelector)) { | ||
| for (const keyPressSelectorItem of ([] as KeyPressSelector[]).concat(keyPressSelector as KeyPressSelector[])) { | ||
| await page.waitForSelector(keyPressSelectorItem.selector); | ||
| await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress); | ||
| } | ||
| } | ||
|
|
||
| if (hoverSelector) { | ||
| for (const hoverSelectorIndex of [].concat(hoverSelector)) { | ||
| for (const hoverSelectorIndex of ([] as string[]).concat(hoverSelector as string[])) { | ||
| await page.waitForSelector(hoverSelectorIndex); | ||
| await page.hover(hoverSelectorIndex); | ||
| } | ||
| } | ||
|
|
||
| if (clickSelector) { | ||
| for (const clickSelectorIndex of [].concat(clickSelector)) { | ||
| for (const clickSelectorIndex of ([] as string[]).concat(clickSelector as string[])) { | ||
| await page.waitForSelector(clickSelectorIndex); | ||
| await page.click(clickSelectorIndex); | ||
| } | ||
| } | ||
|
|
||
| if (postInteractionWait) { | ||
| if (parseInt(postInteractionWait) > 0) { | ||
| await page.waitForTimeout(postInteractionWait); | ||
| const interactionWait = parseInt(String(postInteractionWait)); | ||
| if (!Number.isNaN(interactionWait) && interactionWait >= 0) { | ||
| await page.waitForTimeout(interactionWait); | ||
| } else { | ||
| await page.waitForSelector(postInteractionWait); | ||
| await page.waitForSelector(postInteractionWait as string); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| if (scrollToSelector) { | ||
| await page.waitForSelector(scrollToSelector); | ||
| await page.evaluate(scrollToSelector => { | ||
| document.querySelector(scrollToSelector).scrollIntoView(); | ||
| await page.evaluate((scrollToSel: string) => { | ||
| document.querySelector(scrollToSel)!.scrollIntoView(); | ||
| }, scrollToSelector); | ||
| } | ||
| }; | ||
| }) as ClickAndHoverHelper; | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.