-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CLI to test extension implementations (#435)
* feat: cli to test extension implementations * feat: cli command to test extensions
- Loading branch information
Showing
17 changed files
with
429 additions
and
229 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ lib | |
coverage/ | ||
tsconfig.tsbuildinfo | ||
.tmp | ||
test/resources/spec.html |
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,29 @@ | ||
import { PuppeteerStringifyExtension } from '../../lib/main.js'; | ||
|
||
export default class Extension extends PuppeteerStringifyExtension { | ||
// beforeAllSteps?(out: LineWriter, flow: UserFlow): Promise<void>; | ||
async beforeAllSteps(...args) { | ||
await super.beforeAllSteps(...args); | ||
args[0].appendLine('console.log("starting");'); | ||
} | ||
|
||
// beforeEachStep?(out: LineWriter, step: Step, flow: UserFlow): Promise<void>; | ||
async beforeEachStep(...args) { | ||
await super.beforeEachStep(...args); | ||
const [out, step] = args; | ||
out.appendLine(`console.log("about to execute step ${step.type}")`); | ||
} | ||
|
||
// afterEachStep?(out: LineWriter, step: Step, flow: UserFlow): Promise<void>; | ||
async afterEachStep(...args) { | ||
const [out, step] = args; | ||
out.appendLine(`console.log("finished step ${step.type}")`); | ||
await super.afterEachStep(...args); | ||
} | ||
|
||
// afterAllSteps?(out: LineWriter, flow: UserFlow): Promise<void>; | ||
async afterAllSteps(...args) { | ||
args[0].appendLine('console.log("finished");'); | ||
await super.afterAllSteps(...args); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,190 @@ | ||
export const recording = { | ||
title: 'spec', | ||
steps: [ | ||
{ | ||
type: 'setViewport', | ||
width: 900, | ||
height: 700, | ||
deviceScaleFactor: 1, | ||
isMobile: false, | ||
hasTouch: false, | ||
isLandscape: false, | ||
}, | ||
{ | ||
type: 'navigate', | ||
url: 'http://localhost:8907/spec.html', | ||
assertedEvents: [ | ||
{ | ||
type: 'navigation', | ||
url: 'http://localhost:8907/spec.html', | ||
title: '', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'click', | ||
target: 'main', | ||
selectors: [ | ||
['aria/Click'], | ||
['#button'], | ||
['xpath///*[@id="button"]'], | ||
['text/Click'], | ||
], | ||
offsetY: 18, | ||
offsetX: 36, | ||
}, | ||
{ | ||
type: 'doubleClick', | ||
target: 'main', | ||
selectors: [ | ||
['aria/Click'], | ||
['#button'], | ||
['xpath///*[@id="button"]'], | ||
['text/Click'], | ||
], | ||
offsetY: 18, | ||
offsetX: 36, | ||
}, | ||
{ | ||
type: 'keyDown', | ||
target: 'main', | ||
key: 'Tab', | ||
}, | ||
{ | ||
type: 'keyUp', | ||
key: 'Tab', | ||
target: 'main', | ||
}, | ||
{ | ||
type: 'change', | ||
value: 'test', | ||
selectors: [['#input'], ['xpath///*[@id="input"]']], | ||
target: 'main', | ||
}, | ||
{ | ||
type: 'change', | ||
value: 'testSuffix', | ||
selectors: [['#input-prefilled']], | ||
target: 'main', | ||
}, | ||
|
||
{ | ||
type: 'keyDown', | ||
target: 'main', | ||
key: 'Enter', | ||
}, | ||
{ | ||
type: 'keyUp', | ||
key: 'Enter', | ||
target: 'main', | ||
}, | ||
{ | ||
type: 'click', | ||
selectors: [['#input'], ['xpath///*[@id="input"]']], | ||
target: 'main', | ||
button: 'secondary', | ||
offsetX: 1, | ||
offsetY: 1, | ||
}, | ||
{ | ||
type: 'hover', | ||
target: 'main', | ||
selectors: [ | ||
['aria/Hover'], | ||
['#button'], | ||
['xpath///*[@id="hover"]'], | ||
['text/Hover'], | ||
], | ||
}, | ||
{ | ||
type: 'waitForExpression', | ||
expression: | ||
'new Promise(resolve => setTimeout(() => resolve(true), 500))', | ||
}, | ||
{ | ||
type: 'waitForElement', | ||
target: 'main', | ||
selectors: ['#button'], | ||
count: 1, | ||
visible: true, | ||
properties: { | ||
id: 'button', | ||
}, | ||
attributes: { | ||
id: 'button', | ||
}, | ||
}, | ||
{ | ||
type: 'change', | ||
value: 'optionB', | ||
selectors: [['#select']], | ||
target: 'main', | ||
}, | ||
], | ||
}; | ||
|
||
export const expectedLog = `window dimensions 900x700 | ||
click targetId=button button=0 value= | ||
click targetId=button button=0 value= | ||
dblclick targetId=button button=0 value= | ||
change targetId=input button=undefined value=test | ||
change targetId=input-prefilled button=undefined value=testSuffix | ||
contextmenu targetId=input button=2 value=test | ||
mouseenter targetId=hover button=0 value= | ||
change targetId=select button=undefined value=optionB | ||
`.trim(); | ||
|
||
export const files = new Map([ | ||
[ | ||
'spec.html', | ||
`<!DOCTYPE html> | ||
<button id="button" onclick="logEvent(event)" ondblclick="logEvent(event)"> | ||
Click | ||
</button> | ||
<button | ||
id="hover" | ||
onmouseenter="logEvent(event)" | ||
onmouseleave="logEvent(event)" | ||
> | ||
Hover | ||
</button> | ||
<input id="input" oncontextmenu="logEvent(event)" onchange="logEvent(event)" /> | ||
<input id="input-prefilled" onchange="logEvent(event)" value="test" /> | ||
<select id="select" onchange="logEvent(event)"> | ||
<option value=""></option> | ||
<option value="optionA">Option A</option> | ||
<option value="optionB">Option B</option> | ||
</select> | ||
<pre id="log"></pre> | ||
<script> | ||
function logStr(str) { | ||
log.innerText += str; | ||
const data = { username: 'example' }; | ||
fetch('/log', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/text', | ||
}, | ||
body: str, | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
} | ||
function logEvent(event) { | ||
logStr( | ||
'\\n' + | ||
event.type + | ||
' targetId=' + | ||
event.target.id + | ||
' button=' + | ||
event.button + | ||
' value=' + | ||
event.target.value | ||
); | ||
} | ||
logStr(\`window dimensions \${window.innerWidth}x\${window.innerHeight}\`); | ||
input.addEventListener('contextmenu', (e) => e.preventDefault(), false); | ||
</script>`, | ||
], | ||
]); |
Oops, something went wrong.
edd9628
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package-lock.json
edd9628
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm install @puppeteer/replay --save
This comment was marked as off-topic.
Sorry, something went wrong.