Skip to content

Commit 618b914

Browse files
committed
Playwright tests
1 parent 204feb5 commit 618b914

12 files changed

+323
-25
lines changed

.github/workflows/test.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: test
2+
on: push
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
timeout-minutes: 5
7+
# Container to avoid slowly installing playwright deps each time
8+
# https://playwright.dev/docs/ci#via-containers
9+
container:
10+
image: mcr.microsoft.com/playwright:v1.50.1-noble
11+
options: --user 1001
12+
strategy:
13+
matrix:
14+
node-version: [22.x]
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- name: Cache node_modules
23+
id: cache-node-modules
24+
uses: actions/cache@v3
25+
with:
26+
key: ${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
27+
path: node_modules
28+
- name: Install dependencies
29+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
30+
run: npm ci
31+
#- name: Install Playwright browsers
32+
# run: npx playwright install --with-deps
33+
timeout-minutes: 2
34+
- name: Run Playwright tests
35+
run: npm run test-playwright

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dist
1+
dist

build.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const esbuild = require('esbuild')
2-
const fs = require('fs')
3-
const fsp = require('fs').promises
4-
const path = require('path')
2+
const fs = require('node:fs')
3+
const fsp = require('node:fs').promises
4+
const path = require('node:path')
5+
const httpdir = require('httpdir')
56

67
const srcPath = path.join(__dirname, 'src')
78
const distPath = path.join(__dirname, 'dist')
89

910
build()
1011
if (process.argv.includes('--watch')) {
11-
const httpdir = require('/usr/local/lib/node_modules/httpdir')
1212
const server = httpdir.createServer({ basePath: distPath, httpPort: 9697 })
1313
server.onStart(({ urls }) => {
1414
console.log(urls.join('\n'))

package-lock.json

+75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"author": "Johan Satgé",
66
"private": true,
77
"scripts": {
8-
"build": "node build.js"
8+
"build": "node build.js",
9+
"test-playwright": "npm run build && playwright test"
910
},
1011
"repository": {
1112
"type": "git",
@@ -25,5 +26,9 @@
2526
"htm": "^3.1.1",
2627
"preact": "^10.23.1",
2728
"prismjs": "^1.29.0"
29+
},
30+
"devDependencies": {
31+
"@playwright/test": "^1.50.1",
32+
"httpdir": "^2.1.0"
2833
}
2934
}

playwright.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { defineConfig } = require('@playwright/test')
2+
const httpdir = require('httpdir')
3+
4+
export default defineConfig({
5+
use: {
6+
baseURL: 'http://localhost:9698',
7+
headless: true,
8+
acceptDownloads: true,
9+
},
10+
testMatch: 'tests/*.spec.js',
11+
outputDir: 'dist/tests-results',
12+
webServer: {
13+
command: 'node_modules/.bin/httpdir dist 9698',
14+
url: 'http://localhost:9698',
15+
reuseExistingServer: true,
16+
stdout: 'ignore',
17+
stderr: 'pipe',
18+
},
19+
})

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Standalone Preact Builder ⚛️
22

3+
[![Test](https://github.com/johansatge/standalone-preact-builder/actions/workflows/test.yml/badge.svg)](https://github.com/johansatge/standalone-preact-builder/actions)
4+
35
> Build custom, self-contained & self-hosted Preact script in the browser
46
57
---

src/bundler.js

+37-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function wasmJsResolver() {
3131
// Function sends back the code, sample usage code and stats
3232
export async function buildBundle(requestedImports, format) {
3333
const { bundleSource, bundleComments, usage } = getBundleSource(requestedImports, format)
34-
console.log('BUNDLE SOURCE', bundleSource)
3534
await esbuildInitPromise
3635
const params = {
3736
stdin: {
@@ -139,7 +138,8 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
139138
' const value = count.value',
140139
' return html`',
141140
' <h1>Hello ${props.name}!</h1>',
142-
' <button onclick=${() => count.value += 1}>Increment (count: ${value})</button>',
141+
' <p>Count: ${count.value}</p>',
142+
' <button onclick=${() => count.value += 1}>Increment</button>',
143143
' `',
144144
' }',
145145
'',
@@ -153,7 +153,8 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
153153
' const [value, setValue] = useState(0)',
154154
' return html`',
155155
' <h1>Hello ${props.name}!</h1>',
156-
' <button onclick=${() => setValue(value + 1)}>Increment (count: ${value})</button>',
156+
' <p>Count: ${value}</p>',
157+
' <button onclick=${() => setValue(value + 1)}>Increment</button>',
157158
' `',
158159
' }',
159160
'',
@@ -162,21 +163,46 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
162163
}
163164
return [
164165
'',
165-
' function App(props) {',
166-
' return html`<h1>Hello ${props.name}!</h1>`',
166+
' class App extends Component {',
167+
' constructor(props) {',
168+
' super(props)',
169+
' this.state = { count: 0 }',
170+
' }',
171+
' incrementCount = () => {',
172+
' this.setState((prevState) => ({ count: prevState.count + 1 }))',
173+
' }',
174+
' render() {',
175+
' return html`',
176+
' <h1>Hello ${this.props.name}!</h1>',
177+
' <p>Count: ${this.state.count}</p>',
178+
' <button onclick=${this.incrementCount}>Increment</button>',
179+
' `',
180+
' }',
167181
' }',
168-
'',
169-
' render(html`<${App} name="World" />`, document.querySelector(\'#root\'))',
182+
' render(h(App, { name: \'World\' }), document.querySelector(\'#root\'))',
170183
]
171-
172184
}
173185

174186
function getAppUsageWithoutHtm() {
175187
return [
176-
' function App(props) {',
177-
' return h(\'h1\', null, `Hello ${props.name}!`)',
188+
'',
189+
' class App extends Component {',
190+
' constructor(props) {',
191+
' super(props)',
192+
' this.state = { count: 0 }',
193+
' }',
194+
' incrementCount = () => {',
195+
' this.setState((prevState) => ({ count: prevState.count + 1 }))',
196+
' }',
197+
' render() {',
198+
' return h(\'div\', null, [',
199+
' h(\'h1\', null, [`Hello ${this.props.name}!`]),',
200+
' h(\'p\', null, [`Count: ${this.state.count}`]),',
201+
' h(\'button\', { onClick: this.incrementCount }, [\'Increment\']),',
202+
' ])',
203+
' }',
178204
' }',
179-
' render(App({ name: \'World\' }), document.querySelector(\'#root\'))',
205+
' render(h(App, { name: \'World\' }), document.querySelector(\'#root\'))',
180206
]
181207
}
182208

src/ui.css

+10
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ body {
172172
border-radius: 4px;
173173
}
174174

175+
.check-button:disabled {
176+
opacity: 0.5;
177+
cursor: default;
178+
}
179+
175180
.columns {
176181
display: grid;
177182
grid-template-columns: repeat(4, 1fr);
@@ -278,6 +283,11 @@ input[type="radio"]:checked::after {
278283
border-radius: 50%;
279284
}
280285

286+
input[type="radio"]:disabled {
287+
opacity: 0.5;
288+
cursor: default;
289+
}
290+
281291
.loader {
282292
position: absolute;
283293
box-sizing: border-box;

0 commit comments

Comments
 (0)