Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed Jul 21, 2023
1 parent 512d4fb commit cd6b48c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
32 changes: 32 additions & 0 deletions scripts/browserTest/index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

import crypto from 'crypto'
import puppeteer from 'puppeteer'
import { createServer } from 'http'
Expand All @@ -21,14 +23,44 @@ let hasError = false
const server = createServer(requestListener({ serve, collectCoverage }))
server.closeAsync = () => new Promise(resolve => server.close(() => resolve()))

/**
* @param {{fileName:string, browser:puppeteer.Browser}} param0
*/
const main = async ({ fileName, browser }) => {
console.log(`> ${fileName}`)

const page = await browser.newPage()
await page.setRequestInterception(true);

/** @type {Array<puppeteer.HTTPRequest>} */
const requests = [];

// Enable both JavaScript and CSS coverage
if (collectCoverage) await page.coverage.startJSCoverage()

// Blocks all window.location.href requests
page.on('request', async request => {
let isNavRequest = request.isNavigationRequest() && request.frame() === page.mainFrame();
if (!isNavRequest) {
request.continue();
return;
}

requests.push(request);
if (requests.length == 1) {
request.continue();
return;
}

request.abort('aborted');

const url = requests[requests.length - 1].url()
await page.evaluate((url) => {
window.__gotohref__ = url;
}, url);

});

// Navigate to page
let url = `http://localhost:8080/${fileName.replace(/^\+/, '')}`
await page.goto(url, { waitUntil: 'networkidle2' })
Expand Down
22 changes: 18 additions & 4 deletions test/browser/link.test.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -70,12 +70,26 @@
headLastChild().remove()
})

describe('Back/Delay (TODO)', async () => {
describe('Delay', async () => {
const App = () => h(Link, { delay: 1000, href: 'https://nanojsx.github.io/' }, 'nanojsx.github.io')

render(App, root())

await Test.wait()

/** @type {HTMLLinkElement} */
const link = root()?.firstChild
link.click()

await Test.wait(2000)

expect(window.__gotohref__).toBe('https://nanojsx.github.io/')
})

describe('Back (TODO)', async () => {
const back = (Link, { back: true, href: 'https://nanojsx.github.io/' }, 'nanojsx.github.io')
const delay = (Link, { delay: 150, href: 'https://nanojsx.github.io/' }, 'nanojsx.github.io')

expect('skip', null).toBe(null, 'Should test "back"')
expect('skip', null).toBe(null, 'Should test "delay"')
})

Test.start()
Expand Down

0 comments on commit cd6b48c

Please sign in to comment.