Skip to content

Commit 6bf1702

Browse files
committed
scripts: add run-js-tests.sh for JavaScript test execution
* Adds bash script to run JavaScript tests in CI or watch mode * Supports npm ci/install, watch mode, and help options * Uses WORKING_DIR environment variable for CI compatibility
1 parent bb74b02 commit 6bf1702

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

run-js-tests.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (C) 2026 CERN.
5+
# Copyright (C) 2026 CESNET.
6+
#
7+
# Run JavaScript tests for this repository.
8+
9+
set -o errexit
10+
set -o nounset
11+
12+
# Use WORKING_DIR from environment if provided (CI), otherwise calculate from script location
13+
if [ -n "${WORKING_DIR:-}" ]; then
14+
JS_DIR="$WORKING_DIR"
15+
else
16+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
17+
JS_DIR="$SCRIPT_DIR/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records"
18+
fi
19+
20+
WATCH_MODE=false
21+
22+
cd "$JS_DIR"
23+
24+
# Parse arguments
25+
for arg in "$@"; do
26+
case ${arg} in
27+
-i|--install)
28+
if [ -f package-lock.json ]; then
29+
npm ci
30+
else
31+
npm install
32+
fi
33+
exit 0
34+
;;
35+
-w|--watch)
36+
WATCH_MODE=true
37+
shift
38+
;;
39+
-h|--help)
40+
echo "Usage: ./run-js-tests.sh [options] [npm test options]"
41+
echo ""
42+
echo "Options:"
43+
echo " -i, --install Install dependencies only"
44+
echo " -w, --watch Run tests in watch mode (default: CI mode)"
45+
echo " -h, --help Show this help message"
46+
echo ""
47+
echo "Examples:"
48+
echo " ./run-js-tests.sh Run tests once (CI mode - default)"
49+
echo " ./run-js-tests.sh -w Run tests in watch mode"
50+
echo " ./run-js-tests.sh --testPathPattern=DepositFilesService"
51+
exit 0
52+
;;
53+
esac
54+
done
55+
56+
# Default to CI mode (non-watch) unless -w/--watch is specified
57+
if [ "$WATCH_MODE" = false ]; then
58+
CI=true npm test -- --watchAll=false "$@"
59+
else
60+
npm test -- "$@"
61+
fi

0 commit comments

Comments
 (0)