-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbeb453
commit 6ad8e31
Showing
9 changed files
with
164 additions
and
7 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
Empty file.
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,63 @@ | ||
import { createServer } from 'vite'; | ||
import { firefox, chromium, webkit } from 'playwright'; | ||
|
||
const PORT = 3001; | ||
const TIMEOUT = 30_000; | ||
|
||
(async () => { | ||
let server, | ||
browsers = []; | ||
const browserList = [firefox, chromium, webkit]; | ||
try { | ||
server = await createServer({ | ||
server: { | ||
port: PORT, | ||
}, | ||
}); | ||
await server.listen(); | ||
|
||
browsers = await Promise.all( | ||
browserList.map((browserApp) => browserApp.launch({ headless: true })), | ||
); | ||
|
||
await Promise.all( | ||
browsers.map((browser) => { | ||
console.log(browser._name); | ||
return new Promise((resolve, reject) => { | ||
let timerId; | ||
Promise.race([ | ||
browser | ||
.newPage() | ||
.then((page) => { | ||
page.on('websocket', (webSocket) => { | ||
webSocket.on('framesent', ({ payload }) => { | ||
const asJson = JSON.parse(payload); | ||
if (asJson?.data?.type === 'STREAM_ENDED') { | ||
clearTimeout(timerId); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
|
||
return page.goto( | ||
`http://localhost:${PORT}/test/test-suite.html`, | ||
); | ||
}) | ||
.catch(reject), | ||
new Promise((resolve, reject) => { | ||
timerId = setTimeout(() => reject('timeout'), TIMEOUT); | ||
}), | ||
]); | ||
}); | ||
}), | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
process.exitCode = 1; | ||
} finally { | ||
await Promise.all(browsers.map((browser) => browser.close())); | ||
if (server) { | ||
await server.close(); | ||
} | ||
} | ||
})(); |
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,36 @@ | ||
import { test } from '@cofn/test-lib/client'; | ||
import { fromView } from './utils.js'; | ||
|
||
const debug = document.getElementById('debug'); | ||
|
||
test('render a component when mounted', ({ eq }) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ attributes }) => | ||
html`<p>hello ${attributes.name}</p>`, | ||
); | ||
|
||
el.setAttribute('name', 'Laurent'); | ||
debug.appendChild(el); | ||
eq(el.innerHTML, '<p>hello Laurent</p>'); | ||
}); | ||
|
||
test('component is updated when rendered is called, passing the relevant data', ({ | ||
eq, | ||
}) => { | ||
const el = fromView( | ||
({ html }) => | ||
({ attributes }) => | ||
html`<p>hello ${attributes.name}</p>`, | ||
); | ||
el.setAttribute('name', 'Laurent'); | ||
debug.appendChild(el); | ||
|
||
eq(el.innerHTML, '<p>hello Laurent</p>'); | ||
|
||
el.render({ | ||
attributes: { name: 'Robert' }, | ||
}); | ||
|
||
eq(el.innerHTML, '<p>hello Robert</p>'); | ||
}); |
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,26 @@ | ||
<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='UTF-8'> | ||
<title>Test suite for package view</title> | ||
<style> | ||
@import url("@cofn/test-lib/client/theme.css"); | ||
</style> | ||
</head> | ||
<body> | ||
<div id="report-container"> | ||
<h1>Test reporting</h1> | ||
<div id="report"></div> | ||
</div> | ||
<div id="debug"> | ||
</div> | ||
</body> | ||
<script type='module'> | ||
import { report, createHTMLReporter, createSocketSink } from '@cofn/test-lib/client'; | ||
import './simple-render.js'; | ||
|
||
const [st1, st2] = report().tee(); | ||
st1.pipeTo(createSocketSink(import.meta.hot)); | ||
st2.pipeTo(createHTMLReporter({element: document.getElementById('report')})) | ||
</script> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { define } from '@cofn/core'; | ||
import { withView } from '../src/index.js'; | ||
export const nextTick = () => new Promise((resolve) => setTimeout(resolve, 0)); | ||
|
||
let compCount = 0; | ||
export const fromView = (view) => { | ||
const tag = `view-test-${++compCount}`; | ||
define(tag, withView(view)); | ||
return document.createElement(tag); | ||
}; |
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,6 @@ | ||
import { defineConfig } from 'vite'; | ||
import zoraDev from '@cofn/test-lib/vite'; | ||
|
||
export default defineConfig({ | ||
plugins: [zoraDev()], | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.