Skip to content

Commit

Permalink
updated: use playwright instead of wdio
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Feb 23, 2024
1 parent badaeeb commit 45b44ab
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 338 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- run: |
npm run lint
npm test
- name: Install Playwright Browsers
if: ${{ success() && github.event_name != 'pull_request' && matrix.node-version == '20.x' }}
run: npx playwright install --with-deps
- name: Runtime test
if: ${{ success() && github.event_name != 'pull_request' && matrix.node-version == '20.x' }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ pids
.nyc_output/
.reify-cache/
stats.html
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
84 changes: 78 additions & 6 deletions package-lock.json

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

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build": "rollup -c build/rollup.node.config.js && rollup -c build/rollup.browser.config.js && rollup -c build/rollup.essential.config.js",
"postest": "npm run cov-html",
"test-types": "tsc -p test",
"test-runtime": "start-server-and-test serve 3000 wdio run ./wdio.conf.js",
"test-runtime": "playwright test",
"test-commonjs": "c8 mocha 'test/**/*.spec.cjs'",
"test": "c8 mocha 'test/**/*.spec.js' && npm run test-types",
"debug": "mocha --inspect --inspect-brk 'test/**/*.spec.js'",
Expand All @@ -51,16 +51,13 @@
"devDependencies": {
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@playwright/test": "^1.41.2",
"@riotjs/dom-bindings": "^9.0.4",
"@riotjs/prettier-config": "^1.1.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@wdio/cli": "^8.32.3",
"@wdio/local-runner": "^8.32.3",
"@wdio/mocha-framework": "^8.32.3",
"@wdio/spec-reporter": "^8.32.2",
"acorn": "^8.11.3",
"c8": "^9.1.0",
"chai": "^5.1.0",
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// @ts-check
import { defineConfig, devices } from '@playwright/test'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* @see https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: './test/',
testMatch: '*.e2e.js',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npx serve',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
})
13 changes: 0 additions & 13 deletions test/karma.conf.cjs

This file was deleted.

16 changes: 5 additions & 11 deletions test/test.e2e.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { browser, expect } from '@wdio/globals'
import { test, expect } from '@playwright/test'

describe('Run the mocha tests', function () {
it('All the mocha tests passed', async () => {
await browser.url('http://localhost:3000/test/e2e.runtime.html')
await browser.waitUntil(async () =>
browser.execute(() => typeof window.testFailures === 'number'),
)
const testFailures = await browser.execute(() => window.testFailures)
test('All the mocha tests passed', async ({ page }) => {
await page.goto('http://localhost:3000/test/e2e.runtime.html')
const testFailures = await page.evaluate('window.testFailures')

expect(testFailures).toBe(0)
expect(true).toBe(true)
})
expect(testFailures).toBe(0)
})
Loading

0 comments on commit 45b44ab

Please sign in to comment.