Skip to content

Commit

Permalink
Feat/playwright (#29)
Browse files Browse the repository at this point in the history
* chore: bump node version

* feat: migrate to playwright

* chore: add async generator example

* chore: update package.json

* chore: add changeset
  • Loading branch information
heyMP authored Jun 19, 2024
1 parent 1c89279 commit f5c9bc4
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 3,418 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-berries-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heymp/scratchpad": major
---

Migrate to Playwright
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.16.0
v20.11.1
11 changes: 9 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Processor extends EventTarget {
constructor() {
super();
this.url = opts['url'];
this.headless = 'headless' in opts ? 'new' : false
this.headless = opts['headless'];
this._func = '';

if (file.endsWith('.ts')) {
Expand All @@ -51,7 +51,14 @@ class Processor extends EventTarget {

startTsWatcher() {
// start a watcher
const tscCommand = spawn('npx', ['tsc', file, '-w', '--outFile', '/dev/stdout'], { cwd: process.cwd() });
const tscCommand = spawn('npx', [
'tsc', file,
'-w',
'--outFile',
'/dev/stdout',
'--target',
'esnext',
], { cwd: process.cwd() });
tscCommand.stdout.on('data', data => {
const output = data.toString();
if (output.includes('Starting') || output.includes('Watching for file changes')) {
Expand Down
39 changes: 39 additions & 0 deletions examples/eventBus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/// <reference path="../types.d.ts" />
clear();

class EventBusMessage extends Event {
constructor(public data: any) {
super('message');
}
}

class EventBus extends EventTarget {
constructor() {
super();
}
emit(event: any, data: any) {
this.dispatchEvent(new EventBusMessage({ event, data }));
}
}

const eventBus = new EventBus();

function* eventBusGenerator() {
while (true) {
window.promise = new Promise(resolve => eventBus.addEventListener('message', (e) => resolve(e), { once: true }));
yield window.promise;
}
}

setInterval(() => {
eventBus.emit('tick', Date.now());
}, 1000);

let i = 0;
for await (const message of eventBusGenerator()) {
if (i > 5) break;
i++;
log(message);
}

log('complete', window.promise);
Loading

0 comments on commit f5c9bc4

Please sign in to comment.