Skip to content

Commit dd64280

Browse files
committed
Migrate tests/workflows to node:test and update docs
Replace the legacy Jest-based test setup and dotenv loader with Node's built-in test runner and native env-file flags. GitHub Actions workflows were reworked: job 'test' renamed to 'local_seams', new 'integration_seams' (creates .env from secrets, sets up Node 24, caches npm, runs npm run test:integration) and coordinated bump_version job added; CD jobs now run npm run test:integration for smoke checks. Documentation and guides (.github/copilot-instructions.md, CONFIG.md, CONTRIBUTING.md, README.md) updated to reflect Node native env-file usage, updated test script names (test:local, test:integration, test:coverage) and testing guidance. Removed import of env-loader from bin/tpen3_services.js. Large set of legacy Jest tests under __tests__ and various class test folders were removed and replaced by new test suites under test/local and test/integration; package.json/package-lock were updated accordingly.
1 parent 3eb83b3 commit dd64280

48 files changed

Lines changed: 1360 additions & 8123 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TPEN Services is a Node.js Express API service for TPEN3 (Transcription for Pale
1616

1717
### Environment Configuration
1818

19-
TPEN Services uses a layered configuration approach with `--import ./env-loader.js` using the dotenv package:
19+
TPEN Services uses a layered configuration approach with Node native env-file flags:
2020

2121
- `config.env` - Safe defaults (committed to repo, no secrets)
2222
- Works out-of-the-box for local Docker/MongoDB/MariaDB
@@ -33,10 +33,10 @@ TPEN Services uses a layered configuration approach with `--import ./env-loader.
3333
- Contains actual secrets and environment-specific values
3434
- Overrides values from `config.env`
3535

36-
Configuration loading order (via `--import ./env-loader.js` using the dotenv package):
36+
Configuration loading order (via Node CLI env-file flags in npm scripts):
3737

3838
1. `config.env` is loaded first (provides safe defaults)
39-
2. `.env.{NODE_ENV}` is loaded second (environment-specific: .env.development, .env.production, .env.test)
39+
2. `.env.development` is loaded second (development defaults)
4040
3. `.env` is loaded last (local/server overrides - HIGHEST PRIORITY)
4141

4242
This allows developers to work immediately with sensible defaults while keeping secrets out of the repository.
@@ -48,19 +48,15 @@ This allows developers to work immediately with sensible defaults while keeping
4848
- Start the application: `npm start` or `npm run dev`
4949
- Test the root endpoint: `curl http://localhost:3011/` -- should return HTML containing the TPEN3 Services index (heading + welcome text)
5050
- Run unit tests that don't require databases: `npm run unitTests` -- many tests pass without database connections
51-
- Run existence tests: `npm run existsTests` -- validates route registration and class imports
5251
- Run all tests: `npm run allTests` -- Full test suite confirming full app functionality
5352
- ALWAYS wait for full test completion. Tests may appear to hang but should complete within 2 minutes.
5453
- NOTE: Application may crash after serving initial requests due to database connection attempts - this is expected behavior without running MongoDB/MariaDB.
5554

5655
### Test Categories Available
5756
- `npm run allTests` -- Full test suite which requires .env settings
58-
- `npm run unitTests` -- Core unit tests (some require databases)
59-
- `npm run existsTests` -- Route and class existence validation (database-independent)
60-
- `npm run functionsTests` -- Function-level tests
61-
- `npm run E2Etests` -- End-to-end API tests
62-
- `npm run dbTests` -- Database-specific tests (require running databases)
63-
- `npm run authTest` -- Authentication tests (require Auth0 configuration)
57+
- `npm run unitTests` -- Fast local seam checks
58+
- `npm run E2Etests` -- CI-oriented integration seam checks
59+
- `npm run test:coverage` -- Coverage report via c8
6460

6561
### Expected Test Behavior
6662
- Tests requiring databases will timeout/fail without MongoDB/MariaDB running
@@ -108,8 +104,8 @@ Required for external services:
108104
1. Do not overwrite the existing .env file. If an .env file does not exist or is not populated then copy environment configuration: `cp .env.development .env`
109105
2. Install dependencies with `npm install`
110106
3. Make code changes
111-
4. Test with: `npm run existsTests` (fast, database-independent)
112-
5. For all other tests use `npm run allTests`
107+
4. Test with: `npm run unitTests` (fast, database-independent)
108+
5. For full validation use `npm run allTests`
113109
6. Test manually: `curl http://localhost:3011/` and relevant endpoints
114110

115111
NEVER CANCEL long-running commands. Application builds and tests are designed to complete within documented timeouts. Always wait for completion to ensure accurate validation of changes.

.github/workflows/cd_dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ jobs:
8686
- name: Run smoke tests
8787
run: |
8888
cd /srv/node/tpen-services/
89-
SMOKE_TEST_URL=https://dev.api.t-pen.org node __tests__/smoke.test.js
89+
npm run test:integration

.github/workflows/cd_prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ jobs:
8686
- name: Run smoke tests
8787
run: |
8888
cd /srv/node/tpen-services/
89-
SMOKE_TEST_URL=https://api.t-pen.org node __tests__/smoke.test.js
89+
npm run test:integration

.github/workflows/ci_dev.yaml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: development
55
jobs:
6-
test:
6+
local_seams:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master
@@ -50,8 +50,62 @@ jobs:
5050
- name: Install dependencies and run the test
5151
run: |
5252
npm install
53-
npm run E2Etests
53+
npm run test:local
5454
55+
integration_seams:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@master
59+
- name: Create .env from secrets
60+
uses: SpicyPizza/create-envfile@v2
61+
with:
62+
fail_on_empty: false
63+
sort_keys: false
64+
envkey_DOWN: ${{ secrets.DOWN }}
65+
envkey_SERVERURL: ${{ secrets.SERVERURL }}
66+
envkey_MONGODBNAME: ${{ secrets.MONGODBNAME }}
67+
envkey_MONGODB: ${{ secrets.MONGODB }}
68+
envkey_TPENPROJECTS: ${{ secrets.TPENPROJECTS }}
69+
envkey_TPENGROUPS: ${{ secrets.TPENGROUPS }}
70+
envkey_TPENUSERS: ${{ secrets.TPENUSERS }}
71+
envkey_MARIADBNAME: ${{ secrets.MARIADBNAMEDEV }}
72+
envkey_MARIADB: ${{ secrets.MARIADB }}
73+
envkey_MARIADBUSER: ${{ secrets.MARIADBUSERDEV }}
74+
envkey_MARIADBPASSWORD: ${{ secrets.MARIADBPASSWORDDEV }}
75+
envkey_RERUMIDPREFIX: ${{ secrets.RERUMIDPREFIXDEV }}
76+
envkey_TINYPEN: ${{ secrets.TINYPENDEV }}
77+
envkey_AUDIENCE: ${{ secrets.AUDIENCE }}
78+
envkey_DOMAIN: ${{ secrets.DOMAIN }}
79+
envkey_TPEN_SUPPORT_EMAIL: ${{ secrets.TPEN_SUPPORT_EMAIL }}
80+
envkey_SMTP_HOST: ${{ secrets.SMTP_HOST }}
81+
envkey_SMTP_PORT: ${{ secrets.SMTP_PORT }}
82+
envkey_TPEN_EMAIL_CC: ${{ secrets.TPEN_EMAIL_CC }}
83+
- name: Setup Node.js
84+
uses: actions/setup-node@master
85+
with:
86+
node-version: "24"
87+
- name: Cache node modules
88+
uses: actions/cache@master
89+
env:
90+
cache-name: cache-node-modules
91+
with:
92+
path: ~/.npm
93+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{
94+
hashFiles('**/package-lock.json') }}
95+
restore-keys: |
96+
${{ runner.os }}-build-${{ env.cache-name }}-
97+
${{ runner.os }}-build-
98+
${{ runner.os }}-
99+
- name: Install dependencies and run the test
100+
run: |
101+
npm install
102+
npm run test:integration
103+
104+
bump_version:
105+
runs-on: ubuntu-latest
106+
needs: [local_seams, integration_seams]
107+
steps:
108+
- uses: actions/checkout@master
55109
- name: Bump version (patch + prerelease)
56110
run: |
57111
git config user.name "github-actions[bot]"

.github/workflows/ci_prod.yaml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: main
55
jobs:
6-
test:
6+
local_seams:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master
@@ -50,8 +50,62 @@ jobs:
5050
- name: Install dependencies and run the test
5151
run: |
5252
npm install
53-
npm run E2Etests
53+
npm run test:local
5454
55+
integration_seams:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@master
59+
- name: Create .env from secrets
60+
uses: SpicyPizza/create-envfile@v2
61+
with:
62+
fail_on_empty: false
63+
sort_keys: false
64+
envkey_DOWN: ${{ secrets.DOWN }}
65+
envkey_SERVERURL: ${{ secrets.SERVERURL }}
66+
envkey_MONGODBNAME: ${{ secrets.MONGODBNAME }}
67+
envkey_MONGODB: ${{ secrets.MONGODB }}
68+
envkey_TPENPROJECTS: ${{ secrets.TPENPROJECTS }}
69+
envkey_TPENGROUPS: ${{ secrets.TPENGROUPS }}
70+
envkey_TPENUSERS: ${{ secrets.TPENUSERS }}
71+
envkey_MARIADBNAME: ${{ secrets.MARIADBNAME }}
72+
envkey_MARIADB: ${{ secrets.MARIADB }}
73+
envkey_MARIADBUSER: ${{ secrets.MARIADBUSER }}
74+
envkey_MARIADBPASSWORD: ${{ secrets.MARIADBPASSWORD }}
75+
envkey_RERUMIDPREFIX: ${{ secrets.RERUMIDPREFIX }}
76+
envkey_TINYPEN: ${{ secrets.TINYPEN }}
77+
envkey_AUDIENCE: ${{ secrets.AUDIENCE }}
78+
envkey_DOMAIN: ${{ secrets.DOMAIN }}
79+
envkey_TPEN_SUPPORT_EMAIL: ${{ secrets.TPEN_SUPPORT_EMAIL }}
80+
envkey_SMTP_HOST: ${{ secrets.SMTP_HOST }}
81+
envkey_SMTP_PORT: ${{ secrets.SMTP_PORT }}
82+
envkey_TPEN_EMAIL_CC: ${{ secrets.TPEN_EMAIL_CC }}
83+
- name: Setup Node.js
84+
uses: actions/setup-node@master
85+
with:
86+
node-version: "24"
87+
- name: Cache node modules
88+
uses: actions/cache@master
89+
env:
90+
cache-name: cache-node-modules
91+
with:
92+
path: ~/.npm
93+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{
94+
hashFiles('**/package-lock.json') }}
95+
restore-keys: |
96+
${{ runner.os }}-build-${{ env.cache-name }}-
97+
${{ runner.os }}-build-
98+
${{ runner.os }}-
99+
- name: Install dependencies and run the test
100+
run: |
101+
npm install
102+
npm run test:integration
103+
104+
bump_version:
105+
runs-on: ubuntu-latest
106+
needs: [local_seams, integration_seams]
107+
steps:
108+
- uses: actions/checkout@master
55109
- name: Bump version (minor + prerelease)
56110
run: |
57111
git config user.name "github-actions[bot]"

CONFIG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Configuration Architecture
44

5-
TPEN Services uses a layered configuration approach to separate safe defaults from environment-specific secrets. Configuration is loaded using `--import ./env-loader.js` with the dotenv package:
5+
TPEN Services uses a layered configuration approach to separate safe defaults from environment-specific secrets. Configuration is loaded using Node native env-file flags in npm scripts:
66

77
1. **`config.env`** (committed) - Safe defaults for development
88
2. **`.env`** (gitignored) - Environment-specific overrides
@@ -47,10 +47,10 @@ cp .env.production .env
4747
# Optional: Database connections, SMTP, etc.
4848
```
4949

50-
The application loads configuration via `--import ./env-loader.js` using the dotenv package in this order:
50+
The application loads configuration via Node flags in this order:
5151

5252
1. `config.env` - provides safe defaults
53-
2. `.env.{NODE_ENV}` - environment-specific overrides (.env.development, .env.production, .env.test)
53+
2. `.env.development` - development template values
5454
3. `.env` - local/server overrides (HIGHEST PRIORITY)
5555

5656
### What Goes Where?

CONTRIBUTING.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ curl http://localhost:3011
126126

127127
## Testing
128128

129-
TPEN Services uses Jest for testing with multiple test suites:
129+
TPEN Services uses Node.js built-in test runner (`node:test`) with `c8` for coverage:
130130

131131
### Run All Tests
132132
```bash
@@ -135,31 +135,18 @@ npm run allTests
135135

136136
### Run Specific Test Suites
137137
```bash
138-
# Unit tests only
138+
# Fast local seam checks
139139
npm run unitTests
140140

141-
# End-to-end tests
141+
# CI-oriented integration seam checks
142142
npm run E2Etests
143143

144-
# Database tests
145-
npm run dbTests
146-
147-
# Authentication tests
148-
npm run authTest
149-
150-
# User class tests
151-
npm run userClassTests
152-
153-
# Import functionality tests
154-
npm run importTests
155-
156-
# Member invitation tests
157-
npm run inviteMemberTests
144+
# Coverage report
145+
npm run test:coverage
158146
```
159147

160148
### Test Requirements
161-
- Some tests require database connections and will be skipped if databases are not available
162-
- Authentication tests require proper Auth0 configuration ( currently skipped )
149+
- Current suites focus on API seam and validation contract regressions, and are designed to run without live DB dependencies
163150
- Ensure your `.env` file is properly configured before running tests
164151

165152
## Code Style and Best Practices
@@ -179,7 +166,7 @@ npm run inviteMemberTests
179166
- **API Routes**: Organized in feature folders (`project/`, `manifest/`, `line/`, etc.)
180167
- **Classes**: Located in `classes/` directory
181168
- **Utilities**: Helper functions in `utilities/` directory
182-
- **Tests**: Use `__tests__` directories or `.test.js` suffix
169+
- **Tests**: Use the `test/local` and `test/integration` directories with `.test.js` files
183170

184171
### Error Handling
185172
- Use appropriate HTTP status codes
@@ -245,7 +232,7 @@ TPEN-services/
245232
├── line/ # Line/annotation routes
246233
├── userProfile/ # User profile routes
247234
├── utilities/ # Helper functions
248-
├── __tests__/ # Global tests
235+
├── test/ # node:test suites (local and integration)
249236
├── app.js # Express app configuration
250237
├── package.json # Dependencies and scripts
251238
├── config.env # Safe defaults (committed)
@@ -271,7 +258,7 @@ TPEN-services/
271258
- [TPEN Project Homepage](https://t-pen.org/TPEN3)
272259
- [Express.js Documentation](https://expressjs.com/)
273260
- [MongoDB Documentation](https://docs.mongodb.com/)
274-
- [Jest Testing Framework](https://jestjs.io/)
261+
- [Node.js Test Runner](https://nodejs.org/api/test.html)
275262
- [Auth0 Documentation](https://auth0.com/docs)
276263

277264
## License

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Services required by TPEN interfaces in order to interact with data.
3636

3737
### Configuration Files
3838

39-
TPEN Services uses a layered configuration approach with `--import ./env-loader.js` using the dotenv package:
39+
TPEN Services uses a layered configuration approach with Node's native env-file support:
4040

4141
- **`config.env`** - Safe defaults, committed to repository
4242
- Works out-of-the-box for local Docker/MongoDB/MariaDB
@@ -58,10 +58,10 @@ TPEN Services uses a layered configuration approach with `--import ./env-loader.
5858
- Contains your specific settings and secrets
5959
- Overrides values from `config.env`
6060

61-
Configuration is loaded via `--import ./env-loader.js` using the dotenv package:
61+
Configuration is loaded via Node CLI flags in npm scripts:
6262

6363
1. `config.env` is loaded first (provides safe defaults)
64-
2. `.env.{NODE_ENV}` is loaded second (environment-specific: .env.development, .env.production, .env.test)
64+
2. `.env.development` is loaded second (development defaults)
6565
3. `.env` is loaded last (local/server overrides - HIGHEST PRIORITY)
6666

6767
### Environment Variables
@@ -79,14 +79,17 @@ See [CONFIG.md](./CONFIG.md) for complete configuration documentation.
7979
## Testing
8080

8181
```bash
82-
# Run all tests
82+
# Fast local regression suite (node:test)
83+
npm test
84+
85+
# Run local + integration seams
8386
npm run allTests
8487

85-
# Run specific test suites
86-
npm run unitTests # Core unit tests
87-
npm run existsTests # Route/class validation
88-
npm run E2Etests # End-to-end API tests
89-
npm run dbTests # Database tests
88+
# Run only CI-oriented integration seams
89+
npm run E2Etests
90+
91+
# Coverage with c8
92+
npm run test:coverage
9093
```
9194

9295
## Deployment

__tests__/full_end_to_end.test.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)