Skip to content

Commit ec1be60

Browse files
committed
feat(tests): refactor E2E tests to use dedicated test data directory and update paths
1 parent 83abf19 commit ec1be60

14 files changed

+58
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ services/backend/persistent_data/*
5858

5959
# Test files
6060
services/backend/tests/.test-context.json
61+
services/backend/tests/e2e/test-data/*.db
6162

6263
._*.ts
6364
._*.vue
-136 KB
Binary file not shown.

services/backend/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
4-
testMatch: ['**/tests/**/*.test.ts'],
4+
testMatch: ['**/tests/e2e/**/*.test.ts'],
55
moduleNameMapper: {
66
'^@src/(.*)$': '<rootDir>/src/$1',
77
},

services/backend/src/routes/db/setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ async function setupDbHandler(
3030
// Determine DB path based on environment
3131
const isTestEnv = process.env.NODE_ENV === 'test';
3232
const sqliteDbFileName = isTestEnv ? 'deploystack.test.db' : 'deploystack.db';
33-
// dbPath should be relative to services/backend, and the actual db file is usually in a 'database' subfolder
34-
const sqliteDbPath = `database/${sqliteDbFileName}`;
33+
// dbPath should be relative to services/backend
34+
// For tests, use the test-data directory; for production, use the database directory
35+
const sqliteDbPath = isTestEnv ? `tests/e2e/test-data/${sqliteDbFileName}` : `database/${sqliteDbFileName}`;
3536

3637
if (clientRequestBody.type === DatabaseType.SQLite) {
3738
internalConfigObject = { type: DatabaseType.SQLite, dbPath: sqliteDbPath };

services/backend/test.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ npm run test:backend
5454
This command will:
5555

5656
1. Trigger Jest to find and execute all `*.e2e.test.ts` files within the `services/backend/tests/` directory.
57-
2. Execute a global setup script (`services/backend/tests/globalSetup.ts`) before any tests run. This script:
57+
2. Execute a global setup script (`services/backend/tests/e2e/globalSetup.ts`) before any tests run. This script:
5858
- Sets necessary environment variables for testing (e.g., `NODE_ENV=test`, a specific test port, a test encryption secret).
59-
- Clears any existing test database files (`persistent_data/database/deploystack.db` and `persistent_data/db.selection.json`) to ensure a clean state.
59+
- Clears any existing test database files from `tests/e2e/test-data/` and `persistent_data/` directories to ensure a clean state.
6060
- Programmatically starts the backend server on a dedicated test port.
6161
3. Run the tests.
6262
4. Execute a global teardown script (`services/backend/tests/globalTeardown.ts`) after all tests complete. This script stops the backend server.
@@ -109,7 +109,7 @@ When adding new E2E tests:
109109
- Ensures the test database file does not exist before setup.
110110
- Calls `POST /api/db/setup` with `{"type": "sqlite"}`.
111111
- Verifies the API response indicates successful setup initiation.
112-
- Checks that the SQLite database file (`persistent_data/database/deploystack.db`) is created.
112+
- Checks that the SQLite database file is created in the test data directory (`tests/e2e/test-data/deploystack.test.db`).
113113
- Calls `GET /api/db/status` and verifies the response shows `configured: true`, `initialized: true`, and `dialect: "sqlite"`.
114114
- Validates global settings initialization without errors.
115115
- Confirms all migrations are applied successfully.

services/backend/tests/e2e/1-setup.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as path from 'path';
55
import { getTestContext } from './testContext';
66

77
// __dirname is services/backend/tests/e2e
8-
const APP_BACKEND_ROOT = path.join(__dirname, '..', '..'); // Resolves to services/backend/
9-
const DB_FILE_PATH = path.join(APP_BACKEND_ROOT, 'database', 'deploystack.test.db'); // Path where the app creates the db
8+
const TEST_DATA_DIR = path.join(__dirname, 'test-data'); // Resolves to services/backend/tests/e2e/test-data
9+
const DB_FILE_PATH = path.join(TEST_DATA_DIR, 'deploystack.test.db'); // Path where the app creates the test db
1010

1111
describe('POST /api/db/setup and GET /api/db/status (E2E)', () => {
1212
let server: FastifyInstance;

services/backend/tests/e2e/2-user-registration.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as path from 'path';
55
import { getTestContext, updateTestContext } from './testContext';
66

77
// __dirname is services/backend/tests/e2e
8-
const APP_BACKEND_ROOT = path.join(__dirname, '..', '..'); // Resolves to services/backend/
9-
const DB_FILE_PATH = path.join(APP_BACKEND_ROOT, 'database', 'deploystack.test.db'); // Path where the app creates the db
8+
const TEST_DATA_DIR = path.join(__dirname, 'test-data'); // Resolves to services/backend/tests/e2e/test-data
9+
const DB_FILE_PATH = path.join(TEST_DATA_DIR, 'deploystack.test.db'); // Path where the app creates the test db
1010

1111
describe('User Registration E2E Tests', () => {
1212
let server: FastifyInstance;

services/backend/tests/e2e/3-email-login.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as path from 'path';
55
import { getTestContext, updateTestContext } from './testContext';
66

77
// __dirname is services/backend/tests/e2e
8-
const APP_BACKEND_ROOT = path.join(__dirname, '..', '..'); // Resolves to services/backend/
9-
const DB_FILE_PATH = path.join(APP_BACKEND_ROOT, 'database', 'deploystack.test.db'); // Path where the app creates the db
8+
const TEST_DATA_DIR = path.join(__dirname, 'test-data'); // Resolves to services/backend/tests/e2e/test-data
9+
const DB_FILE_PATH = path.join(TEST_DATA_DIR, 'deploystack.test.db'); // Path where the app creates the test db
1010

1111
describe('Email Login and Logout E2E Tests', () => {
1212
let server: FastifyInstance;

services/backend/tests/e2e/4-global-settings-check.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function getDefinedCoreSettingKeys(): Promise<string[]> {
5959
describe('Global Settings Initialization Check', () => {
6060
// __dirname is services/backend/tests/e2e
6161
const APP_BACKEND_ROOT = path.join(__dirname, '..', '..'); // Resolves to services/backend/
62-
const dbPath = path.join(APP_BACKEND_ROOT, 'database', 'deploystack.test.db'); // Correct path
62+
const dbPath = path.join(__dirname, 'test-data', 'deploystack.test.db'); // Correct path for test data
6363
let db: Database.Database;
6464

6565
beforeAll(() => {

services/backend/tests/e2e/5-global-settings-api-access.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getTestContext } from './testContext';
66

77
// __dirname is services/backend/tests/e2e
88
const APP_BACKEND_ROOT = path.join(__dirname, '..', '..'); // Resolves to services/backend/
9-
const DB_FILE_PATH = path.join(APP_BACKEND_ROOT, 'database', 'deploystack.test.db'); // Path where the app creates the db
9+
const DB_FILE_PATH = path.join(__dirname, 'test-data', 'deploystack.test.db'); // Path where the app creates the test db
1010

1111
describe('Global Settings Access Control E2E Tests', () => {
1212
let server: FastifyInstance;

0 commit comments

Comments
 (0)