Skip to content

Instantly share code, notes, and snippets.

@jaredcwhite
Created September 28, 2023 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredcwhite/3949cf215e0ac5e552652170c34405f7 to your computer and use it in GitHub Desktop.
Save jaredcwhite/3949cf215e0ac5e552652170c34405f7 to your computer and use it in GitHub Desktop.
Setting up web-test-runner
// test/button_click.js
import { fixture, assert, aTimeout, html as testhtml } from "@open-wc/testing"
// Custom elements could go here, or be imported
describe("button click", () => {
it("handles click properly", async () => {
const el = await fixture(testhtml`
<test-element>
<article>
<button onclick="this.textContent='clicked!'">Button</button>
</article>
</test-element>
`)
el.querySelector("button").click()
assert.equal(el.shadowRoot.querySelector("test-msg").textContent, "clicked!")
})
})
# .github/workflows/ci.yml
name: CI Test
on:
pull_request:
branches:
- "*"
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install packages
run: npm ci
- name: Set up Playwright
run: npx playwright install --with-deps
- name: Run tests
run: npm run test
"scripts": {
"test": "web-test-runner --node-resolve",
"test:dev": "npm run test -- --watch"
},
"devDependencies": {
"@open-wc/testing": "^3.2.0",
"@web/test-runner": "^0.17.1",
"@web/test-runner-playwright": "^0.10.1",
}
import { playwrightLauncher } from "@web/test-runner-playwright"
export default {
browsers: [
playwrightLauncher({ product: "chromium" }),
playwrightLauncher({ product: "firefox" }),
playwrightLauncher({ product: "webkit" }),
],
files: "test/**/*.test.js",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment