Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test(server): keep the new gate tests inside the tests' type check

Maurice8e6c30f883a9
diff --git a/server/tests/unit/coverage-thresholds.test.ts b/server/tests/unit/coverage-thresholds.test.ts
index 56e551596..73d356fdc 100644
--- a/server/tests/unit/coverage-thresholds.test.ts
+++ b/server/tests/unit/coverage-thresholds.test.ts
@@ -1,7 +1,6 @@
import { readdirSync } from 'node:fs';
import path from 'node:path';
-import { describe, expect, it } from 'vitest';
-import config from '../../vitest.config';
+import { beforeAll, describe, expect, it } from 'vitest';
/**
* The coverage gate is a ratchet per src/nest domain (vitest.config.ts). A
@@ -14,6 +13,17 @@ import config from '../../vitest.config';
const NEST = path.resolve(__dirname, '../../src/nest');
+// Loaded at runtime rather than imported: an import would pull vitest.config.ts
+// into the tests' tsc program, which compiles it as CommonJS and rejects its
+// import.meta.
+const CONFIG_PATH = '../../vitest.config';
+let thresholds: Record<string, Record<string, number>> = {};
+
+beforeAll(async () => {
+ const config = ((await import(CONFIG_PATH)) as { default: { test?: { coverage?: unknown } } }).default;
+ thresholds = (config.test?.coverage as { thresholds?: typeof thresholds } | undefined)?.thresholds ?? {};
+});
+
function domains(): string[] {
return readdirSync(NEST, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
@@ -22,7 +32,6 @@ function domains(): string[] {
}
function domainKeys(): string[] {
- const thresholds = (config.test?.coverage as { thresholds?: Record<string, unknown> } | undefined)?.thresholds ?? {};
return Object.keys(thresholds)
.map((key) => key.match(/^src\/nest\/([^/*]+)\/\*\*\/\*\.ts$/)?.[1])
.filter((name): name is string => Boolean(name))
@@ -49,7 +58,6 @@ describe('per-domain coverage thresholds', () => {
});
it('COVT-004: no domain entry sits above 100 or below 0', () => {
- const thresholds = (config.test?.coverage as { thresholds?: Record<string, Record<string, number>> }).thresholds ?? {};
for (const domain of domainKeys()) {
const entry = thresholds[`src/nest/${domain}/**/*.ts`];
for (const metric of ['statements', 'branches', 'functions', 'lines']) {
diff --git a/server/tests/unit/db/foreign-key-indexes.test.ts b/server/tests/unit/db/foreign-key-indexes.test.ts
index 1aff9e4ef..309655279 100644
--- a/server/tests/unit/db/foreign-key-indexes.test.ts
+++ b/server/tests/unit/db/foreign-key-indexes.test.ts
@@ -1,6 +1,7 @@
+import { createSnapshotTestDb } from '../../helpers/db-mock';
+
import type Database from 'better-sqlite3';
import { afterAll, describe, expect, it } from 'vitest';
-import { createSnapshotTestDb } from '../../helpers/db-mock';
/**
* Migration20200101042200 added 86 indexes by hand so that deleting a trip or a
diff --git a/server/tests/unit/scripts/import-boundaries.test.ts b/server/tests/unit/scripts/import-boundaries.test.ts
index 741d8add6..9e79455e6 100644
--- a/server/tests/unit/scripts/import-boundaries.test.ts
+++ b/server/tests/unit/scripts/import-boundaries.test.ts
@@ -8,11 +8,11 @@
* violation, that what the rules deliberately ignore stays ignored, and that a
* broken setup stops the run instead of passing it.
*/
-import { afterEach, describe, expect, it } from 'vitest';
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
+import { afterEach, describe, expect, it } from 'vitest';
const SCRIPT = path.join(__dirname, '../../../scripts/import-boundaries.mjs');
@@ -140,7 +140,10 @@ describe('import-boundaries.mjs', () => {
expect(run(ok).status).toBe(0);
// Type-only still counts: it couples A to B's private shapes all the same.
- const bad = serverRoot({ ...files, 'nest/a/sub/a.thing.ts': "import type { h } from '../../b/b.helpers';\nexport type X = typeof h;\n" });
+ const bad = serverRoot({
+ ...files,
+ 'nest/a/sub/a.thing.ts': "import type { h } from '../../b/b.helpers';\nexport type X = typeof h;\n",
+ });
const { status, out } = run(bad);
expect(status).toBe(1);
expect(out).toContain('FAIL domainInternals: a -> b/b.helpers.ts');
@@ -149,7 +152,8 @@ describe('import-boundaries.mjs', () => {
it('BOUND-006: fails when a shared-kernel file imports a domain', () => {
const dir = serverRoot({
'nest/auth/jwt-auth.guard.ts': 'export class JwtAuthGuard {}\n',
- 'nest/common/validate.ts': "import { JwtAuthGuard } from '../auth/jwt-auth.guard';\nexport const g = JwtAuthGuard;\n",
+ 'nest/common/validate.ts':
+ "import { JwtAuthGuard } from '../auth/jwt-auth.guard';\nexport const g = JwtAuthGuard;\n",
});
const { status, out } = run(dir);
expect(status).toBe(1);
@@ -181,7 +185,9 @@ describe('import-boundaries.mjs', () => {
expect(check.out).toContain('1 baseline entry no longer occurs');
expect(run(dir, '--update').status).toBe(1);
- const written: unknown = JSON.parse(readFileSync(path.join(dir, 'scripts/import-boundaries-baseline.json'), 'utf8'));
+ const written: unknown = JSON.parse(
+ readFileSync(path.join(dir, 'scripts/import-boundaries-baseline.json'), 'utf8'),
+ );
expect(written).toEqual({ ...EMPTY, domainInternals: ['a -> b/b.helpers.ts'] });
});
diff --git a/server/tests/unit/scripts/size-lint.test.ts b/server/tests/unit/scripts/size-lint.test.ts
index ba12eed55..8a4e88508 100644
--- a/server/tests/unit/scripts/size-lint.test.ts
+++ b/server/tests/unit/scripts/size-lint.test.ts
@@ -6,11 +6,11 @@
* fails on a violation and that it refuses to run on a broken setup instead
* of passing silently.
*/
-import { afterEach, describe, expect, it } from 'vitest';
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
+import { afterEach, describe, expect, it } from 'vitest';
const SCRIPT = path.join(__dirname, '../../../scripts/size-lint.mjs');
@@ -130,7 +130,12 @@ describe('size-lint.mjs', () => {
it('SIZE-009: --update only lowers, drops files back under the limit, and never adds one', () => {
const dir = serverRoot(
- { 'src/shrunk.ts': lines(1100), 'src/fixed.ts': lines(50), 'src/grown.ts': lines(1500), 'src/new.ts': lines(1300) },
+ {
+ 'src/shrunk.ts': lines(1100),
+ 'src/fixed.ts': lines(50),
+ 'src/grown.ts': lines(1500),
+ 'src/new.ts': lines(1300),
+ },
{ 'src/shrunk.ts': 1200, 'src/fixed.ts': 1300, 'src/grown.ts': 1400, 'src/gone.ts': 1100 },
);
const { status } = run(dir, '--update');