4.0.4 • Published 6 months ago

puppet-strings-open-app v4.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
6 months ago

puppet-strings-open-app

npm CI Status dependencies Status devDependencies Status

An extension to puppet-strings for compiling and opening a web UI in Chrome.

Example

To test a React component in isolation within Chrome:

ui/component.js

import { html } from 'htm/react'

export default function Component() {
  return html`
    <div>Hello World!</div>
  `
}

ui/component.test.js

import test from 'ava'
import { closeTab, findElement } from 'puppet-strings'
import openApp from 'puppet-strings-open-app'

test('rendering in a browser', async (t) => {
  const app = await openApp({
    path: './app',
    files: {
      'index.html': `
        <!doctype html>
        <script type="module" src="/index.js"></script>
        <div></div>
      `,
      'index.js': `
        import { createRoot } from 'react-dom/client'
        import { html } from 'htm/react'
        import Component from './component'

        const root = createRoot(document.body.firstElementChild)
        root.render(html\`<\${Component} />\`)
      `
    }
  })
  t.teardown(async () => {
    await closeTab(app)
  })

  const root = await findElement(app, 'div')
  t.is(root.innerText, 'Hello World!')
})

Installation

Install puppet-strings-open-app by running:

yarn add puppet-strings-open-app
4.0.4

6 months ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.3

1 year ago

4.0.2

1 year ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago