mirror of
https://github.com/penpot/penpot.git
synced 2026-11-01 15:40:41 +00:00
A copy text had three override subgroups: its letters, any style, and its structure (the number of paragraphs or runs). One style override kept every other style of the main out (F72), letters and a style together kept everything out (F73), a structure change kept the main's styles out unless both texts had one style (F74), which the editors' content never had (F79), and alignment, direction and vertical alignment overrides were lost at the next sync (F76). Now a copy text has :text-content-text for its letters and line breaks and one group per style unit: family, weight (with style and variant), size, line height, spacing, decoration, case, fills, typography, alignment, direction and vertical alignment (cttx/style-units). An edit sets the groups of what it changes: a letter both texts share that changes its style, or a style that was not in the text before, so typed letters touch no style. A token in the content sets the groups of the styles it sets, and token sync of a text follows them. Sync and the keep-touched variant switch share one merge (cttx/merge-overrides): the letters of one side, and each unit from its side placed on them. A unit with one value applies everywhere; else letters both texts share (stretches of three or more) take the source's style, and the rest follow the letter before them. The switch carries an override only when the old and new mains agree on it (F77, F81), and the copy then holds the groups its result differs in. A typography reference stays only when every unit it sets comes from its side. The variant id goes with the weight; where the family comes from the other side, the frontend has to pick the family's closest variant. app.common.types.text reads a content as letters, each with its run and paragraph, and builds the content back from them; it gives the style of one unit for a letter, compares styles by what they show, and finds the letters two texts share with a letter diff (Myers). The component contract memory describes the model. Files older than this keep :text-content-attribute and :text-content-structure, read as every group they may cover until the migration recomputes them. Tests whose expected values the model changes: text-sync-test (the copy's weight, letters or new run no longer keep the main's size out; the letters read whole), text-touched-test (its edits went to the paragraph node, which shows nothing; they now edit the run), variants-switch-test (the copies with two runs keep their letters across a switch, and the size override the mains agree on), the editor output table, case Y and the notation test (new groups). The 1j pins of F72-F79 and F81 go; F79's direct test of equal-attrs? becomes a sync of editor content. A new check holds the production override rule to the 1j reference rule. New tests: the letter view, and a detached, duplicated or reset copy text keeping or clearing its override groups. Benchmark (lower quantile, ms; baseline / now / ratio): deepest-edit-through-three-levels 35.2 / 36.6 / 1.04 edit-through-a-chain-of-dependents 68.9 / 67.2 / 0.98 library-update-into-copies 83.1 / 72.5 / 0.87 main-edit-into-10-copies 1.8 / 1.5 / 0.82 main-edit-into-100-copies 15.4 / 14.9 / 0.97 main-edit-into-1000-copies 153.1 / 153.4 / 1.00 variant-switch-into-copies 32.1 / 27.1 / 0.85 The worlds hold no text. A main text edit synced into 100 copy texts that changed their letters takes 40 ms, against 29 ms before: the merge aligns the letters of each copy with the main's. AI-assisted-by: claude-opus-5-5
419 lines
15 KiB
Clojure
419 lines
15 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns common-tests.runner
|
|
(:require
|
|
#?(:clj [common-tests.fressian-test])
|
|
#?(:cljs [app.common.logging :as l])
|
|
#?(:cljs [clojure.string :as str])
|
|
#?(:cljs [clojure.tools.cli :refer [parse-opts]])
|
|
#?(:cljs [goog.object :as gobj])
|
|
[clojure.test :as t]
|
|
[common-tests.attrs-test]
|
|
[common-tests.buffer-test]
|
|
[common-tests.colors-test]
|
|
[common-tests.data-test]
|
|
[common-tests.features-test]
|
|
[common-tests.files-builder-test]
|
|
[common-tests.files-changes-test]
|
|
[common-tests.files-migrations-0025-test]
|
|
[common-tests.files-migrations-0026-test]
|
|
[common-tests.files-migrations-test]
|
|
[common-tests.files.comp-processors-test]
|
|
[common-tests.files.convert-swap-slots-test]
|
|
[common-tests.files.helpers-test]
|
|
[common-tests.files.repair-components-test]
|
|
[common-tests.files.repair-test]
|
|
[common-tests.files.shapes-builder-test]
|
|
[common-tests.files.tokens-test]
|
|
[common-tests.files.validate-test]
|
|
[common-tests.geom-align-test]
|
|
[common-tests.geom-bounds-layout-nil-test]
|
|
[common-tests.geom-bounds-map-test]
|
|
[common-tests.geom-flex-layout-test]
|
|
[common-tests.geom-grid-layout-test]
|
|
[common-tests.geom-grid-test]
|
|
[common-tests.geom-image-bounds-resize-test]
|
|
[common-tests.geom-line-test]
|
|
[common-tests.geom-modif-tree-test]
|
|
[common-tests.geom-modifiers-test]
|
|
[common-tests.geom-point-test]
|
|
[common-tests.geom-proportions-test]
|
|
[common-tests.geom-rect-test]
|
|
[common-tests.geom-shapes-common-test]
|
|
[common-tests.geom-shapes-constraints-test]
|
|
[common-tests.geom-shapes-corners-test]
|
|
[common-tests.geom-shapes-effects-test]
|
|
[common-tests.geom-shapes-intersect-test]
|
|
[common-tests.geom-shapes-strokes-test]
|
|
[common-tests.geom-shapes-test]
|
|
[common-tests.geom-shapes-text-test]
|
|
[common-tests.geom-shapes-tree-seq-test]
|
|
[common-tests.geom-snap-test]
|
|
[common-tests.geom-test]
|
|
[common-tests.helpers-test]
|
|
[common-tests.logging-test]
|
|
[common-tests.logic.chained-propagation-test]
|
|
[common-tests.logic.comp-creation-test]
|
|
[common-tests.logic.comp-detach-with-nested-test]
|
|
[common-tests.logic.comp-flex-interactions-test]
|
|
[common-tests.logic.comp-main-edit-breaks-copy-slots-test]
|
|
[common-tests.logic.comp-move-swapped-copies-test]
|
|
[common-tests.logic.comp-reset-test]
|
|
[common-tests.logic.comp-sync-test]
|
|
[common-tests.logic.comp-touched-test]
|
|
[common-tests.logic.composable-runner-test]
|
|
[common-tests.logic.composable-sync-test]
|
|
[common-tests.logic.copying-and-duplicating-test]
|
|
[common-tests.logic.duplicated-pages-test]
|
|
[common-tests.logic.library-asset-sync-test]
|
|
[common-tests.logic.move-shapes-test]
|
|
[common-tests.logic.multiple-nesting-levels-test]
|
|
[common-tests.logic.swap-and-reset-test]
|
|
[common-tests.logic.swap-as-override-test]
|
|
[common-tests.logic.swap-group-test]
|
|
[common-tests.logic.swap-keeps-id-test]
|
|
[common-tests.logic.text-editor-output-test]
|
|
[common-tests.logic.text-notation-test]
|
|
[common-tests.logic.text-override-operations-test]
|
|
[common-tests.logic.text-override-rule-test]
|
|
[common-tests.logic.text-override-switch-test]
|
|
[common-tests.logic.text-override-sync-test]
|
|
[common-tests.logic.text-sync-test]
|
|
[common-tests.logic.text-touched-test]
|
|
[common-tests.logic.token-apply-test]
|
|
[common-tests.logic.token-test]
|
|
[common-tests.logic.variants-switch-target-test]
|
|
[common-tests.logic.variants-switch-test]
|
|
[common-tests.logic.variants-test]
|
|
[common-tests.math-test]
|
|
[common-tests.media-test]
|
|
[common-tests.path-names-test]
|
|
[common-tests.record-test]
|
|
[common-tests.schema-test]
|
|
[common-tests.spec-test]
|
|
[common-tests.svg-path-test]
|
|
[common-tests.svg-test]
|
|
[common-tests.text-test]
|
|
[common-tests.time-test]
|
|
[common-tests.token-test]
|
|
[common-tests.types-shape-tree-test]
|
|
[common-tests.types.absorb-assets-test]
|
|
[common-tests.types.color-test]
|
|
[common-tests.types.components-test]
|
|
[common-tests.types.container-test]
|
|
[common-tests.types.file-test]
|
|
[common-tests.types.fill-test]
|
|
[common-tests.types.font-test]
|
|
[common-tests.types.modifiers-test]
|
|
[common-tests.types.objects-map-test]
|
|
[common-tests.types.organization-test]
|
|
[common-tests.types.path-data-test]
|
|
[common-tests.types.plugins-test]
|
|
[common-tests.types.shape-decode-encode-test]
|
|
[common-tests.types.shape-interactions-test]
|
|
[common-tests.types.shape-layout-test]
|
|
[common-tests.types.stroke-test]
|
|
[common-tests.types.text-letters-test]
|
|
[common-tests.types.text-test]
|
|
[common-tests.types.token-test]
|
|
[common-tests.types.tokens-lib-test]
|
|
[common-tests.types.tokens-migrations-test]
|
|
[common-tests.types.tokens-status-test]
|
|
[common-tests.types.variant-test]
|
|
[common-tests.undo-stack-test]
|
|
[common-tests.uuid-test]
|
|
[common-tests.variant-test]))
|
|
|
|
(def test-namespaces
|
|
[#?(:clj 'common-tests.fressian-test)
|
|
'common-tests.attrs-test
|
|
'common-tests.buffer-test
|
|
'common-tests.colors-test
|
|
'common-tests.data-test
|
|
'common-tests.features-test
|
|
'common-tests.files-builder-test
|
|
'common-tests.files-changes-test
|
|
'common-tests.files-migrations-0025-test
|
|
'common-tests.files-migrations-0026-test
|
|
'common-tests.files-migrations-test
|
|
'common-tests.files.comp-processors-test
|
|
'common-tests.files.convert-swap-slots-test
|
|
'common-tests.files.helpers-test
|
|
'common-tests.files.repair-components-test
|
|
'common-tests.files.repair-test
|
|
'common-tests.files.shapes-builder-test
|
|
'common-tests.files.tokens-test
|
|
'common-tests.files.validate-test
|
|
'common-tests.geom-align-test
|
|
'common-tests.geom-bounds-layout-nil-test
|
|
'common-tests.geom-bounds-map-test
|
|
'common-tests.geom-flex-layout-test
|
|
'common-tests.geom-grid-layout-test
|
|
'common-tests.geom-grid-test
|
|
'common-tests.geom-image-bounds-resize-test
|
|
'common-tests.geom-line-test
|
|
'common-tests.geom-modif-tree-test
|
|
'common-tests.geom-modifiers-test
|
|
'common-tests.geom-point-test
|
|
'common-tests.geom-proportions-test
|
|
'common-tests.geom-rect-test
|
|
'common-tests.geom-shapes-common-test
|
|
'common-tests.geom-shapes-constraints-test
|
|
'common-tests.geom-shapes-corners-test
|
|
'common-tests.geom-shapes-effects-test
|
|
'common-tests.geom-shapes-intersect-test
|
|
'common-tests.geom-shapes-strokes-test
|
|
'common-tests.geom-shapes-test
|
|
'common-tests.geom-shapes-text-test
|
|
'common-tests.geom-shapes-tree-seq-test
|
|
'common-tests.geom-snap-test
|
|
'common-tests.geom-test
|
|
'common-tests.helpers-test
|
|
'common-tests.logging-test
|
|
'common-tests.logic.chained-propagation-test
|
|
'common-tests.logic.comp-creation-test
|
|
'common-tests.logic.comp-detach-with-nested-test
|
|
'common-tests.logic.comp-flex-interactions-test
|
|
'common-tests.logic.comp-main-edit-breaks-copy-slots-test
|
|
'common-tests.logic.comp-move-swapped-copies-test
|
|
'common-tests.logic.comp-reset-test
|
|
'common-tests.logic.comp-sync-test
|
|
'common-tests.logic.comp-touched-test
|
|
'common-tests.logic.composable-runner-test
|
|
'common-tests.logic.composable-sync-test
|
|
'common-tests.logic.copying-and-duplicating-test
|
|
'common-tests.logic.duplicated-pages-test
|
|
'common-tests.logic.library-asset-sync-test
|
|
'common-tests.logic.move-shapes-test
|
|
'common-tests.logic.multiple-nesting-levels-test
|
|
'common-tests.logic.swap-and-reset-test
|
|
'common-tests.logic.swap-as-override-test
|
|
'common-tests.logic.swap-group-test
|
|
'common-tests.logic.swap-keeps-id-test
|
|
'common-tests.logic.text-editor-output-test
|
|
'common-tests.logic.text-notation-test
|
|
'common-tests.logic.text-override-operations-test
|
|
'common-tests.logic.text-override-rule-test
|
|
'common-tests.logic.text-override-switch-test
|
|
'common-tests.logic.text-override-sync-test
|
|
'common-tests.logic.text-sync-test
|
|
'common-tests.logic.text-touched-test
|
|
'common-tests.logic.token-apply-test
|
|
'common-tests.logic.token-test
|
|
'common-tests.logic.variants-switch-target-test
|
|
'common-tests.logic.variants-switch-test
|
|
'common-tests.logic.variants-test
|
|
'common-tests.math-test
|
|
'common-tests.media-test
|
|
'common-tests.path-names-test
|
|
'common-tests.record-test
|
|
'common-tests.schema-test
|
|
'common-tests.spec-test
|
|
'common-tests.svg-path-test
|
|
'common-tests.svg-test
|
|
'common-tests.text-test
|
|
'common-tests.time-test
|
|
'common-tests.token-test
|
|
'common-tests.types-shape-tree-test
|
|
'common-tests.types.absorb-assets-test
|
|
'common-tests.types.color-test
|
|
'common-tests.types.components-test
|
|
'common-tests.types.container-test
|
|
'common-tests.types.file-test
|
|
'common-tests.types.fill-test
|
|
'common-tests.types.font-test
|
|
'common-tests.types.modifiers-test
|
|
'common-tests.types.objects-map-test
|
|
'common-tests.types.organization-test
|
|
'common-tests.types.path-data-test
|
|
'common-tests.types.plugins-test
|
|
'common-tests.types.shape-decode-encode-test
|
|
'common-tests.types.shape-interactions-test
|
|
'common-tests.types.shape-layout-test
|
|
'common-tests.types.stroke-test
|
|
'common-tests.types.text-letters-test
|
|
'common-tests.types.text-test
|
|
'common-tests.types.token-test
|
|
'common-tests.types.tokens-lib-test
|
|
'common-tests.types.tokens-migrations-test
|
|
'common-tests.types.tokens-status-test
|
|
'common-tests.types.variant-test
|
|
'common-tests.undo-stack-test
|
|
'common-tests.uuid-test
|
|
'common-tests.variant-test])
|
|
|
|
#?(:cljs
|
|
(assert (every? find-ns-obj test-namespaces)
|
|
"test-namespaces contains a namespace that isn't required in runner.cljc"))
|
|
|
|
#?(:cljs (enable-console-print!))
|
|
|
|
#?(:cljs
|
|
(defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m]
|
|
(if (cljs.test/successful? m)
|
|
(.exit js/process 0)
|
|
(.exit js/process 1))))
|
|
#?(:cljs
|
|
(defmethod t/report [:cljs.test/default :begin-test-var] [m]
|
|
(let [v (:var m)]
|
|
(println (str " ▸ " (:ns (meta v)) "/" (:name (meta v)))))))
|
|
|
|
#?(:cljs
|
|
(do
|
|
;; This runner intentionally mirrors frontend-tests.runner. Both runners need
|
|
;; forwarded CLI args, focused namespace/var execution, fixture preservation,
|
|
;; and app log-level setup. A shared helper could own those mechanics, but we
|
|
;; keep the logic local while there are only two test targets because sharing
|
|
;; it would add cross-module test classpath coupling.
|
|
(def ^:private log-levels
|
|
#{:trace :debug :info :warn :error})
|
|
|
|
(def cli-options
|
|
[["-f" "--focus FOCUS" "Run one test namespace or one test var, e.g. common-tests.logic.comp-sync-test/test-sync-when-changing-attribute"]
|
|
["-l" "--log-level LEVEL" "Set app logger level: trace|debug|info|warn|error"
|
|
:parse-fn keyword
|
|
:validate [log-levels "must be one of trace, debug, info, warn, error"]]
|
|
["-h" "--help"]])
|
|
|
|
(defn- argv
|
|
[]
|
|
(let [args (->> (.-argv js/process)
|
|
(array-seq)
|
|
(drop 2))]
|
|
(cond-> args
|
|
(= "--" (first args)) rest)))
|
|
|
|
(defn- usage
|
|
[summary]
|
|
(str "Usage: pnpm run test:js -- [options]\n\n"
|
|
"Options:\n"
|
|
summary "\n\n"
|
|
"Focus examples:\n"
|
|
" pnpm run test:js -- --focus common-tests.logic.comp-sync-test\n"
|
|
" pnpm run test:js -- --focus common-tests.logic.comp-sync-test/test-sync-when-changing-attribute\n\n"
|
|
"Log level example (quiets app logging during the run):\n"
|
|
" pnpm run test:js -- --focus common-tests.logic.comp-sync-test --log-level warn"))
|
|
|
|
(defn- fail!
|
|
[message]
|
|
(js/console.error message)
|
|
(.exit js/process 1))
|
|
|
|
(defn- parse-focus
|
|
[focus]
|
|
(let [[ns-name test-name & extra] (str/split focus #"/")]
|
|
(cond
|
|
(or (str/blank? ns-name) (seq extra))
|
|
(fail! (str "Invalid --focus value: " focus))
|
|
|
|
(some? test-name)
|
|
{:ns (symbol ns-name) :test test-name}
|
|
|
|
:else
|
|
{:ns (symbol ns-name)})))
|
|
|
|
(defn- fixture-value
|
|
[ns-obj fixture-name]
|
|
(let [value (gobj/get ns-obj (munge fixture-name))]
|
|
(when-not (undefined? value)
|
|
value)))
|
|
|
|
(defn- ns-test-vars
|
|
[ns-sym]
|
|
(when-let [ns-obj (find-ns-obj ns-sym)]
|
|
(->> (js-keys ns-obj)
|
|
(keep (fn [key]
|
|
(some-> (gobj/get ns-obj key)
|
|
(.-cljs$lang$var))))
|
|
(filter (comp :test meta))
|
|
(sort-by (comp :line meta)))))
|
|
|
|
(defn- ns-fixtures
|
|
[ns-sym vars]
|
|
(when-let [ns-obj (find-ns-obj ns-sym)]
|
|
(let [ns-key (or (some-> vars first meta :ns) ns-sym)
|
|
once-fixtures (fixture-value ns-obj "cljs-test-once-fixtures")
|
|
each-fixtures (fixture-value ns-obj "cljs-test-each-fixtures")]
|
|
{:once (when once-fixtures {ns-key once-fixtures})
|
|
:each (when each-fixtures {ns-key each-fixtures})})))
|
|
|
|
(defn- selected-tests
|
|
[{:keys [ns test]}]
|
|
(when-not (some #{ns} test-namespaces)
|
|
(fail! (str "Unknown test namespace: " ns)))
|
|
(let [vars (vec (ns-test-vars ns))]
|
|
(when (empty? vars)
|
|
(fail! (str "No tests found in namespace: " ns)))
|
|
(if test
|
|
(let [test-sym (symbol test)
|
|
test-var (some #(when (= test-sym (:name (meta %))) %) vars)]
|
|
(if test-var
|
|
{:vars [test-var]
|
|
:fixtures (ns-fixtures ns [test-var])}
|
|
(fail! (str "Unknown test var: " ns "/" test))))
|
|
{:vars vars
|
|
:fixtures (ns-fixtures ns vars)})))
|
|
|
|
(defn- merge-fixtures
|
|
[fixtures]
|
|
{:once (apply merge (keep :once fixtures))
|
|
:each (apply merge (keep :each fixtures))})
|
|
|
|
(defn- run-test-vars!
|
|
[tests]
|
|
(let [vars (vec (mapcat :vars tests))
|
|
fixtures (merge-fixtures (map :fixtures tests))
|
|
env (assoc (t/empty-env)
|
|
:once-fixtures (:once fixtures)
|
|
:each-fixtures (:each fixtures))
|
|
summary (volatile! {:test 0 :pass 0 :fail 0 :error 0 :type :summary})]
|
|
|
|
(t/set-env! env)
|
|
|
|
(t/run-block
|
|
(concat (t/test-vars-block vars)
|
|
[(fn []
|
|
(vswap! summary
|
|
(partial merge-with +)
|
|
(:report-counters (t/get-and-clear-env!))))
|
|
(fn []
|
|
(t/set-env! env)
|
|
(t/report @summary)
|
|
(t/report (assoc @summary :type :end-run-tests))
|
|
(t/clear-env!))]))))
|
|
|
|
(defn- run-focused-test!
|
|
[focus]
|
|
(run-test-vars! [(selected-tests (parse-focus focus))]))
|
|
|
|
(defn- run-all-tests!
|
|
[]
|
|
(run-test-vars! (map #(selected-tests {:ns %}) test-namespaces)))))
|
|
|
|
(defn -main
|
|
[& _args]
|
|
#?(:cljs
|
|
(let [{:keys [options errors summary]} (parse-opts (argv) cli-options)]
|
|
(cond
|
|
(seq errors)
|
|
(fail! (str/join "\n" errors))
|
|
|
|
(:help options)
|
|
(do
|
|
(println (usage summary))
|
|
(.exit js/process 0))
|
|
|
|
:else
|
|
(do
|
|
(when-let [level (:log-level options)]
|
|
(l/setup! {:app level}))
|
|
(if (:focus options)
|
|
(run-focused-test! (:focus options))
|
|
(run-all-tests!)))))
|
|
:clj
|
|
(apply t/run-tests test-namespaces)))
|