-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tests using Playwright (#68)
* Set up Playwright and add first test * Add npm run commands for running tests Run tests in github actions * Fix tests on non Mac environments * Add method to HeynoteEditor class to set the buffer content * Add more tests * Set Github action job name
- Loading branch information
Showing
12 changed files
with
327 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Tests | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Run Playwright Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: latest | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npm run test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ dist | |
dist-electron | ||
release | ||
.env | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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: './tests', | ||
/* 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://localhost: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 vite --port=3000 webapp', | ||
url: 'http://localhost:3000', | ||
timeout: 10 * 1000, | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { HeynotePage } from "./test-utils.js"; | ||
|
||
let heynotePage | ||
|
||
test.beforeEach(async ({ page }) => { | ||
console.log("beforeEach") | ||
heynotePage = new HeynotePage(page) | ||
await heynotePage.goto() | ||
}); | ||
|
||
test("enter text and create new block", async ({ page }) => { | ||
expect((await heynotePage.getBlocks()).length).toBe(1) | ||
await page.locator("body").pressSequentially("Hello World!") | ||
await page.locator("body").press("Enter") | ||
await page.locator("body").press(heynotePage.isMac ? "Meta+Enter" : "Control+Enter") | ||
await page.waitForTimeout(100); | ||
expect((await heynotePage.getBlocks()).length).toBe(2) | ||
expect(await heynotePage.getBlockContent(0)).toBe("Hello World!\n") | ||
expect(await heynotePage.getBlockContent(1)).toBe("") | ||
|
||
// check that visual block layers are created | ||
expect(await page.locator("css=.heynote-blocks-layer > div").count()).toBe(2) | ||
}) | ||
|
||
test("backspace", async ({ page }) => { | ||
|
||
await page.locator("body").pressSequentially("Hello World!") | ||
for (let i=0; i<5; i++) { | ||
await page.locator("body").press("Backspace") | ||
} | ||
expect(await heynotePage.getBlockContent(0)).toBe("Hello W") | ||
}) | ||
|
||
test("first block is protected", async ({ page }) => { | ||
const initialContent = await heynotePage.getContent() | ||
await page.locator("body").press("Backspace") | ||
expect(await heynotePage.getBlockContent(0)).toBe("") | ||
expect(await heynotePage.getContent()).toBe(initialContent) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { HeynotePage } from "./test-utils.js"; | ||
|
||
let heynotePage | ||
|
||
test.beforeEach(async ({ page }) => { | ||
console.log("beforeEach") | ||
heynotePage = new HeynotePage(page) | ||
await heynotePage.goto() | ||
}); | ||
|
||
test("test markdown mode", async ({ page }) => { | ||
heynotePage.setContent(` | ||
∞∞∞markdown | ||
# Markdown! | ||
- [ ] todo | ||
- [x] done | ||
`) | ||
//await page.locator("body").pressSequentially("test") | ||
expect(await page.locator("css=.status .status-block.lang")).toHaveText("Markdown") | ||
}) | ||
|
||
test("checkbox toggle", async ({ page }) => { | ||
heynotePage.setContent(` | ||
∞∞∞markdown | ||
- [ ] todo | ||
`) | ||
const checkbox = await page.locator("css=.cm-content input[type=checkbox]") | ||
expect(checkbox).toHaveCount(1) | ||
await checkbox.click() | ||
expect(await heynotePage.getBlockContent(0)).toBe("- [x] todo\n") | ||
await checkbox.click() | ||
expect(await heynotePage.getBlockContent(0)).toBe("- [ ] todo\n") | ||
}) |
Oops, something went wrong.