Skip to content

Migration to Vite#1073

Merged
jfhenon merged 7 commits into
masterfrom
Vite
Dec 7, 2025
Merged

Migration to Vite#1073
jfhenon merged 7 commits into
masterfrom
Vite

Conversation

@jfhenon
Copy link
Copy Markdown
Collaborator

@jfhenon jfhenon commented Nov 29, 2025

PR description

Lot of changes in the build but highly simplified, modern and much faster.

Summary by Sourcery

Migrate the project’s build and dev tooling from Rollup/web-dev-server/Cypress to a Vite-based setup with Vitest and Playwright, updating configs, scripts, and tests accordingly.

New Features:

  • Add Vite-based build configurations for the main editor bundle and the svgcanvas and react-test packages, including IIFE and xdomain entry HTML pages.
  • Introduce Playwright end-to-end test suite with shared helpers, fixtures, and configuration, including Istanbul coverage integration.
  • Add Vitest-based unit and locale tests driven by a Vite test configuration.

Enhancements:

  • Simplify npm scripts for building, serving, and testing by standardizing on Vite for dev/preview and consolidating test commands.
  • Replace JSX usage in the react-test package runtime integration with explicit React.createElement calls to avoid JSX tooling requirements at runtime.
  • Adjust dynamic imports and HTML asset handling to be compatible with Vite’s bundling and analysis, including plugin-based string loading of HTML templates and dialogs.

Documentation:

  • Update development and README documentation to describe the new Vitest unit tests and Playwright-based end-to-end testing workflow instead of Cypress.

Tests:

  • Port existing Cypress unit and UI tests to Vitest unit tests and Playwright e2e specs, including browser-bug regression coverage and clipboard/UI interaction scenarios.

Chores:

  • Remove legacy Rollup, Cypress, and web-dev-server configuration, snapshots, and support files that are no longer used with the Vite-based toolchain.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 29, 2025

Reviewer's Guide

Migrates the project from Rollup/web-dev-server/Cypress to a Vite-based build and test setup, including new Vite configs for the main app and packages, Vitest unit tests, Playwright e2e harness with coverage, and updated HTML/bootstrap code for ES and IIFE editor entrypoints.

Sequence diagram for Playwright-based e2e test execution with Vite preview

sequenceDiagram
  actor Dev
  participant Npm as NpmTestE2E
  participant RunE2E as RunE2EScript
  participant Play as PlaywrightCLI
  participant WebSrv as PlaywrightWebServer
  participant VitePrev as VitePreviewServer
  participant App as SVGEditorApp
  participant Cov as NYC

  Dev->>Npm: npm run test:e2e
  Npm->>RunE2E: node scripts/run-e2e.mjs
  RunE2E->>RunE2E: set COVERAGE=true
  RunE2E->>RunE2E: sanitize env (unset ELECTRON_RUN_AS_NODE)

  RunE2E->>Play: npx playwright --version
  Play-->>RunE2E: version ok

  RunE2E->>RunE2E: rimraf .nyc_output/*
  RunE2E->>Play: npx playwright test

  Play->>WebSrv: start configured web server
  WebSrv->>VitePrev: npm run start:e2e (vite preview)
  VitePrev->>App: serve dist/editor at http://localhost:8000

  loop e2e test cases
    Play->>App: HTTP requests to baseURL (editor pages)
    App-->>Play: responses and DOM
  end

  Play-->>RunE2E: tests complete (exit code)
  RunE2E->>Cov: npx nyc report (text-summary,json-summary)
  Cov-->>Dev: coverage reports
Loading

File-Level Changes

Change Details Files
Replace Rollup and web-dev-server build/test scripts with Vite, Vitest, and Playwright workflows.
  • Update root npm scripts to use Vite for build/serve, Vitest for unit tests, and a custom Playwright-based e2e runner with coverage aggregation
  • Simplify lint/test pre-scripts and add dedicated start:e2e and start:iife commands using vite preview
  • Remove legacy Rollup, Babel, Cypress, and related tooling dependencies and add Vite/Vitest/Playwright plugins and jsdom
package.json
package-lock.json
README.md
docs/Development.md
scripts/run-e2e.mjs
Introduce Vite configuration for the main editor app with library output, dynamic import handling, HTML-as-string loading, and Istanbul instrumentation.
  • Define Vite multi-page app config that builds Editor as ES and IIFE bundles into dist/editor with inline dynamic imports and sourcemaps
  • Add plugins to skip default HTML build, treat dialog/panel/template HTML as string assets, and post-process HTML bundle assets
  • Configure dynamic import vars for locales/extensions and enable Istanbul-based coverage when tests run
  • Configure Vitest to run in jsdom, discover tests under tests/**/*.test.js, and collect coverage for locale.js
vite.config.mjs
Add Vite build configurations for svgcanvas and react-test packages and adapt React integration to non-JSX builds.
  • Create Vite library configs for svgcanvas and react-test that output ES bundles to dist with sourcemaps and inline dynamic imports for svgcanvas
  • Configure esbuild JSX handling in the react-test Vite config and define process.env.NODE_ENV for production builds
  • Replace JSX usage in react-test sources with React.createElement so they work with the Vite/esbuild setup
packages/svgcanvas/vite.config.mjs
packages/react-test/vite.config.mjs
packages/svgcanvas/package.json
packages/react-test/package.json
packages/react-test/src/ReactTest.js
packages/react-test/src/index.js
Rework editor HTML entrypoints and xdomain support for the new Vite/IIFE outputs.
  • Add dedicated iife-index.html and xdomain-index.html entry pages that bootstrap the Editor via ES module and IIFE bundles in dist/editor
  • Adjust main editor index.html markup slightly (cleanup link tag) and update xdomain configuration to rely on a runtime XDOMAIN global check instead of Rollup injection
  • Create a static asset copy script that copies HTML, CSS, JS, and image assets into dist/editor after Vite builds
src/editor/index.html
src/editor/xdomain-index.html
src/editor/iife-index.html
src/editor/dialogs/editorPreferencesDialog.html
scripts/copy-static.mjs
Update dynamic import sites and locale/testing code to be compatible with Vite and Vitest.
  • Annotate dynamic import expressions in EditorStartup with /* @vite-ignore */ so Vite tolerates runtime-dynamic extension loading paths
  • Add Vitest locale tests and adjust matrix/math tests to use console logging rather than Cypress logging APIs
  • Introduce a browser-bugs unit test adapted for jsdom and ensure compatibility with missing SVG transform APIs
src/editor/EditorStartup.js
tests/locale.test.js
tests/unit/math.test.js
tests/unit/browser-bugs/removeItem-setAttribute.test.js
Replace Cypress e2e suite with Playwright-based e2e tests and helpers, preserving coverage via Istanbul/nyc.
  • Add Playwright config that runs against vite preview on port 8000 and uses a custom fixture to persist Istanbul coverage from the browser into .nyc_output
  • Implement test helpers for common editor interactions (visiting, setting language/snapping, manipulating canvas and SVG source)
  • Port core Cypress UI/e2e scenarios (clipboard, shapes, tools, zoom, issues, components, scenarios) to Playwright specs under tests/e2e
  • Add a test runner script that ensures Playwright is available, instruments the build with COVERAGE=true, runs the Playwright suite, and then generates nyc coverage reports
  • Remove Cypress configuration, support files, fixtures, and snapshot SVGs as they are no longer used
playwright.config.mjs
tests/e2e/helpers.js
tests/e2e/fixtures.js
tests/e2e/clipboard.spec.js
tests/e2e/control-points.spec.js
tests/e2e/export.spec.js
tests/e2e/issues.spec.js
tests/e2e/scenarios.spec.js
tests/e2e/se-components.spec.js
tests/e2e/shapes-and-image.spec.js
tests/e2e/text-tools.spec.js
tests/e2e/tool-selection.spec.js
tests/e2e/zoom.spec.js
scripts/run-e2e.mjs
cypress.config.mjs
cypress/**/*

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • In vite.config.mjs the vitest test config excludes tests/unit/** even though your migrated unit specs (e.g., tests/unit/*.test.js) live there, so those tests will be skipped unless you adjust the exclude pattern.
  • The new tests/unit/browser-bugs/removeItem-setAttribute.test.js test uses assert without importing it or configuring a global assert for vitest; either import Node's assert module or rewrite the expectations to use expect.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `vite.config.mjs` the vitest `test` config excludes `tests/unit/**` even though your migrated unit specs (e.g., `tests/unit/*.test.js`) live there, so those tests will be skipped unless you adjust the `exclude` pattern.
- The new `tests/unit/browser-bugs/removeItem-setAttribute.test.js` test uses `assert` without importing it or configuring a global assert for vitest; either import Node's `assert` module or rewrite the expectations to use `expect`.

## Individual Comments

### Comment 1
<location> `vite.config.mjs:72` </location>
<code_context>
+    emptyOutDir: true,
+    sourcemap: true,
+    lib: {
+      entry: resolve(__dirname, 'src/editor/Editor.js'),
+      name: 'Editor',
+      formats: ['es', 'iife'],
</code_context>

<issue_to_address>
**issue (bug_risk):** __dirname is not defined in ESM; this will fail at runtime under pure ESM execution.

Because `vite.config.mjs` runs as an ES module, `__dirname` isn’t available and this line will throw `ReferenceError: __dirname is not defined` when Vite loads the config.

Derive the directory from `import.meta.url` instead, e.g.:
```js
const __dirname = new URL('.', import.meta.url).pathname

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'src/editor/Editor.js'),
      // ...
    }
  }
})
```
(adjust as needed for your path normalization requirements).
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread vite.config.mjs
emptyOutDir: true,
sourcemap: true,
lib: {
entry: resolve(__dirname, 'src/editor/Editor.js'),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): __dirname is not defined in ESM; this will fail at runtime under pure ESM execution.

Because vite.config.mjs runs as an ES module, __dirname isn’t available and this line will throw ReferenceError: __dirname is not defined when Vite loads the config.

Derive the directory from import.meta.url instead, e.g.:

const __dirname = new URL('.', import.meta.url).pathname

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'src/editor/Editor.js'),
      // ...
    }
  }
})

(adjust as needed for your path normalization requirements).

@jfhenon jfhenon force-pushed the Vite branch 2 times, most recently from 111abd9 to fc7b936 Compare November 29, 2025 13:25
@jfhenon jfhenon force-pushed the Vite branch 2 times, most recently from fac2c1a to 0a1b0e2 Compare December 2, 2025 21:01
extend test coverage
also update svgedit.css
@jfhenon jfhenon merged commit 76c8e42 into master Dec 7, 2025
6 checks passed
@jfhenon jfhenon deleted the Vite branch December 7, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant