Skip to content

Commit 5177a7d

Browse files
committed
ci: enforce full-suite checks and align test runner modes
1 parent 700f589 commit 5177a7d

3 files changed

Lines changed: 128 additions & 6 deletions

File tree

.github/workflows/ci-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test Quality Gates
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: test-quality-${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
run-all-tests:
16+
name: Run Full Test Suite
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '20'
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run all tests
33+
run: npm test

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
"scripts": {
77
"start": "node src/index.js",
88
"dev": "NODE_ENV=development nodemon src/index.js",
9-
"test": "MONGOMS_DOWNLOAD_DIR=/tmp/mongodb-binaries node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=30000",
10-
"test:coverage": "MONGOMS_DOWNLOAD_DIR=/tmp/mongodb-binaries node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=30000 --coverage",
9+
"test": "MONGOMS_DOWNLOAD_DIR=/tmp/mongodb-binaries node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=30000 --runInBand",
10+
"test:coverage": "MONGOMS_DOWNLOAD_DIR=/tmp/mongodb-binaries node --experimental-vm-modules node_modules/jest/bin/jest.js --testTimeout=30000 --runInBand --coverage",
11+
"test:basic": "npm run test -- --testPathIgnorePatterns=mongodb-storage.test.js",
12+
"test:mongo": "npm run test -- src/__tests__/storage/mongodb-storage.test.js",
13+
"test:coverage:basic": "npm run test:coverage -- --testPathIgnorePatterns=mongodb-storage.test.js",
1114
"migrate": "node scripts/migrate.js"
1215
},
1316
"dependencies": {

run-tests.sh

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,91 @@ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55
repo_root="${script_dir}"
66
devcontainer_exec="${script_dir}/scripts/devcontainer-exec.sh"
77

8+
usage() {
9+
cat <<'USAGE'
10+
Usage: ./run-tests.sh [--mode <basic|mongo|all>] [--coverage]
11+
12+
Options:
13+
-m, --mode Test mode to run. Default: all
14+
-c, --coverage Enable coverage for selected mode
15+
-h, --help Show this help message
16+
USAGE
17+
}
18+
19+
mode="all"
20+
coverage="false"
21+
22+
while [[ $# -gt 0 ]]; do
23+
case "$1" in
24+
-m|--mode)
25+
if [[ $# -lt 2 ]]; then
26+
echo "Error: --mode requires a value" >&2
27+
usage
28+
exit 1
29+
fi
30+
mode="$2"
31+
shift 2
32+
;;
33+
--mode=*)
34+
mode="${1#*=}"
35+
shift
36+
;;
37+
-c|--coverage)
38+
coverage="true"
39+
shift
40+
;;
41+
-h|--help)
42+
usage
43+
exit 0
44+
;;
45+
basic|mongo|all)
46+
mode="$1"
47+
shift
48+
;;
49+
*)
50+
echo "Error: unknown argument '$1'" >&2
51+
usage
52+
exit 1
53+
;;
54+
esac
55+
done
56+
57+
case "${mode}" in
58+
basic|mongo|all)
59+
;;
60+
*)
61+
echo "Error: invalid mode '${mode}'. Use basic, mongo, or all." >&2
62+
usage
63+
exit 1
64+
;;
65+
esac
66+
67+
if [[ "${coverage}" == "true" ]]; then
68+
case "${mode}" in
69+
basic)
70+
test_cmd=(npm run test:coverage:basic)
71+
;;
72+
mongo)
73+
test_cmd=(npm run test:coverage -- --runInBand src/__tests__/storage/mongodb-storage.test.js)
74+
;;
75+
all)
76+
test_cmd=(npm run test:coverage)
77+
;;
78+
esac
79+
else
80+
case "${mode}" in
81+
basic)
82+
test_cmd=(npm run test:basic)
83+
;;
84+
mongo)
85+
test_cmd=(npm run test:mongo)
86+
;;
87+
all)
88+
test_cmd=(npm test)
89+
;;
90+
esac
91+
fi
92+
893
docker_available() {
994
if ! command -v docker >/dev/null 2>&1; then
1095
return 1
@@ -15,23 +100,24 @@ docker_available() {
15100

16101
# 1) If already inside any container, run tests directly.
17102
if [[ -f "/.dockerenv" ]]; then
18-
exec npm test
103+
exec "${test_cmd[@]}"
19104
fi
20105

21106
# 2) If Docker is unavailable, run tests locally on host.
22107
if ! docker_available; then
23-
exec npm test
108+
exec "${test_cmd[@]}"
24109
fi
25110

26111
# 3) If a devcontainer for this repo is running, run tests there.
27112
container_id="$("${devcontainer_exec}" --find-container-id 2>/dev/null || true)"
28113
if [[ -n "${container_id}" ]]; then
29-
exec "${devcontainer_exec}" npm test
114+
exec "${devcontainer_exec}" "${test_cmd[@]}"
30115
fi
31116

32117
# 4) No devcontainer: run tests in a fresh disposable container (legacy behavior).
118+
cmd_string="$(printf '%q ' "${test_cmd[@]}")"
33119
exec docker run --rm -i \
34120
-v "${repo_root}:/app" \
35121
-w /app \
36122
node:latest \
37-
sh -c "npm install && npm test"
123+
sh -c "npm install && ${cmd_string}"

0 commit comments

Comments
 (0)