mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
test(server): keep the new gate tests inside the tests' type check
coverage-thresholds.test.ts imported vitest.config.ts, which pulled the config into tsconfig.tests.json's program; that program compiles as CommonJS and rejects the config's import.meta, so typecheck:tests failed. The test now loads the config at runtime. The other new gate tests get prettier's formatting.
This commit is contained in:
@@ -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']) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'] });
|
||||
});
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user