diff --git a/.github/workflows/_e2e.yml b/.github/workflows/_e2e.yml new file mode 100644 index 0000000000..42b957cc61 --- /dev/null +++ b/.github/workflows/_e2e.yml @@ -0,0 +1,21 @@ +name: E2E Tests +on: + workflow_call: +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: | + npm start & + sleep 120 + npx playwright test diff --git a/.github/workflows/test.yml b/.github/workflows/_unit.yml similarity index 97% rename from .github/workflows/test.yml rename to .github/workflows/_unit.yml index c8a39e45a8..669658f35d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/_unit.yml @@ -1,6 +1,6 @@ +name: Unit Tests on: workflow_call: - jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86add7f58d..d20fef1f7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,5 +9,7 @@ concurrency: cancel-in-progress: true jobs: - test: - uses: ./.github/workflows/test.yml + unit: + uses: ./.github/workflows/_unit.yml + e2e: + uses: ./.github/workflows/_e2e.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d0e925d520..96000dd6ea 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,5 +5,7 @@ on: branches: [develop] jobs: - test: - uses: ./.github/workflows/test.yml + unit: + uses: ./.github/workflows/_unit.yml + e2e: + uses: ./.github/workflows/_e2e.yml diff --git a/.gitignore b/.gitignore index 9b3fdfd29c..862c9515f8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ test/random.js core.js quill.js +/test-results/ +/playwright-report/ +/playwright/.cache/ diff --git a/_develop/scripts/puppeteer.sh b/_develop/scripts/puppeteer.sh deleted file mode 100755 index aa040fe7eb..0000000000 --- a/_develop/scripts/puppeteer.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -npm start & -sleep 20 -./node_modules/.bin/jasmine test/functional/epic.js -EXIT_CODE=$? - -FOREMAN_PID=$(pgrep foreman) -kill -s SIGINT $FOREMAN_PID - -exit $EXIT_CODE diff --git a/_develop/wdio.config.js b/_develop/wdio.config.js deleted file mode 100644 index f6eab1d481..0000000000 --- a/_develop/wdio.config.js +++ /dev/null @@ -1,34 +0,0 @@ -exports.config = { - specs: ['./test/functional/epic.js'], - exclude: [], - - reporters: ['spec'], - - maxInstances: 10, - capabilities: [ - { - browserName: 'chrome', - }, - ], - - sync: true, - logLevel: 'error', - coloredLogs: true, - - baseUrl: `http://localhost:${process.env.npm_package_config_ports_proxy}`, - - waitforTimeout: 10000, - connectionRetryTimeout: 90000, - connectionRetryCount: 3, - - framework: 'jasmine', - jasmineNodeOpts: { - defaultTimeoutInterval: 10000, - expectationResultHandler: passed => { - if (passed) return; - this.saveScreenshot( - `./wd-${this.desiredCapabilities.browserName}-error.png`, - ); - }, - }, -}; diff --git a/e2e/full.spec.ts b/e2e/full.spec.ts new file mode 100644 index 0000000000..048a13a412 --- /dev/null +++ b/e2e/full.spec.ts @@ -0,0 +1,215 @@ +import { test, expect } from '@playwright/test'; +import { getSelectionInTextNode, SHORTKEY } from './utils'; +import { CHAPTER, P1, P2 } from './utils/fixtures'; +import QuillPage from './utils/QuillPage'; + +test('compose an epic', async ({ page }) => { + await page.goto('http://localhost:9000/standalone/full'); + const quillPage = new QuillPage(page); + await page.waitForSelector('.ql-editor', { timeout: 10000 }); + await expect(page).toHaveTitle('Full Editor - Quill Rich Text Editor'); + + await page.type('.ql-editor', 'The Whale'); + expect(await quillPage.editorHTML()).toEqual('

The Whale

'); + + await page.keyboard.press('Enter'); + expect(await quillPage.editorHTML()).toEqual('

The Whale


'); + + await page.keyboard.press('Enter'); + await page.keyboard.press('Tab'); + await page.type('.ql-editor', P1); + await page.keyboard.press('Enter'); + await page.keyboard.press('Enter'); + await page.type('.ql-editor', P2); + expect(await quillPage.editorHTML()).toEqual( + [ + '

The Whale

', + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + // More than enough to get to top + await Promise.all( + Array(40) + .fill(0) + .map(() => page.keyboard.press('ArrowUp')), + ); + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('Enter'); + await page.type('.ql-editor', CHAPTER); + await page.keyboard.press('Enter'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

The Whale

', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + // More than enough to get to top + await Promise.all( + Array(20) + .fill(0) + .map(() => page.keyboard.press('ArrowUp')), + ); + await page.keyboard.press('ArrowRight'); + await page.keyboard.press('ArrowRight'); + await page.keyboard.press('ArrowRight'); + await page.keyboard.press('ArrowRight'); + await page.keyboard.press('Backspace'); + await page.keyboard.press('Backspace'); + await page.keyboard.press('Backspace'); + await page.keyboard.press('Backspace'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

Whale

', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.keyboard.press('Delete'); + await page.keyboard.press('Delete'); + await page.keyboard.press('Delete'); + await page.keyboard.press('Delete'); + await page.keyboard.press('Delete'); + expect(await quillPage.editorHTML()).toEqual( + [ + '


', + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.keyboard.press('Delete'); + expect(await quillPage.editorHTML()).toEqual( + [ + '


', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.click('.ql-toolbar .ql-bold'); + await page.click('.ql-toolbar .ql-italic'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

\uFEFF

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + let bold = await page.$('.ql-toolbar .ql-bold.ql-active'); + let italic = await page.$('.ql-toolbar .ql-italic.ql-active'); + expect(bold).not.toBe(null); + expect(italic).not.toBe(null); + + await page.type('.ql-editor', 'Moby Dick'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + bold = await page.$('.ql-toolbar .ql-bold.ql-active'); + italic = await page.$('.ql-toolbar .ql-italic.ql-active'); + expect(bold).not.toBe(null); + expect(italic).not.toBe(null); + + await page.keyboard.press('ArrowRight'); + await page.keyboard.down('Shift'); + await Promise.all( + Array(CHAPTER.length) + .fill(0) + .map(() => page.keyboard.press('ArrowRight')), + ); + await page.keyboard.up('Shift'); + bold = await page.$('.ql-toolbar .ql-bold.ql-active'); + italic = await page.$('.ql-toolbar .ql-italic.ql-active'); + expect(bold).toBe(null); + expect(italic).toBe(null); + + await page.keyboard.down(SHORTKEY); + await page.keyboard.press('b'); + await page.keyboard.up(SHORTKEY); + bold = await page.$('.ql-toolbar .ql-bold.ql-active'); + expect(bold).not.toBe(null); + expect(await quillPage.editorHTML()).toEqual( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + + await page.keyboard.press('ArrowLeft'); + await page.keyboard.press('ArrowUp'); + await page.click('.ql-toolbar .ql-header[value="1"]'); + expect(await quillPage.editorHTML()).toEqual( + [ + '

Moby Dick

', + `

${CHAPTER}

`, + '


', + `

\t${P1}

`, + '


', + `

${P2}

`, + ].join(''), + ); + const header = await page.$('.ql-toolbar .ql-header.ql-active[value="1"]'); + expect(header).not.toBe(null); + + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('ArrowDown'); + await page.keyboard.press('Enter'); + await page.keyboard.press('Enter'); + await page.keyboard.press('ArrowUp'); + await page.type('.ql-editor', 'AA'); + await page.keyboard.press('ArrowLeft'); + await page.keyboard.down(SHORTKEY); + await page.keyboard.press('b'); + await page.keyboard.press('b'); + await page.keyboard.up(SHORTKEY); + await page.type('.ql-editor', 'B'); + expect(await quillPage.root.locator('p').nth(2).innerHTML()).toBe('ABA'); + await page.keyboard.down(SHORTKEY); + await page.keyboard.press('b'); + await page.keyboard.up(SHORTKEY); + await page.type('.ql-editor', 'C'); + await page.keyboard.down(SHORTKEY); + await page.keyboard.press('b'); + await page.keyboard.up(SHORTKEY); + await page.type('.ql-editor', 'D'); + expect(await quillPage.root.locator('p').nth(2).innerHTML()).toBe( + 'ABCDA', + ); + const selection = await page.evaluate(getSelectionInTextNode); + expect(selection).toBe('["DA",1,"DA",1]'); +}); diff --git a/e2e/utils/QuillPage.ts b/e2e/utils/QuillPage.ts new file mode 100644 index 0000000000..ed1b809372 --- /dev/null +++ b/e2e/utils/QuillPage.ts @@ -0,0 +1,15 @@ +import { Page } from '@playwright/test'; + +class QuillPage { + constructor(private page: Page) {} + + get root() { + return this.page.locator('.ql-editor'); + } + + editorHTML() { + return this.root.innerHTML(); + } +} + +export default QuillPage; diff --git a/e2e/utils/fixtures.ts b/e2e/utils/fixtures.ts new file mode 100644 index 0000000000..20a0e7aa84 --- /dev/null +++ b/e2e/utils/fixtures.ts @@ -0,0 +1,5 @@ +export const CHAPTER = 'Chapter 1. Loomings.'; +export const P1 = + 'Call me Ishmael. Some years ago—never mind how long precisely-having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.'; +export const P2 = + 'There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs—commerce surrounds it with her surf. Right and left, the streets take you waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there.'; diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts new file mode 100644 index 0000000000..f136df2582 --- /dev/null +++ b/e2e/utils/index.ts @@ -0,0 +1,12 @@ +export const SHORTKEY = process.platform === 'darwin' ? 'Meta' : 'Control'; + +export function getSelectionInTextNode() { + const { anchorNode, anchorOffset, focusNode, focusOffset } = + document.getSelection(); + return JSON.stringify([ + (anchorNode as Text).data, + anchorOffset, + (focusNode as Text).data, + focusOffset, + ]); +} diff --git a/package-lock.json b/package-lock.json index fac10d4c8b..130932b1e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "devDependencies": { "@babel/core": "^7.19.3", "@babel/preset-env": "^7.19.4", + "@playwright/test": "^1.27.1", "@types/jasmine": "^4.3.0", "@typescript-eslint/eslint-plugin": "^5.38.0", "@typescript-eslint/parser": "^5.38.0", @@ -48,7 +49,6 @@ "mini-css-extract-plugin": "^2.6.1", "npm-run-all": "^4.1.5", "prettier": "^2.7.1", - "puppeteer": "^19.0.0", "style-loader": "^3.3.1", "stylus": "^0.59.0", "stylus-loader": "^7.0.0", @@ -58,6 +58,9 @@ "webpack": "^5.74.0", "webpack-cli": "^4.10.0", "webpack-dev-server": "^4.11.1" + }, + "engines": { + "npm": ">=8.2.3" } }, "node_modules/@adobe/css-tools": { @@ -3572,6 +3575,22 @@ "@parcel/core": "^2.6.2" } }, + "node_modules/@playwright/test": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.27.1.tgz", + "integrity": "sha512-mrL2q0an/7tVqniQQF6RBL2saskjljXzqNcCOVMUjRIgE6Y38nCNaP+Dc2FBW06bcpD3tqIws/HT9qiMHbNU0A==", + "dev": true, + "dependencies": { + "@types/node": "*", + "playwright-core": "1.27.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@pmmmwh/react-refresh-webpack-plugin": { "version": "0.5.8", "resolved": "https://registry.npmjs.org/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.8.tgz", @@ -5097,18 +5116,6 @@ "node": ">=8.9" } }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dev": true, - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -8568,12 +8575,6 @@ "node": ">=10.0.0" } }, - "node_modules/devtools-protocol": { - "version": "0.0.1045489", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1045489.tgz", - "integrity": "sha512-D+PTmWulkuQW4D1NTiCRCFxF7pQPn0hgp4YyX4wAQ6xYXKOadSWPR3ENGDQ47MW/Ewc9v2rpC/UEEGahgBYpSQ==", - "dev": true - }, "node_modules/devtools/node_modules/agent-base": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz", @@ -13933,19 +13934,6 @@ "node": ">=10.19.0" } }, - "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dev": true, - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -18477,6 +18465,18 @@ "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==" }, + "node_modules/playwright-core": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.27.1.tgz", + "integrity": "sha512-9EmeXDncC2Pmp/z+teoVYlvmPWUC6ejSSYZUln7YaP89Z6lpAaiaAnqroUt/BoLo8tn7WYShcfaCh+xofZa44Q==", + "dev": true, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/postcss": { "version": "8.4.18", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.18.tgz", @@ -19249,44 +19249,6 @@ "node": ">=8" } }, - "node_modules/puppeteer": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.1.1.tgz", - "integrity": "sha512-nyIytOp1mYagiVeKkWODuMAGJoeQkcGNy7utkm2BN2d2r90n1ezO1tM4ld2V3vpP4u2kGk20obqv/Lj0Icd3KA==", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "cosmiconfig": "7.0.1", - "https-proxy-agent": "5.0.1", - "progress": "2.0.3", - "proxy-from-env": "1.1.0", - "puppeteer-core": "19.1.1" - }, - "engines": { - "node": ">=14.1.0" - } - }, - "node_modules/puppeteer-core": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.1.1.tgz", - "integrity": "sha512-jV26Ke0VFel4MoXLjqm50uAW2uwksTP6Md1tvtXqWqXM5FyboKI6E9YYJ1qEQilUAqlhgGq8xLN5+SL8bPz/kw==", - "dev": true, - "dependencies": { - "cross-fetch": "3.1.5", - "debug": "4.3.4", - "devtools-protocol": "0.0.1045489", - "extract-zip": "2.0.1", - "https-proxy-agent": "5.0.1", - "proxy-from-env": "1.1.0", - "rimraf": "3.0.2", - "tar-fs": "2.1.1", - "unbzip2-stream": "1.4.3", - "ws": "8.9.0" - }, - "engines": { - "node": ">=14.1.0" - } - }, "node_modules/qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", @@ -27092,6 +27054,16 @@ "nullthrows": "^1.1.1" } }, + "@playwright/test": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.27.1.tgz", + "integrity": "sha512-mrL2q0an/7tVqniQQF6RBL2saskjljXzqNcCOVMUjRIgE6Y38nCNaP+Dc2FBW06bcpD3tqIws/HT9qiMHbNU0A==", + "dev": true, + "requires": { + "@types/node": "*", + "playwright-core": "1.27.1" + } + }, "@pmmmwh/react-refresh-webpack-plugin": { "version": "0.5.8", "resolved": "https://registry.npmjs.org/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.8.tgz", @@ -28293,15 +28265,6 @@ "regex-parser": "^2.2.11" } }, - "agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "dev": true, - "requires": { - "debug": "4" - } - }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -30991,12 +30954,6 @@ } } }, - "devtools-protocol": { - "version": "0.0.1045489", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1045489.tgz", - "integrity": "sha512-D+PTmWulkuQW4D1NTiCRCFxF7pQPn0hgp4YyX4wAQ6xYXKOadSWPR3ENGDQ47MW/Ewc9v2rpC/UEEGahgBYpSQ==", - "dev": true - }, "di": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", @@ -34896,16 +34853,6 @@ "resolve-alpn": "^1.0.0" } }, - "https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "dev": true, - "requires": { - "agent-base": "6", - "debug": "4" - } - }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -38196,6 +38143,12 @@ "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==" }, + "playwright-core": { + "version": "1.27.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.27.1.tgz", + "integrity": "sha512-9EmeXDncC2Pmp/z+teoVYlvmPWUC6ejSSYZUln7YaP89Z6lpAaiaAnqroUt/BoLo8tn7WYShcfaCh+xofZa44Q==", + "dev": true + }, "postcss": { "version": "8.4.18", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.18.tgz", @@ -38700,37 +38653,6 @@ "escape-goat": "^2.0.0" } }, - "puppeteer": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-19.1.1.tgz", - "integrity": "sha512-nyIytOp1mYagiVeKkWODuMAGJoeQkcGNy7utkm2BN2d2r90n1ezO1tM4ld2V3vpP4u2kGk20obqv/Lj0Icd3KA==", - "dev": true, - "requires": { - "cosmiconfig": "7.0.1", - "https-proxy-agent": "5.0.1", - "progress": "2.0.3", - "proxy-from-env": "1.1.0", - "puppeteer-core": "19.1.1" - } - }, - "puppeteer-core": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-19.1.1.tgz", - "integrity": "sha512-jV26Ke0VFel4MoXLjqm50uAW2uwksTP6Md1tvtXqWqXM5FyboKI6E9YYJ1qEQilUAqlhgGq8xLN5+SL8bPz/kw==", - "dev": true, - "requires": { - "cross-fetch": "3.1.5", - "debug": "4.3.4", - "devtools-protocol": "0.0.1045489", - "extract-zip": "2.0.1", - "https-proxy-agent": "5.0.1", - "proxy-from-env": "1.1.0", - "rimraf": "3.0.2", - "tar-fs": "2.1.1", - "unbzip2-stream": "1.4.3", - "ws": "8.9.0" - } - }, "qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", @@ -38781,7 +38703,7 @@ "requires": { "@mdx-js/react": "^2.1.5", "babel-preset-gatsby": "^2.24.0", - "classnames": "*", + "classnames": "^2.3.2", "gatsby": "^4.24.5", "gatsby-plugin-feed": "^4.24.0", "gatsby-plugin-google-analytics": "^4.24.0", diff --git a/package.json b/package.json index e9b4396502..af679931f1 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "@babel/core": "^7.19.3", "@babel/preset-env": "^7.19.4", + "@playwright/test": "^1.27.1", "@types/jasmine": "^4.3.0", "@typescript-eslint/eslint-plugin": "^5.38.0", "@typescript-eslint/parser": "^5.38.0", @@ -53,7 +54,6 @@ "mini-css-extract-plugin": "^2.6.1", "npm-run-all": "^4.1.5", "prettier": "^2.7.1", - "puppeteer": "^19.0.0", "style-loader": "^3.3.1", "stylus": "^0.59.0", "stylus-loader": "^7.0.0", @@ -97,7 +97,7 @@ "website:develop": "npm run develop -w website -- --port $npm_package_config_ports_gatsby", "test": "npm run test:unit; npm run test:random", "test:all": "npm run test:unit; npm run test:functional; npm run test:random", - "test:functional": "./_develop/scripts/puppeteer.sh", + "test:e2e": "npx playwright test", "test:unit": "npm run build; karma start _develop/karma.config.js", "test:unit:ci": "npm run build; karma start _develop/karma.config.js --reporters dots,saucelabs", "test:random": "ts-node --preferTsExts -O '{\"module\":\"commonjs\"}' ./node_modules/.bin/jasmine test/random.ts", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000000..edd7709124 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,28 @@ +import type { PlaywrightTestConfig } from '@playwright/test'; +import { devices } from '@playwright/test'; + +const config: PlaywrightTestConfig = { + testDir: './e2e', + testMatch: '*.spec.ts', + timeout: 30 * 1000, + expect: { + timeout: 5000, + }, + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'list', + use: { + actionTimeout: 0, + trace: 'on-first-retry', + }, + projects: [ + { name: 'Chrome', use: { ...devices['Desktop Chrome'] } }, + { name: 'Firefox', use: { ...devices['Desktop Firefox'] } }, + { name: 'Safari', use: { ...devices['Desktop Safari'] } }, + { name: 'Edge', use: { channel: 'msedge' } }, + ], +}; + +export default config; diff --git a/test/functional/epic.js b/test/functional/epic.js deleted file mode 100644 index 4ba99ab084..0000000000 --- a/test/functional/epic.js +++ /dev/null @@ -1,254 +0,0 @@ -const puppeteer = require('puppeteer'); - -jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; - -const SHORTKEY = process.platform === 'darwin' ? 'Meta' : 'Control'; - -const CHAPTER = 'Chapter 1. Loomings.'; -const P1 = - 'Call me Ishmael. Some years ago—never mind how long precisely-having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.'; -const P2 = - 'There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs—commerce surrounds it with her surf. Right and left, the streets take you waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there.'; - -describe('quill', function () { - it('compose an epic', async function () { - const browser = await puppeteer.launch({ - headless: false, - }); - const page = await browser.newPage(); - - await page.goto('http://localhost:9000/standalone/full/'); - await page.waitForSelector('.ql-editor', { timeout: 10000 }); - const title = await page.title(); - expect(title).toEqual('Full Editor - Quill Rich Text Editor'); - - await page.type('.ql-editor', 'The Whale'); - let html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual('

The Whale

'); - - await page.keyboard.press('Enter'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual('

The Whale


'); - - await page.keyboard.press('Enter'); - await page.keyboard.press('Tab'); - await page.type('.ql-editor', P1); - await page.keyboard.press('Enter'); - await page.keyboard.press('Enter'); - await page.type('.ql-editor', P2); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

The Whale

', - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - // More than enough to get to top - await Promise.all( - Array(40) - .fill(0) - .map(() => page.keyboard.press('ArrowUp')), - ); - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('Enter'); - await page.type('.ql-editor', CHAPTER); - await page.keyboard.press('Enter'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

The Whale

', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - // More than enough to get to top - await Promise.all( - Array(20) - .fill(0) - .map(() => page.keyboard.press('ArrowUp')), - ); - await page.keyboard.press('ArrowRight'); - await page.keyboard.press('ArrowRight'); - await page.keyboard.press('ArrowRight'); - await page.keyboard.press('ArrowRight'); - await page.keyboard.press('Backspace'); - await page.keyboard.press('Backspace'); - await page.keyboard.press('Backspace'); - await page.keyboard.press('Backspace'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Whale

', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.keyboard.press('Delete'); - await page.keyboard.press('Delete'); - await page.keyboard.press('Delete'); - await page.keyboard.press('Delete'); - await page.keyboard.press('Delete'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '


', - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.keyboard.press('Delete'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '


', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.click('.ql-toolbar .ql-bold'); - await page.click('.ql-toolbar .ql-italic'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

\uFEFF

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - let bold = await page.$('.ql-toolbar .ql-bold.ql-active'); - let italic = await page.$('.ql-toolbar .ql-italic.ql-active'); - expect(bold).not.toBe(null); - expect(italic).not.toBe(null); - - await page.type('.ql-editor', 'Moby Dick'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - bold = await page.$('.ql-toolbar .ql-bold.ql-active'); - italic = await page.$('.ql-toolbar .ql-italic.ql-active'); - expect(bold).not.toBe(null); - expect(italic).not.toBe(null); - - await page.keyboard.press('ArrowRight'); - await page.keyboard.down('Shift'); - await Promise.all( - Array(CHAPTER.length) - .fill(0) - .map(() => page.keyboard.press('ArrowRight')), - ); - await page.keyboard.up('Shift'); - bold = await page.$('.ql-toolbar .ql-bold.ql-active'); - italic = await page.$('.ql-toolbar .ql-italic.ql-active'); - expect(bold).toBe(null); - expect(italic).toBe(null); - - await page.keyboard.down(SHORTKEY); - await page.keyboard.press('b'); - await page.keyboard.up(SHORTKEY); - bold = await page.$('.ql-toolbar .ql-bold.ql-active'); - expect(bold).not.toBe(null); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - - await page.keyboard.press('ArrowLeft'); - await page.keyboard.press('ArrowUp'); - await page.click('.ql-toolbar .ql-header[value="1"]'); - html = await page.$eval('.ql-editor', e => e.innerHTML); - expect(html).toEqual( - [ - '

Moby Dick

', - `

${CHAPTER}

`, - '


', - `

\t${P1}

`, - '


', - `

${P2}

`, - ].join(''), - ); - const header = await page.$('.ql-toolbar .ql-header.ql-active[value="1"]'); - expect(header).not.toBe(null); - - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('Enter'); - await page.keyboard.press('Enter'); - await page.keyboard.press('ArrowUp'); - await page.type('.ql-editor', 'AA'); - await page.keyboard.press('ArrowLeft'); - await page.keyboard.down(SHORTKEY); - await page.keyboard.press('b'); - await page.keyboard.press('b'); - await page.keyboard.up(SHORTKEY); - await page.type('.ql-editor', 'B'); - html = await page.$$eval('.ql-editor p', paras => paras[2].innerHTML); - expect(html).toBe('ABA'); - await page.keyboard.down(SHORTKEY); - await page.keyboard.press('b'); - await page.keyboard.up(SHORTKEY); - await page.type('.ql-editor', 'C'); - await page.keyboard.down(SHORTKEY); - await page.keyboard.press('b'); - await page.keyboard.up(SHORTKEY); - await page.type('.ql-editor', 'D'); - html = await page.$$eval('.ql-editor p', paras => paras[2].innerHTML); - expect(html).toBe('ABCDA'); - const selection = await page.evaluate(getSelectionInTextNode); - expect(selection).toBe('["DA",1,"DA",1]'); - - // await page.waitFor(1000000); - await browser.close(); - }); -}); - -function getSelectionInTextNode() { - const { anchorNode, anchorOffset, focusNode, focusOffset } = - document.getSelection(); - return JSON.stringify([ - anchorNode.data, - anchorOffset, - focusNode.data, - focusOffset, - ]); -}