Skip to content

Commit abd4c31

Browse files
oc-tmuellerclaude
andauthored
test: add a javascript unit test harness for the classic frontend [4.2] (#630)
Backport of #623. js/documents.js is byte-identical between this branch and master, so it carries the same navigation and post message guards as the master-side fix and had exactly the same problem: no automated coverage, and no JavaScript job in CI. Makefile and both files under tests/js/ are byte-identical to master's. package.json and pnpm-lock.yaml are master's karma additions applied to this branch's tree rather than copies of it, because the two trees have since diverged: #629 bumped vue to 3.5.42 here while master is still on 3.5.40, and #632 moved the pnpm settings into pnpm-workspace.yaml here while master's still sit in package.json. The lockfile delta is 938 insertions and 3 deletions, the same as the master-side change, and adds nothing but the karma tree - no package is removed and no version moves. The CI job is the one part that needed adapting. js-unit.yml has no core-ref-php74 input and no case() on the php version, unlike php-codestyle.yml and php-unit.yml above it, so the core checkout is selected by core-ref alone - 10.16 here, since an app declaring max-version="10" cannot be enabled on a master core. This is also the first job on this branch to install node dependencies, which is what made the broken lockfile #632 repaired invisible here until now. Verified against a real 10.16 core: 37 of 37 specs pass, and they still fail with the expected wrong values when the scheme guard in _absoluteHttpUrl is defeated. core/js/core.json is byte-identical between core master and 10.16 and core 10.16 ships the same core/vendor symlink from its build postinstall, so the karma config needed no path changes. core 10.16's specHelper.js lacks the jasmine.pp shim master's carries for jasmine-sinon, which turns out not to matter here: jasmine-sinon delegates to jasmine's own matchers for jasmine spies, and these specs use no sinon spies. Node dependencies are installed with pnpm 10, the version pnpm-lock.yaml is resolved with. The unused npm and bower rules the target replaces were dead, none of their variables were ever defined on this branch either. Signed-off-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com> Co-authored-by: Thomas Müller <323649642+oc-tmueller@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 90445fa commit abd4c31

6 files changed

Lines changed: 1418 additions & 20 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ jobs:
5757
php-versions: ${{ needs.get-vars.outputs.php-versions }}
5858
core-ref-php74: '10.16'
5959

60+
js-unit:
61+
name: JS Unit
62+
needs:
63+
- get-vars
64+
uses: owncloud/reusable-workflows/.github/workflows/js-unit.yml@main
65+
with:
66+
app-name: ${{ needs.get-vars.outputs.app-name }}
67+
php-version: '7.4'
68+
# js-unit.yml has no core-ref-php74 input, it clones whatever core-ref says
69+
core-ref: '10.16'
70+
6071
build:
6172
name: Build
6273
needs:

‎Makefile‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
SHELL := /bin/bash
22

33
COMPOSER_BIN := $(shell command -v composer 2> /dev/null)
4-
NPM := $(shell command -v npm 2> /dev/null)
5-
NODE_PREFIX=$(shell pwd)
4+
# pinned and resolved through npx on purpose: CI has node but not necessarily
5+
# pnpm. Override with PNPM=<command> to use a local one.
6+
PNPM ?= npx --yes pnpm@10
67

78
app_name=richdocuments
89
project_dir=$(CURDIR)/../$(app_name)
@@ -23,6 +24,9 @@ occ=$(CURDIR)/../core/occ
2324
composer_deps=vendor
2425
acceptance_test_deps=vendor-bin/behat/vendor
2526

27+
# node
28+
nodejs_deps=node_modules
29+
2630
appstore:
2731
mkdir -p $(sign_dir)
2832
rsync -a \
@@ -76,6 +80,7 @@ PHP_CODESNIFFER=vendor-bin/php_codesniffer/vendor/bin/phpcs
7680
PHAN=php -d zend.enable_gc=0 vendor-bin/phan/vendor/bin/phan
7781
PHPSTAN=php -d zend.enable_gc=0 vendor-bin/phpstan/vendor/bin/phpstan
7882
BEHAT_BIN=vendor-bin/behat/vendor/bin/behat
83+
KARMA=$(CURDIR)/node_modules/.bin/karma
7984

8085
.DEFAULT_GOAL := help
8186

@@ -86,14 +91,8 @@ help: ## Show this help message
8691
#
8792
# Node dependencies
8893
#
89-
$(nodejs_deps): package.json
90-
$(NPM) install --prefix $(NODE_PREFIX) && touch $@
91-
92-
$(BOWER): $(nodejs_deps)
93-
$(JSDOC): $(nodejs_deps)
94-
95-
$(bower_deps): $(BOWER)
96-
$(BOWER) install && touch $@
94+
$(nodejs_deps): package.json pnpm-lock.yaml
95+
$(PNPM) install --frozen-lockfile && touch $@
9796

9897
#
9998
# dist
@@ -132,13 +131,6 @@ clean-deps:
132131
.PHONY: clean
133132
clean: clean-deps clean-dist clean-build
134133

135-
##-------------
136-
## CI
137-
##-------------
138-
139-
.PHONY: ci
140-
ci: vendor ## Install dependencies for CI
141-
142134
##-------------
143135
## Tests
144136
##-------------
@@ -153,6 +145,16 @@ test-php-unit-dbg: ## Run php unit tests using phpdbg
153145
test-php-unit-dbg: vendor/bin/phpunit
154146
$(PHPUNITDBG) --configuration ./phpunit.xml --testsuite unit
155147

148+
.PHONY: test-js
149+
test-js: ## Run JavaScript unit tests
150+
test-js: $(nodejs_deps)
151+
$(KARMA) start tests/js/karma.config.cjs --single-run
152+
153+
.PHONY: test-js-debug
154+
test-js-debug: ## Run JavaScript unit tests and keep watching
155+
test-js-debug: $(nodejs_deps)
156+
$(KARMA) start tests/js/karma.config.cjs
157+
156158
.PHONY: test-php-style
157159
test-php-style: ## Run php-cs-fixer and check owncloud code-style
158160
test-php-style: vendor-bin/owncloud-codestyle/vendor vendor-bin/php_codesniffer/vendor
@@ -184,6 +186,11 @@ test-acceptance-webui: ## Run webUI acceptance tests
184186
test-acceptance-webui: $(acceptance_test_deps)
185187
BEHAT_BIN=$(BEHAT_BIN) ../../tests/acceptance/run.sh --remote --type webUI
186188

189+
# Installs dependencies and does any build actions needed for the app to run in CI
190+
.PHONY: ci
191+
ci: vendor
192+
@echo dependencies and build actions for CI are completed
193+
187194
#
188195
# Dependency management
189196
#--------------------------------------

‎package.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
"axios": "^1.16.0",
1717
"easygettext": "https://github.com/owncloud/easygettext/archive/refs/tags/v2.18.2-oc.tar.gz",
1818
"eslint": "9.39.5",
19+
"jasmine-core": "^7.0.2",
20+
"jasmine-sinon": "^0.4.0",
21+
"karma": "^6.4.4",
22+
"karma-chrome-launcher": "^3.2.0",
23+
"karma-firefox-launcher": "^2.1.3",
24+
"karma-jasmine": "^5.1.0",
25+
"karma-jasmine-sinon": "^1.0.4",
1926
"prettier": "3.9.6",
27+
"sinon": "^19.0.5",
2028
"typescript": "6.0.3",
2129
"vite": "^6.4.3",
2230
"vue": "3.5.42"

0 commit comments

Comments
 (0)