🧪 Add JS unit test setup, covering Util.js - #1989
Open
AndyScherzinger wants to merge 1 commit into
Open
Conversation
AndyScherzinger
force-pushed
the
feat/noid/note-info
branch
from
August 17, 2026 18:57
94e1e57 to
5d7829e
Compare
AndyScherzinger
force-pushed
the
test/noid/js-unit-tests
branch
from
August 17, 2026 20:57
73d6ee4 to
47ec9fb
Compare
AndyScherzinger
force-pushed
the
feat/noid/note-info
branch
from
August 17, 2026 20:57
5d7829e to
67be3df
Compare
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
AndyScherzinger
force-pushed
the
feat/noid/note-info
branch
from
August 17, 2026 21:00
67be3df to
651ea2a
Compare
AndyScherzinger
force-pushed
the
test/noid/js-unit-tests
branch
from
August 17, 2026 21:00
47ec9fb to
63b62e5
Compare
This was referenced Aug 17, 2026
AndyScherzinger
marked this pull request as ready for review
August 17, 2026 21:12
AndyScherzinger
force-pushed
the
test/noid/js-unit-tests
branch
from
August 18, 2026 07:44
63b62e5 to
0f5c0b1
Compare
The repo had no JS test runner, so the only way to exercise frontend logic was Playwright — a Docker container, a login and a browser to check what a helper returns. Util.js has been there all along, is pure, and had no coverage at all. vitest, as in text, circles, deck and files_mindmap. The config is deliberately smaller than theirs: no @vitejs/plugin-vue, since no component is tested yet. jsdom rather than node, because escapeHtml() builds an element and because the app logger other modules pull in reads window at import time — a component test would want jsdom anyway. The config file is vitest.config.js rather than .mjs, so it sits with the repo's other configs and inside the workflow's `**.js` paths filter — as `.mjs` a config-only change would skip the test job. The npm script is `test` rather than `test:unit` because the organisation's node-test.yml workflow runs `npm run test --if-present` and `npm run test:coverage --if-present`. That workflow is added verbatim from nextcloud/.github, like the sixteen others already in .github/workflows. `test:e2e` keeps its name, so the two suites stay distinguishable. Util.js is the subject rather than anything newer on purpose: it is on main already, so this lands without waiting on a feature branch, and every feature branch can then bring the tests for whatever it adds. Covered: copyNote's attribute list and its exclusions, the category label, the new-note route check, and the two drag helpers down to their defensive paths — a browser that refuses a mime type, a transfer that advertises no types, a read-only or unknown note. escapeHtml gets its own cases, having been the one piece of this file where a mistake would be a security bug. 33 cases, and Util.js fully covered by line and by branch. Assisted-by: Claude Code:claude-opus-5[1m] Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
AndyScherzinger
force-pushed
the
test/noid/js-unit-tests
branch
from
August 18, 2026 09:48
0f5c0b1 to
9385741
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The repo had no JS test runner. The only way to exercise frontend logic was Playwright - a Docker container, a login and a browser to check what a helper returns. This adds vitest and puts it to work on
src/Util.js, which has been there all along, is pure, and had no coverage at all.What is in here
npm run testandnpm run test:coverage, andcoverage/ignored..github/workflows/node-test.yml, added verbatim from nextcloud/.github like the sixteen others already in.github/workflows. It runs the suite and uploads coverage to Codecov.src/tests/Util.spec.js, 33 cases.Why Util.js
It is on main already, so this lands without waiting on a feature branch, and every feature branch can then bring the tests for whatever it adds.
escapeHtml()in particular is the one piece of that file where a mistake is a security bug, and it had no test.Covered: copyNote's attribute list and its exclusions, the category label, the new-note route check, and the two drag helpers down to their defensive paths - a browser that refuses a mime type, a transfer that advertises no types, a read-only or unknown note. Util.js ends up fully covered by line and by branch.
Implementation notes
@vitejs/plugin-vue, since no component is tested yet.escapeHtml()builds an element and because the app logger other modules pull in readswindowat import time. A component test would want jsdom anyway.testrather thantest:unitbecause the organisation's node-test.yml runsnpm run test --if-presentandnpm run test:coverage --if-present.test:e2ekeeps its name, so the two suites stay distinguishable.vitest.config.jsrather than.mjs, so it sits with the repo's other configs and inside that workflow's**.jspaths filter - as.mjs, a config-only change would skip the test job.toStrictEqual, sincetoEqualcannot tell a property set toundefinedfrom one that was never assigned - which is exactly whatcopyNote()does with them.Merge order
#1972 and #1974 each carry a spec for the module they add, and those cannot run until this got merged.
🤖 AI (if applicable)