import { SUPPORTED_STORAGE_VERSIONS } from '@powersync/service-core'; import path from 'path'; import { fileURLToPath } from 'url'; import { normalizePostgresStorageConfig, PostgresMigrationAgent } from '../../src/index.js'; import { postgresTestSetup, PostgresTestStorageOptions } from '../../src/utils/test-utils.js'; import { env } from './env.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export const TEST_URI = env.PG_STORAGE_TEST_URL; const BASE_CONFIG = { type: 'postgresql' as const, uri: TEST_URI, sslmode: 'disable' as const }; export const TEST_CONNECTION_OPTIONS = normalizePostgresStorageConfig(BASE_CONFIG); /** * Vitest tries to load the migrations via .ts files which fails. * For tests this links to the relevant .js files correctly */ class TestPostgresMigrationAgent extends PostgresMigrationAgent { getInternalScriptsDir(): string { return path.resolve(__dirname, '../../dist/migrations/scripts'); } } export function createPostgresTestSetup(options?: Pick) { return postgresTestSetup({ url: env.PG_STORAGE_TEST_URL, migrationAgent: (config) => new TestPostgresMigrationAgent(config), ...options }); } export const POSTGRES_STORAGE_SETUP = createPostgresTestSetup(); export const POSTGRES_STORAGE_FACTORY = POSTGRES_STORAGE_SETUP; export const POSTGRES_REPORT_STORAGE_FACTORY = POSTGRES_STORAGE_SETUP.reportFactory; export const TEST_STORAGE_VERSIONS = SUPPORTED_STORAGE_VERSIONS.filter((v) => v < 3);