-
Notifications
You must be signed in to change notification settings - Fork 46
test(SD-960): add automated SD export + reimport visual tests #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
de926c2
6ebf56d
f042510
e662b16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import config from '../../test-config'; | ||
|
|
||
| const APP_URL = process.env.SUPERDOC_E2E_APP_URL ?? 'http://localhost:4173/'; | ||
| const ROUND_TRIP_EXPORT_DIR = './test-results/sd-export-reimport'; | ||
| const IGNORED_DOCUMENTS = [ | ||
| 'advanced-tables', | ||
| 'msa-list-base-indent', | ||
| 'custom-list-numbering', | ||
| 'sdpr', | ||
| 'ooxml-rFonts-rstyle-linked-combos-demo', | ||
| 'ooxml-color-rstyle-linked-combos-demo', | ||
| 'ooxml-underline-rstyle-linked-combos-demo', | ||
| 'table-of-contents', | ||
| 'table-of-contents-sdt', | ||
| 'tiny-spacing', // FIXME: exportDocx returns undefined for this doc | ||
| ]; | ||
|
|
||
| const documents = fs | ||
| .readdirSync(config.basicDocumentsFolder) | ||
| .filter((name) => !config.ignoreDocuments.includes(name)) | ||
| .filter((name) => /\.docx$/i.test(name)) | ||
| .map((name) => ({ | ||
| fileName: name, | ||
| baseName: name.replace(/\.docx$/i, ''), | ||
| })) | ||
| .filter(({ baseName }) => !IGNORED_DOCUMENTS.includes(baseName)); | ||
|
|
||
| const ensureDir = (dir) => { | ||
| if (!fs.existsSync(dir)) { | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| } | ||
| }; | ||
|
|
||
| const waitForEditorReady = async (page) => { | ||
| const superEditor = page.locator('div.super-editor').first(); | ||
| await expect(superEditor).toBeVisible({ timeout: 10_000 }); | ||
| await page.waitForFunction( | ||
| () => { | ||
| const superdoc = window.superdoc ?? window.superdocdev; | ||
| const editor = superdoc?.activeEditor ?? window.editor; | ||
| return superdoc !== undefined && editor !== undefined && typeof editor.exportDocx === 'function'; | ||
| }, | ||
| null, | ||
| { polling: 100, timeout: 10_000 }, | ||
| ); | ||
| await page.evaluate(() => { | ||
| const superdoc = window.superdoc ?? window.superdocdev; | ||
| if (superdoc) { | ||
| window.superdoc = superdoc; | ||
| window.editor = superdoc.activeEditor; | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const uploadDocument = async (page, filePath) => { | ||
| await page.locator('input[type="file"]').setInputFiles(filePath); | ||
| await waitForEditorReady(page); | ||
| }; | ||
|
|
||
| const exportDocxAsBuffer = async (page) => { | ||
| const serialized = await page.evaluate(async () => { | ||
| const superdoc = window.superdoc ?? window.superdocdev; | ||
| const activeEditor = superdoc?.activeEditor ?? window.editor; | ||
| if (!activeEditor || typeof activeEditor.exportDocx !== 'function') { | ||
| throw new Error('Active editor with exportDocx is not available.'); | ||
| } | ||
| const blob = await activeEditor.exportDocx({ | ||
| isFinalDoc: true, | ||
| }); | ||
| const arrayBuffer = await blob.arrayBuffer(); | ||
| return Array.from(new Uint8Array(arrayBuffer)); | ||
| }); | ||
|
|
||
| return Buffer.from(serialized); | ||
| }; | ||
|
|
||
| ensureDir(ROUND_TRIP_EXPORT_DIR); | ||
|
|
||
| test.describe('SD x SD export (visual)', () => { | ||
| for (const document of documents) { | ||
| test(document.fileName, async ({ page }) => { | ||
| test.setTimeout(60_000); | ||
|
|
||
| await page.goto(APP_URL); | ||
| await uploadDocument(page, path.join(config.basicDocumentsFolder, document.fileName)); | ||
|
|
||
| const exportedDocx = await exportDocxAsBuffer(page); | ||
| const exportedDocPath = path.join(ROUND_TRIP_EXPORT_DIR, `${document.baseName}-roundtrip.docx`); | ||
| fs.writeFileSync(exportedDocPath, exportedDocx); | ||
|
|
||
| await page.goto(APP_URL); | ||
| await uploadDocument(page, exportedDocPath); | ||
|
|
||
| await expect(page).toHaveScreenshot({ | ||
| name: `${document.baseName}.png`, | ||
| fullPage: true, | ||
| timeout: 30_000, | ||
| }); | ||
| }); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this one correct @priya-harbour ? it seems like it's empty, just to confirm we're not missing anything here
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @chittolinag , No, I am updating the screenshots, so I will ping you once everything is ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new visual spec imports
../../test-config, but there is notest-configmodule anywhere undere2e-tests(verified withfind e2e-tests -maxdepth 3 -type f -name 'test-config.*'), so loading the spec will throwCannot find module '../../test-config'before any tests execute. The suite cannot run until the config file is added or the import path corrected.Useful? React with 👍 / 👎.