Skip to content

test: add a javascript unit test harness for the classic frontend - #623

Open
oc-tmueller wants to merge 1 commit into
masterfrom
feat/js-unit-tests
Open

test: add a javascript unit test harness for the classic frontend#623
oc-tmueller wants to merge 1 commit into
masterfrom
feat/js-unit-tests

Conversation

@oc-tmueller

Copy link
Copy Markdown
Contributor

Summary

The scripts in js/ had no automated coverage and CI had no JavaScript job at
all, so changes to the classic frontend could only be verified by hand. This
adds the setup the other ownCloud apps use - karma with jasmine, specs in
tests/js/, a make test-js target, and the shared js-unit reusable
workflow.

  • tests/js/karma.config.cjs loads jQuery, jQuery UI and OC from the
    surrounding core checkout the same way the server loads them, so the scripts
    under test run unmodified. Only js/documents.js is loaded: the other scripts
    in js/ are never on the same page and share one global namespace, which is
    also why core's own karma config lists files explicitly instead of globbing.
    The file is .cjs because package.json declares "type": "module".
  • karma-jasmine-sinon is needed because core's specHelper.js installs a
    global beforeEach that uses sinon.fakeServer. That also means no spec can
    reach the network, and each spec gets a #testArea div for fixtures.
  • The plugins are listed explicitly. Karma's default karma-* discovery only
    scans the directory karma itself sits in, which finds nothing in a pnpm
    layout.
  • The test-js target replaces the previous npm and bower rules in the
    Makefile. Those were dead: none of nodejs_deps, bower_deps, BOWER or
    JSDOC was ever defined, so the rule applied to an empty target. make dist
    output is unchanged.
  • Node dependencies install with pnpm 9 through npx. pnpm-lock.yaml has no
    integrity hash for the easygettext tarball, which pnpm 10 refuses with
    ERR_PNPM_MISSING_TARBALL_INTEGRITY. Override with PNPM=<command> to use a
    local pnpm.

Testing

37 specs in tests/js/documentsSpec.js, covering the frontend half of #620 -
which had to be verified manually at the time, for lack of this harness:

  • _absoluteHttpUrl() refuses everything that is not an absolute http(s) URL,
    and accepts a subdirectory install and a non-default port.
  • _wopiOrigin() derives the origin from an absolute and from a
    server-relative discovery urlsrc, and has no origin at all for an empty or
    non-http(s) one.
  • WOPIPostMessage() posts to that origin rather than to any origin, and posts
    nothing when the origin is unknown.
  • onStartup() takes the return URL from the hidden input the server renders
    and ignores a server URL parameter.
  • onClose() does not navigate to a return URL that is not an absolute http(s)
    URL.
  • the editor ignores post messages that do not come from the Collabora Online
    origin.

Run locally against ownCloud 11 core with make test-js, 37 specs green. Every
guard the specs describe was checked by reverting it and confirming the specs
fail.

Two things this deliberately does not do, each its own change: the Vue connector
in src/ still has no unit tests - it needs a separate vitest setup like
owncloud/web-extensions uses - and pnpm lint remains broken and still does
not cover js/.

🤖 Generated with Claude Code

The scripts in js/ had no automated coverage at all, and CI had no
JavaScript job. This adds the setup the other ownCloud apps use: karma
with jasmine, specs in tests/js/, a test-js make target and the shared
js-unit reusable workflow.

The classic frontend expects the globals the server puts on the page, so
the karma config loads jQuery, jQuery UI and OC from the surrounding core
checkout the same way the server does, and the scripts under test run
unmodified. Only js/documents.js is loaded - the other scripts in js/ are
never on the same page and share one global namespace.

The first specs cover where the browser may navigate to when the editor
is closed and which origin post messages are exchanged with, the
counterpart to the DocumentController tests.

Node dependencies are installed with pnpm 9, pnpm 10 refuses the
easygettext tarball in the lockfile for a missing integrity hash. The
unused npm and bower rules the target replaces were dead, none of their
variables were ever defined.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com>
@oc-tmueller
oc-tmueller requested a review from a team as a code owner September 10, 2026 13:38
@phil-davis

Copy link
Copy Markdown
Contributor

https://github.com/owncloud/richdocuments/actions/runs/34483941568/job/102893396948?pr=623

0 09 2026 13:39:47.427:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
10 09 2026 13:39:47.428:INFO [launcher]: Launching browsers FirefoxHeadless with concurrency unlimited
10 09 2026 13:39:47.432:INFO [launcher]: Starting browser FirefoxHeadless
10 09 2026 13:40:07.096:INFO [Firefox 155.0 (Linux 0.0.0)]: Connected on socket BwZqST4p_nvQgfYeAAAA with id 24247678
Firefox 155.0 (Linux 0.0.0) LOG: 'JQMIGRATE: Migrate is installed, version 1.4.0'


Firefox 155.0 (Linux 0.0.0): Executed 0 of 37 SUCCESS (0 secs / 0 secs)
Firefox 155.0 (Linux 0.0.0): Executed 1 of 37 SUCCESS (0 secs / 0.01 secs)
Firefox 155.0 (Linux 0.0.0): Executed 2 of 37 SUCCESS (0 secs / 0.018 secs)
Firefox 155.0 (Linux 0.0.0): Executed 3 of 37 SUCCESS (0 secs / 0.019 secs)
Firefox 155.0 (Linux 0.0.0): Executed 4 of 37 SUCCESS (0 secs / 0.021 secs)
WARN: 'Not returning to /index.php/apps/files, not an absolute http(s) url'
Firefox 155.0 (Linux 0.0.0): Executed 4 of 37 SUCCESS (0 secs / 0.021 secs)
Firefox 155.0 (Linux 0.0.0): Executed 5 of 37 SUCCESS (0 secs / 0.022 secs)
WARN: 'Not returning to //evil.tld, not an absolute http(s) url'
Firefox 155.0 (Linux 0.0.0): Executed 5 of 37 SUCCESS (0 secs / 0.022 secs)
Firefox 155.0 (Linux 0.0.0): Executed 6 of 37 SUCCESS (0 secs / 0.024 secs)
WARN: 'Not returning to javascript:alert(document.domain), not an absolute http(s) url'
Firefox 155.0 (Linux 0.0.0): Executed 6 of 37 SUCCESS (0 secs / 0.024 secs)
Firefox 155.0 (Linux 0.0.0): Executed 7 of 37 SUCCESS (0 secs / 0.026 secs)
Firefox 155.0 (Linux 0.0.0): Executed 8 of 37 SUCCESS (0 secs / 0.027 secs)
Firefox 155.0 (Linux 0.0.0): Executed 9 of 37 SUCCESS (0 secs / 0.028 secs)
Firefox 155.0 (Linux 0.0.0): Executed 10 of 37 SUCCESS (0 secs / 0.029 secs)
Firefox 155.0 (Linux 0.0.0): Executed 11 of 37 SUCCESS (0 secs / 0.03 secs)
Firefox 155.0 (Linux 0.0.0): Executed 12 of 37 SUCCESS (0 secs / 0.031 secs)
Firefox 155.0 (Linux 0.0.0): Executed 13 of 37 SUCCESS (0 secs / 0.032 secs)
Firefox 155.0 (Linux 0.0.0): Executed 14 of 37 SUCCESS (0 secs / 0.033 secs)
Firefox 155.0 (Linux 0.0.0): Executed 15 of 37 SUCCESS (0 secs / 0.033 secs)
Firefox 155.0 (Linux 0.0.0): Executed 16 of 37 SUCCESS (0 secs / 0.034 secs)
Firefox 155.0 (Linux 0.0.0): Executed 17 of 37 SUCCESS (0 secs / 0.035 secs)
Firefox 155.0 (Linux 0.0.0): Executed 18 of 37 SUCCESS (0 secs / 0.035 secs)
Firefox 155.0 (Linux 0.0.0): Executed 19 of 37 SUCCESS (0 secs / 0.036 secs)
Firefox 155.0 (Linux 0.0.0): Executed 20 of 37 SUCCESS (0 secs / 0.037 secs)
Firefox 155.0 (Linux 0.0.0): Executed 21 of 37 SUCCESS (0 secs / 0.037 secs)
Firefox 155.0 (Linux 0.0.0): Executed 22 of 37 SUCCESS (0 secs / 0.038 secs)
Firefox 155.0 (Linux 0.0.0): Executed 23 of 37 SUCCESS (0 secs / 0.039 secs)
Firefox 155.0 (Linux 0.0.0): Executed 24 of 37 SUCCESS (0 secs / 0.04 secs)
Firefox 155.0 (Linux 0.0.0): Executed 25 of 37 SUCCESS (0 secs / 0.041 secs)
Firefox 155.0 (Linux 0.0.0): Executed 26 of 37 SUCCESS (0 secs / 0.042 secs)
Firefox 155.0 (Linux 0.0.0): Executed 27 of 37 SUCCESS (0 secs / 0.043 secs)
Firefox 155.0 (Linux 0.0.0): Executed 28 of 37 SUCCESS (0 secs / 0.044 secs)
Firefox 155.0 (Linux 0.0.0): Executed 29 of 37 SUCCESS (0 secs / 0.045 secs)
WARN: 'Cannot determine the Collabora Online origin from javascript:alert(document.domain)'
Firefox 155.0 (Linux 0.0.0): Executed 29 of 37 SUCCESS (0 secs / 0.045 secs)
Firefox 155.0 (Linux 0.0.0): Executed 30 of 37 SUCCESS (0 secs / 0.046 secs)
WARN: 'Cannot determine the Collabora Online origin from data:text/html,<script>alert(1)</script>'
Firefox 155.0 (Linux 0.0.0): Executed 30 of 37 SUCCESS (0 secs / 0.046 secs)
Firefox 155.0 (Linux 0.0.0): Executed 31 of 37 SUCCESS (0 secs / 0.047 secs)
WARN: 'Cannot determine the Collabora Online origin from ftp://collabora.example.com/cool.html'
Firefox 155.0 (Linux 0.0.0): Executed 31 of 37 SUCCESS (0 secs / 0.047 secs)
Firefox 155.0 (Linux 0.0.0): Executed 32 of 37 SUCCESS (0 secs / 0.048 secs)
Firefox 155.0 (Linux 0.0.0): Executed 33 of 37 SUCCESS (0 secs / 0.048 secs)
Firefox 155.0 (Linux 0.0.0): Executed 34 of 37 SUCCESS (0 secs / 0.049 secs)
Firefox 155.0 (Linux 0.0.0): Executed 35 of 37 SUCCESS (0 secs / 0.05 secs)
Firefox 155.0 (Linux 0.0.0): Executed 36 of 37 SUCCESS (0 secs / 0.053 secs)
Firefox 155.0 (Linux 0.0.0): Executed 37 of 37 SUCCESS (0 secs / 0.054 secs)
Firefox 155.0 (Linux 0.0.0): Executed 37 of 37 SUCCESS (0.047 secs / 0.054 secs)
TOTAL: 37 SUCCESS

There are a few warnings, but it passes - good.

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.

2 participants