SolidJS
SolidJSは、シンプルで高性能な反応性を備えたユーザーインターフェースを構築するためのフレームワークです。WebdriverIOとそのブラウザランナーを使用して、実際のブラウザでSolidJSコンポーネントを直接テストできます。
セットアップ
SolidJSプロジェクト内でWebdriverIOをセットアップするには、コンポーネントテストドキュメントの手順に従ってください。ランナーオプション内でプリセットとしてsolidを選択してください。例:
// wdio.conf.js
export const config = {
    // ...
    runner: ['browser', {
        preset: 'solid'
    }],
    // ...
}
情  報
SolidJSプリセットにはvite-plugin-solidのインストールが必要です:
- npm
 - Yarn
 - pnpm
 
npm install --save-dev vite-plugin-solid
yarn add --dev vite-plugin-solid
pnpm add --save-dev vite-plugin-solid
その後、以下のコマンドでテストを開始できます:
npx wdio run ./wdio.conf.js
テストの作成
以下のようなSolidJSコンポーネントがあるとします:
./components/Component.tsx
import { createSignal } from 'solid-js'
function App() {
    const [theme, setTheme] = createSignal('light')
    const toggleTheme = () => {
        const nextTheme = theme() === 'light' ? 'dark' : 'light'
        setTheme(nextTheme)
    }
    return <button onClick={toggleTheme}>
        Current theme: {theme()}
    </button>
}
export default App
テストでは、solid-js/webのrenderメソッドを使用してコンポーネントをテストページに取り付けます。コンポーネントを操作するには、実際のユーザーの操作に近い動作をするWebdriverIOコマンドを使用することをお勧めします:
app.test.tsx
import { expect } from '@wdio/globals'
import { render } from 'solid-js/web'
import App from './components/Component.jsx'
describe('Solid Component Testing', () => {
    /**
     * ensure we render the component for every test in a
     * new root container
     */
    let root: Element
    beforeEach(() => {
        if (root) {
            root.remove()
        }
        root = document.createElement('div')
        document.body.appendChild(root)
    })
    it('Test theme button toggle', async () => {
        render(<App />, root)
        const buttonEl = await $('button')
        await buttonEl.click()
        expect(buttonEl).toContainHTML('dark')
    })
})
WebdriverIOコンポーネントテストスイートのSolidJSの完全な例は、サンプルリポジトリで確認できます。