mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 05:50:35 +00:00
* 🐛 Decode job results with the schema of the job-def A job result is stored as plain JSON, so a uuid comes back as the text it is on disk and a uuid used as a map key comes back as a keyword. The import resolution is a map keyed by file id, and the wizard lost that identity: choosing a library in the link step created no link at all, with no error and with the modal closing as if it had worked. A job-def can now declare a result schema and its precompiled decoder, the pair the params already have, and the substrate applies them when the row is read. A def that declares neither answers with the JSON the row holds, as before; a row whose job-def is gone is read untouched instead of raising. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Type the import result so its resolution keeps uuid keys The resolution of a version 3 import is a map keyed by the new file id, and the result column is plain JSON: without a schema of its own every key came back as a keyword while the :id of the entry came back as text, so the dashboard wizard could not match the file it was linking and created no library link at all. Declare the shape of the resolution (files, done and pending entries and their candidates) and give the job-def its result schema and decoder. The check before the result is stored keeps validating the same schema. Closes #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Take the imported file id from the entry, not the map key The wizard looked a file up in the selection with the key of the resolution map while it had indexed the selection by the :id of the entry. The key is keywordized on its way through the job result, so the lookup missed and the confirm button created no library link at all, with no error and with the modal closing as if it had worked. Take the id from the entry, the source the rest of the wizard already uses, and move the decision to a pure function covered by tests of both shapes of the resolution. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Test that an import result keeps its ids as uuids The regression this branch fixes is only visible through the read path of the substrate: the resolution of an import is a map keyed by the new file id, and a test that works with the value in memory never sees the keys coming back as keywords from the plain JSON column. Import a package whose library needs a replacement chosen by the user, read the result with `jobs/get-job` as the client does, and check the keys, the file ids and the ids of the candidates. Without the result decoder of the import job-def the test answers with text ids. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 📚 Document the result schema of a job-def The memories and the docstring of the substrate said a job result has no schema of its own and comes back as the JSON the row holds. A job-def can now declare its result schema and decoder, and the substrate applies them when the row is read. Keep the rule next to it: a result map keyed by uuid needs its schema declared, or every key comes back as a keyword, and the link-later step of the import wizard takes the file id from the entry and never from the key of the resolution map. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 📚 Fix the documented contract of a job result The docstring of get-job said a result has no schema of its own and comes back as the JSON the row holds, which is what this branch changes: the result is decoded with the schema its job-def declares, and a result that does not conform never reaches the column because the write validates it. Say the same in the management command that stores the result of an external worker, the other writer of the column. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Check the result of a job against its schema before storing it The result of a job crosses a plain JSON column, so a uuid comes back as text and a uuid used as a map key as a keyword. The job-def now declares the schema of its result and the substrate compiles the decoder from it, which is what the read path uses to get the types back. The same schema is the contract of the write path: complete refuses a result that does not conform, with the malli explanation, so nothing invalid reaches the column, and the answer is the same for the runner and for the external worker that completes a job through the management RPC. A job that is no longer completable is skipped without checking, and the read path decodes only: a row written by another version stays readable. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Check the result of an import inside its transaction The check ran after the transaction of the import had committed, so a result the schema does not accept failed the job with the files already created in the destination project: a half imported project and an error. The core decides whether the whole import is kept or rolled back, so the check belongs inside its transaction, which is what turns a contract violation into a rollback. The substrate checks the result again when the job is completed, which is the only net for a job that does not validate its own result. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 🐛 Cover the edges of an import result read by the client The shape of a result with no libraries to resolve, and the one of a version 1 import, is the most common in production and neither was covered by the tests that read a result the way the client does. Cover both through jobs/get-job, and the case of a registry that no longer knows the kind of the row: it answers with the JSON of the column, keywordized keys and uuid as text, instead of raising. Say in the two tests that depend on the decoder what implementation without it makes them fail. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * 📚 Fix the prose and the fixtures of the result contract The result schema of a job-def is what the read decodes with and what the write checks: say that in the memories, with the rule that any uuid of a result needs it, whether a value or a map key. The motive of the wizard helper was a fact this branch makes false: what a key of the resolution map holds depends on the result schema of the job-def that wrote it, so the rule is to read the id from the entry. Same correction in its memory and in the test that pins the shape. The candidates of a pending entry match by slugified name, not by name, and every test row now states the kind of its job, because the name is what resolves its job-def when the result is read or checked. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * ♻️ Keep the wizard link helper private and cover its shape The helper that decides which links the wizard creates belongs to its namespace, as its neighbours do: reach it from the test with @#', the pattern the frontend tests already use for a private helper. Cover the shapes it had no test for: a file with two libraries pending resolution, a file whose libraries were auto-linked, and a selection where only one of two entries was resolved. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> * ♻️ Share one job-row helper across the job tests Three test namespaces had their own copy of the same insert, differing only in the kind of the job and in whether the row holds the resource it consumes. Move it to the test helpers as create-job*, with the kind of the job as its first argument: it is what resolves the job-def of the row when its result is read or checked, so every test states it. The bang of the name goes away with it: the design rules keep it for the mutating API of app.db, and this is a fixture of the tests. The three namespaces lose the requires that only their removed copy used. Relates to #12339 AI-assisted-by: deepseek-v4.1-flash Signed-off-by: Andrey Antukh <niwi@niwi.nz> --------- Signed-off-by: Andrey Antukh <niwi@niwi.nz>
460 lines
18 KiB
Clojure
460 lines
18 KiB
Clojure
(ns frontend-tests.runner
|
|
(:require
|
|
[app.common.logging :as l]
|
|
[cljs.test :as t]
|
|
[clojure.string :as str]
|
|
[clojure.tools.cli :refer [parse-opts]]
|
|
[frontend-tests.basic-shapes-test]
|
|
[frontend-tests.browser-history-test]
|
|
[frontend-tests.code-gen-style-test]
|
|
[frontend-tests.composable-tests.comp.sync-test]
|
|
[frontend-tests.copy-as-svg-test]
|
|
[frontend-tests.data.comments-filters-test]
|
|
[frontend-tests.data.dashboard-test]
|
|
[frontend-tests.data.event-test]
|
|
[frontend-tests.data.exports-assets-test]
|
|
[frontend-tests.data.exports-files-test]
|
|
[frontend-tests.data.fix-deleted-fonts-test]
|
|
[frontend-tests.data.imports-test]
|
|
[frontend-tests.data.jobs-test]
|
|
[frontend-tests.data.nitrate-test]
|
|
[frontend-tests.data.persistence-retry-test]
|
|
[frontend-tests.data.persistence-test]
|
|
[frontend-tests.data.profile-test]
|
|
[frontend-tests.data.repo-test]
|
|
[frontend-tests.data.store-test]
|
|
[frontend-tests.data.svg-upload-test]
|
|
[frontend-tests.data.uploads-test]
|
|
[frontend-tests.data.viewer-test]
|
|
[frontend-tests.data.workspace-colors-test]
|
|
[frontend-tests.data.workspace-comments-test]
|
|
[frontend-tests.data.workspace-context-menu-test]
|
|
[frontend-tests.data.workspace-interactions-test]
|
|
[frontend-tests.data.workspace-mcp-test]
|
|
[frontend-tests.data.workspace-media-test]
|
|
[frontend-tests.data.workspace-pages-test]
|
|
[frontend-tests.data.workspace-path-edition-test]
|
|
[frontend-tests.data.workspace-reflow-test]
|
|
[frontend-tests.data.workspace-shortcuts-test]
|
|
[frontend-tests.data.workspace-texts-test]
|
|
[frontend-tests.data.workspace-thumbnails-test]
|
|
[frontend-tests.data.workspace-versions-test]
|
|
[frontend-tests.debug-logging-test]
|
|
[frontend-tests.errors-governor-test]
|
|
[frontend-tests.errors-test]
|
|
[frontend-tests.fonts-test]
|
|
[frontend-tests.helpers-shapes-test]
|
|
[frontend-tests.logic.bool-move-test]
|
|
[frontend-tests.logic.comp-remove-swap-slots-test]
|
|
[frontend-tests.logic.components-and-tokens]
|
|
[frontend-tests.logic.copy-paste-typography-test]
|
|
[frontend-tests.logic.copying-and-duplicating-test]
|
|
[frontend-tests.logic.frame-guides-test]
|
|
[frontend-tests.logic.groups-test]
|
|
[frontend-tests.logic.ignore-tree-test]
|
|
[frontend-tests.logic.nudge-selected-shapes-test]
|
|
[frontend-tests.logic.pasting-in-containers-test]
|
|
[frontend-tests.logic.path-actions-test]
|
|
[frontend-tests.logic.path-clipboard-test]
|
|
[frontend-tests.logic.path-helpers-test]
|
|
[frontend-tests.logic.path-lifecycle-test]
|
|
[frontend-tests.logic.path-tools-test]
|
|
[frontend-tests.logic.sidebar-transform-coalescing-test]
|
|
[frontend-tests.logic.update-position-test]
|
|
[frontend-tests.logic.wasm-modifiers-nil-id-test]
|
|
[frontend-tests.logic.wasm-pixel-snap-test]
|
|
[frontend-tests.main-errors-test]
|
|
[frontend-tests.main.refs-test]
|
|
[frontend-tests.plugins.comments-test]
|
|
[frontend-tests.plugins.context-shapes-test]
|
|
[frontend-tests.plugins.events-test]
|
|
[frontend-tests.plugins.file-test]
|
|
[frontend-tests.plugins.flex-test]
|
|
[frontend-tests.plugins.format-test]
|
|
[frontend-tests.plugins.grid-test]
|
|
[frontend-tests.plugins.interactions-test]
|
|
[frontend-tests.plugins.library-test]
|
|
[frontend-tests.plugins.local-storage-test]
|
|
[frontend-tests.plugins.management-test]
|
|
[frontend-tests.plugins.page-active-validation-test]
|
|
[frontend-tests.plugins.page-test]
|
|
[frontend-tests.plugins.parser-test]
|
|
[frontend-tests.plugins.register-test]
|
|
[frontend-tests.plugins.shape-bugfixes-test]
|
|
[frontend-tests.plugins.text-test]
|
|
[frontend-tests.plugins.tokens-test]
|
|
[frontend-tests.plugins.user-test]
|
|
[frontend-tests.plugins.utils-test]
|
|
[frontend-tests.plugins.value-objects-test]
|
|
[frontend-tests.render-dimensions-test]
|
|
[frontend-tests.render-wasm.process-objects-test]
|
|
[frontend-tests.render-wasm.serialization-test]
|
|
[frontend-tests.render-wasm.text-editor-apply-styles-test]
|
|
[frontend-tests.render-wasm.text-editor-caret-color-test]
|
|
[frontend-tests.render-wasm.text-editor-content-range-test]
|
|
[frontend-tests.render-wasm.text-paste-test]
|
|
[frontend-tests.render-wasm.webgl-test]
|
|
[frontend-tests.router-test]
|
|
[frontend-tests.svg-fills-test]
|
|
[frontend-tests.svg-filters-test]
|
|
[frontend-tests.text-editor-paste-guard-test]
|
|
[frontend-tests.tokens.context-menu-test]
|
|
[frontend-tests.tokens.copy-paste-props-test]
|
|
[frontend-tests.tokens.import-export-test]
|
|
[frontend-tests.tokens.logic.token-actions-test]
|
|
[frontend-tests.tokens.logic.token-data-test]
|
|
[frontend-tests.tokens.logic.token-remapping-test]
|
|
[frontend-tests.tokens.logic.tokens-status-test]
|
|
[frontend-tests.tokens.referenced-token-value-test]
|
|
[frontend-tests.tokens.style-dictionary-test]
|
|
[frontend-tests.tokens.token-errors-test]
|
|
[frontend-tests.tokens.workspace-tokens-remap-test]
|
|
[frontend-tests.ui.check-updates-test]
|
|
[frontend-tests.ui.color-token-position-test]
|
|
[frontend-tests.ui.colorpicker-token-set-order-test]
|
|
[frontend-tests.ui.comment-input-ime-test]
|
|
[frontend-tests.ui.comments-clustering-test]
|
|
[frontend-tests.ui.comments-position-modifier-test]
|
|
[frontend-tests.ui.dashboard-import-linking-test]
|
|
[frontend-tests.ui.drawarea-test]
|
|
[frontend-tests.ui.ds-controls-numeric-input-test]
|
|
[frontend-tests.ui.error-boundary-test]
|
|
[frontend-tests.ui.gradient-handlers-test]
|
|
[frontend-tests.ui.history-test]
|
|
[frontend-tests.ui.inspect-geometry-test]
|
|
[frontend-tests.ui.inspect-stroke-tokens-test]
|
|
[frontend-tests.ui.jobs-progress-test]
|
|
[frontend-tests.ui.layout-container-multiple-test]
|
|
[frontend-tests.ui.measurements-test]
|
|
[frontend-tests.ui.measures-menu-props-test]
|
|
[frontend-tests.ui.organization-team-switch-test]
|
|
[frontend-tests.ui.routes-test]
|
|
[frontend-tests.ui.settings-password-schema-test]
|
|
[frontend-tests.ui.settings-shortcuts-test]
|
|
[frontend-tests.ui.shape-filters-test]
|
|
[frontend-tests.ui.shortcuts-labels-test]
|
|
[frontend-tests.ui.shortcuts-recording-test]
|
|
[frontend-tests.ui.sidebar-scroll-test]
|
|
[frontend-tests.ui.stroke-menu-test]
|
|
[frontend-tests.ui.text-attrs-multiple-test]
|
|
[frontend-tests.ui.workspace-libraries-test]
|
|
[frontend-tests.util-clipboard-test]
|
|
[frontend-tests.util-object-test]
|
|
[frontend-tests.util-queue-test]
|
|
[frontend-tests.util-range-tree-test]
|
|
[frontend-tests.util-simple-math-test]
|
|
[frontend-tests.util-text-clipboard-test]
|
|
[frontend-tests.util-text-editor-test]
|
|
[frontend-tests.util-webapi-test]
|
|
[frontend-tests.util-zip-test]
|
|
[frontend-tests.util.dom.dnd-test]
|
|
[frontend-tests.worker-snap-test]
|
|
[goog.object :as gobj]))
|
|
|
|
(enable-console-print!)
|
|
|
|
(defmethod t/report [:cljs.test/default :begin-test-var] [m]
|
|
(let [v (:var m)]
|
|
(println (str " ▸ " (:ns (meta v)) "/" (:name (meta v))))))
|
|
|
|
(defmethod t/report [:cljs.test/default :end-run-tests] [m]
|
|
(if (cljs.test/successful? m)
|
|
(.exit js/process 0)
|
|
(.exit js/process 1)))
|
|
|
|
(def test-namespaces
|
|
['frontend-tests.basic-shapes-test
|
|
'frontend-tests.code-gen-style-test
|
|
'frontend-tests.composable-tests.comp.sync-test
|
|
'frontend-tests.copy-as-svg-test
|
|
'frontend-tests.data.comments-filters-test
|
|
'frontend-tests.data.dashboard-test
|
|
'frontend-tests.data.event-test
|
|
'frontend-tests.data.fix-deleted-fonts-test
|
|
'frontend-tests.data.nitrate-test
|
|
'frontend-tests.data.persistence-retry-test
|
|
'frontend-tests.data.persistence-test
|
|
'frontend-tests.data.profile-test
|
|
'frontend-tests.data.repo-test
|
|
'frontend-tests.data.store-test
|
|
'frontend-tests.data.exports-assets-test
|
|
'frontend-tests.data.exports-files-test
|
|
'frontend-tests.data.imports-test
|
|
'frontend-tests.data.jobs-test
|
|
'frontend-tests.data.svg-upload-test
|
|
'frontend-tests.data.uploads-test
|
|
'frontend-tests.data.viewer-test
|
|
'frontend-tests.data.workspace-colors-test
|
|
'frontend-tests.data.workspace-comments-test
|
|
'frontend-tests.data.workspace-context-menu-test
|
|
'frontend-tests.data.workspace-interactions-test
|
|
'frontend-tests.data.workspace-mcp-test
|
|
'frontend-tests.data.workspace-media-test
|
|
'frontend-tests.data.workspace-pages-test
|
|
'frontend-tests.data.workspace-path-edition-test
|
|
'frontend-tests.data.workspace-reflow-test
|
|
'frontend-tests.data.workspace-shortcuts-test
|
|
'frontend-tests.data.workspace-texts-test
|
|
'frontend-tests.data.workspace-thumbnails-test
|
|
'frontend-tests.data.workspace-versions-test
|
|
'frontend-tests.debug-logging-test
|
|
'frontend-tests.errors-governor-test
|
|
'frontend-tests.errors-test
|
|
'frontend-tests.fonts-test
|
|
'frontend-tests.helpers-shapes-test
|
|
'frontend-tests.logic.bool-move-test
|
|
'frontend-tests.logic.comp-remove-swap-slots-test
|
|
'frontend-tests.logic.components-and-tokens
|
|
'frontend-tests.logic.copy-paste-typography-test
|
|
'frontend-tests.logic.copying-and-duplicating-test
|
|
'frontend-tests.logic.frame-guides-test
|
|
'frontend-tests.logic.groups-test
|
|
'frontend-tests.logic.ignore-tree-test
|
|
'frontend-tests.logic.nudge-selected-shapes-test
|
|
'frontend-tests.logic.path-actions-test
|
|
'frontend-tests.logic.path-clipboard-test
|
|
'frontend-tests.logic.path-helpers-test
|
|
'frontend-tests.logic.path-lifecycle-test
|
|
'frontend-tests.logic.path-tools-test
|
|
'frontend-tests.logic.pasting-in-containers-test
|
|
'frontend-tests.main.refs-test
|
|
'frontend-tests.main-errors-test
|
|
'frontend-tests.logic.sidebar-transform-coalescing-test
|
|
'frontend-tests.logic.update-position-test
|
|
'frontend-tests.logic.wasm-modifiers-nil-id-test
|
|
'frontend-tests.logic.wasm-pixel-snap-test
|
|
'frontend-tests.plugins.comments-test
|
|
'frontend-tests.plugins.context-shapes-test
|
|
'frontend-tests.plugins.events-test
|
|
'frontend-tests.plugins.management-test
|
|
'frontend-tests.plugins.file-test
|
|
'frontend-tests.plugins.flex-test
|
|
'frontend-tests.plugins.format-test
|
|
'frontend-tests.plugins.grid-test
|
|
'frontend-tests.plugins.interactions-test
|
|
'frontend-tests.plugins.library-test
|
|
'frontend-tests.plugins.local-storage-test
|
|
'frontend-tests.plugins.page-active-validation-test
|
|
'frontend-tests.plugins.page-test
|
|
'frontend-tests.plugins.parser-test
|
|
'frontend-tests.plugins.register-test
|
|
'frontend-tests.plugins.shape-bugfixes-test
|
|
'frontend-tests.plugins.text-test
|
|
'frontend-tests.plugins.tokens-test
|
|
'frontend-tests.plugins.user-test
|
|
'frontend-tests.plugins.utils-test
|
|
'frontend-tests.plugins.value-objects-test
|
|
'frontend-tests.render-wasm.process-objects-test
|
|
'frontend-tests.render-wasm.serialization-test
|
|
'frontend-tests.render-wasm.text-editor-apply-styles-test
|
|
'frontend-tests.render-wasm.text-editor-caret-color-test
|
|
'frontend-tests.render-wasm.text-editor-content-range-test
|
|
'frontend-tests.render-wasm.text-paste-test
|
|
'frontend-tests.render-wasm.webgl-test
|
|
'frontend-tests.browser-history-test
|
|
'frontend-tests.router-test
|
|
'frontend-tests.svg-fills-test
|
|
'frontend-tests.svg-filters-test
|
|
'frontend-tests.tokens.copy-paste-props-test
|
|
'frontend-tests.tokens.context-menu-test
|
|
'frontend-tests.tokens.import-export-test
|
|
'frontend-tests.tokens.logic.token-actions-test
|
|
'frontend-tests.tokens.logic.token-data-test
|
|
'frontend-tests.tokens.logic.token-remapping-test
|
|
'frontend-tests.tokens.referenced-token-value-test
|
|
'frontend-tests.tokens.style-dictionary-test
|
|
'frontend-tests.tokens.token-errors-test
|
|
'frontend-tests.tokens.logic.tokens-status-test
|
|
'frontend-tests.tokens.workspace-tokens-remap-test
|
|
'frontend-tests.ui.check-updates-test
|
|
'frontend-tests.ui.color-token-position-test
|
|
'frontend-tests.ui.colorpicker-token-set-order-test
|
|
'frontend-tests.ui.comment-input-ime-test
|
|
'frontend-tests.ui.comments-clustering-test
|
|
'frontend-tests.ui.comments-position-modifier-test
|
|
'frontend-tests.ui.dashboard-import-linking-test
|
|
'frontend-tests.ui.drawarea-test
|
|
'frontend-tests.ui.ds-controls-numeric-input-test
|
|
'frontend-tests.ui.error-boundary-test
|
|
'frontend-tests.ui.gradient-handlers-test
|
|
'frontend-tests.ui.history-test
|
|
'frontend-tests.ui.inspect-geometry-test
|
|
'frontend-tests.ui.inspect-stroke-tokens-test
|
|
'frontend-tests.ui.jobs-progress-test
|
|
'frontend-tests.ui.layout-container-multiple-test
|
|
'frontend-tests.ui.measurements-test
|
|
'frontend-tests.ui.measures-menu-props-test
|
|
'frontend-tests.ui.organization-team-switch-test
|
|
'frontend-tests.ui.routes-test
|
|
'frontend-tests.render-dimensions-test
|
|
'frontend-tests.text-editor-paste-guard-test
|
|
'frontend-tests.ui.settings-password-schema-test
|
|
'frontend-tests.ui.settings-shortcuts-test
|
|
'frontend-tests.ui.shape-filters-test
|
|
'frontend-tests.ui.shortcuts-labels-test
|
|
'frontend-tests.ui.shortcuts-recording-test
|
|
'frontend-tests.ui.sidebar-scroll-test
|
|
'frontend-tests.ui.stroke-menu-test
|
|
'frontend-tests.ui.text-attrs-multiple-test
|
|
'frontend-tests.ui.workspace-libraries-test
|
|
'frontend-tests.util-clipboard-test
|
|
'frontend-tests.util-object-test
|
|
'frontend-tests.util-queue-test
|
|
'frontend-tests.util-range-tree-test
|
|
'frontend-tests.util-simple-math-test
|
|
'frontend-tests.util-text-clipboard-test
|
|
'frontend-tests.util-text-editor-test
|
|
'frontend-tests.util-webapi-test
|
|
'frontend-tests.util.dom.dnd-test
|
|
'frontend-tests.util-zip-test
|
|
'frontend-tests.worker-snap-test])
|
|
|
|
(assert (every? find-ns-obj test-namespaces)
|
|
"test-namespaces contains a namespace that isn't required in runner.cljs")
|
|
|
|
;; This runner intentionally mirrors common-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. frontend-tests.logic.components-and-tokens/change-token-in-main"]
|
|
["-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))]
|
|
;; `pnpm run test -- --focus ...` forwards the separator to the node
|
|
;; process, so drop one leading `--` before handing args to tools.cli.
|
|
(cond-> args
|
|
(= "--" (first args)) rest)))
|
|
|
|
(defn- usage
|
|
[summary]
|
|
(str "Usage: pnpm run test -- [options]\n\n"
|
|
"Options:\n"
|
|
summary "\n\n"
|
|
"Focus examples:\n"
|
|
" pnpm run test -- --focus frontend-tests.logic.components-and-tokens\n"
|
|
" pnpm run test -- --focus frontend-tests.logic.components-and-tokens/change-token-in-main\n\n"
|
|
"Log level example (quiets app logging during the run):\n"
|
|
" pnpm run test -- --focus frontend-tests.logic.groups-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-current-env))))
|
|
(fn []
|
|
(t/report @summary)
|
|
(t/report (assoc @summary :type :end-run-tests)))]))))
|
|
|
|
(defn- run-focused-test!
|
|
[focus]
|
|
(run-test-vars! [(selected-tests (parse-focus focus))]))
|
|
|
|
(defn init
|
|
[]
|
|
(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
|
|
(l/setup! {:app (or (:log-level options) :warn)})
|
|
|
|
(if (:focus options)
|
|
(run-focused-test! (:focus options))
|
|
(run-test-vars! (map #(selected-tests {:ns %}) test-namespaces)))))))
|