Skip to content

Commit

Permalink
Playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johansatge committed Feb 15, 2025
1 parent 204feb5 commit dd2824f
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 25 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: test
on: push
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 1
strategy:
matrix:
node-version: [18.x]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
path: node_modules
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm run test-playwright
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dist
dist
8 changes: 4 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const esbuild = require('esbuild')
const fs = require('fs')
const fsp = require('fs').promises
const path = require('path')
const fs = require('node:fs')
const fsp = require('node:fs').promises
const path = require('node:path')
const httpdir = require('httpdir')

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

build()
if (process.argv.includes('--watch')) {
const httpdir = require('/usr/local/lib/node_modules/httpdir')
const server = httpdir.createServer({ basePath: distPath, httpPort: 9697 })
server.onStart(({ urls }) => {
console.log(urls.join('\n'))
Expand Down
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "Johan Satgé",
"private": true,
"scripts": {
"build": "node build.js"
"build": "node build.js",
"test-playwright": "npm run build && playwright test"
},
"repository": {
"type": "git",
Expand All @@ -25,5 +26,9 @@
"htm": "^3.1.1",
"preact": "^10.23.1",
"prismjs": "^1.29.0"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"httpdir": "^2.1.0"
}
}
19 changes: 19 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { defineConfig } = require('@playwright/test')
const httpdir = require('httpdir')

export default defineConfig({
use: {
baseURL: 'http://localhost:9698',
headless: true,
acceptDownloads: true,
},
testMatch: 'tests/*.spec.js',
outputDir: 'dist/tests-results',
webServer: {
command: 'node_modules/.bin/httpdir dist 9698',
url: 'http://localhost:9698',
reuseExistingServer: true,
stdout: 'pipe',
stderr: 'pipe',
},
})
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Standalone Preact Builder ⚛️

[![Test](https://github.com/johansatge/standalone-preact-builder/actions/workflows/test.yml/badge.svg)](https://github.com/johansatge/standalone-preact-builder/actions)

> Build custom, self-contained & self-hosted Preact script in the browser
---
Expand Down
48 changes: 37 additions & 11 deletions src/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function wasmJsResolver() {
// Function sends back the code, sample usage code and stats
export async function buildBundle(requestedImports, format) {
const { bundleSource, bundleComments, usage } = getBundleSource(requestedImports, format)
console.log('BUNDLE SOURCE', bundleSource)
await esbuildInitPromise
const params = {
stdin: {
Expand Down Expand Up @@ -139,7 +138,8 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
' const value = count.value',
' return html`',
' <h1>Hello ${props.name}!</h1>',
' <button onclick=${() => count.value += 1}>Increment (count: ${value})</button>',
' <p>Count: ${count.value}</p>',
' <button onclick=${() => count.value += 1}>Increment</button>',
' `',
' }',
'',
Expand All @@ -153,7 +153,8 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
' const [value, setValue] = useState(0)',
' return html`',
' <h1>Hello ${props.name}!</h1>',
' <button onclick=${() => setValue(value + 1)}>Increment (count: ${value})</button>',
' <p>Count: ${value}</p>',
' <button onclick=${() => setValue(value + 1)}>Increment</button>',
' `',
' }',
'',
Expand All @@ -162,21 +163,46 @@ function getAppUsageWithHtm(withSignals, withUseState,) {
}
return [
'',
' function App(props) {',
' return html`<h1>Hello ${props.name}!</h1>`',
' class App extends Component {',
' constructor(props) {',
' super(props)',
' this.state = { count: 0 }',
' }',
' incrementCount = () => {',
' this.setState((prevState) => ({ count: prevState.count + 1 }))',
' }',
' render() {',
' return html`',
' <h1>Hello ${this.props.name}!</h1>',
' <p>Count: ${this.state.count}</p>',
' <button onclick=${this.incrementCount}>Increment</button>',
' `',
' }',
' }',
'',
' render(html`<${App} name="World" />`, document.querySelector(\'#root\'))',
' render(h(App, { name: \'World\' }), document.querySelector(\'#root\'))',
]

}

function getAppUsageWithoutHtm() {
return [
' function App(props) {',
' return h(\'h1\', null, `Hello ${props.name}!`)',
'',
' class App extends Component {',
' constructor(props) {',
' super(props)',
' this.state = { count: 0 }',
' }',
' incrementCount = () => {',
' this.setState((prevState) => ({ count: prevState.count + 1 }))',
' }',
' render() {',
' return h(\'div\', null, [',
' h(\'h1\', null, [`Hello ${this.props.name}!`]),',
' h(\'p\', null, [`Count: ${this.state.count}`]),',
' h(\'button\', { onClick: this.incrementCount }, [\'Increment\']),',
' ])',
' }',
' }',
' render(App({ name: \'World\' }), document.querySelector(\'#root\'))',
' render(h(App, { name: \'World\' }), document.querySelector(\'#root\'))',
]
}

Expand Down
10 changes: 10 additions & 0 deletions src/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ body {
border-radius: 4px;
}

.check-button:disabled {
opacity: 0.5;
cursor: default;
}

.columns {
display: grid;
grid-template-columns: repeat(4, 1fr);
Expand Down Expand Up @@ -278,6 +283,11 @@ input[type="radio"]:checked::after {
border-radius: 50%;
}

input[type="radio"]:disabled {
opacity: 0.5;
cursor: default;
}

.loader {
position: absolute;
box-sizing: border-box;
Expand Down
Loading

0 comments on commit dd2824f

Please sign in to comment.