@terreno/test 57.17.0 → 57.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1681 -0
- package/README.md +6 -0
- package/dist/assertions/expectAPIError.d.ts +18 -0
- package/dist/assertions/expectAPIError.js +33 -0
- package/dist/assertions/strictResponseProperties.d.ts +14 -0
- package/dist/assertions/strictResponseProperties.js +37 -0
- package/dist/cache/mongoTestCache.js +2 -2
- package/dist/cli/collectFiles.d.ts +38 -0
- package/dist/cli/collectFiles.js +73 -0
- package/dist/cli/testHygiene.d.ts +134 -0
- package/dist/cli/testHygiene.js +357 -0
- package/dist/cli/testHygieneCli.d.ts +2 -0
- package/dist/cli/testHygieneCli.js +5 -0
- package/dist/cli/testHygieneRules.d.ts +58 -0
- package/dist/cli/testHygieneRules.js +517 -0
- package/dist/cli/testShard.d.ts +155 -0
- package/dist/cli/testShard.js +377 -0
- package/dist/cli/testShardCli.d.ts +2 -0
- package/dist/cli/testShardCli.js +5 -0
- package/dist/expo/authTokenStorage.d.ts +76 -0
- package/dist/expo/authTokenStorage.js +160 -0
- package/dist/expo/expoModuleMocks.d.ts +24 -0
- package/dist/expo/expoModuleMocks.js +456 -0
- package/dist/expo/libraryModuleMocks.d.ts +17 -0
- package/dist/expo/libraryModuleMocks.js +347 -0
- package/dist/expo/mockHelpers.d.ts +39 -0
- package/dist/expo/mockHelpers.js +45 -0
- package/dist/expo/mockModuleAliases.d.ts +50 -0
- package/dist/expo/mockModuleAliases.js +174 -0
- package/dist/expo/reactNativeMock.d.ts +39 -0
- package/dist/expo/reactNativeMock.js +421 -0
- package/dist/expo/registerExpoTestEnvironment.d.ts +69 -0
- package/dist/expo/registerExpoTestEnvironment.js +163 -0
- package/dist/expo/renderWithTerreno.d.ts +47 -0
- package/dist/expo/renderWithTerreno.js +47 -0
- package/dist/http/authWithToken.d.ts +20 -0
- package/dist/http/authWithToken.js +30 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +33 -1
- package/dist/logging/silenceLogs.js +0 -2
- package/dist/mocks/aiSdk.d.ts +77 -0
- package/dist/mocks/aiSdk.js +102 -0
- package/dist/mocks/cloudTasks.d.ts +91 -0
- package/dist/mocks/cloudTasks.js +197 -0
- package/dist/mocks/expoPush.d.ts +53 -0
- package/dist/mocks/expoPush.js +57 -0
- package/dist/mocks/gcs.d.ts +101 -0
- package/dist/mocks/gcs.js +162 -0
- package/dist/mocks/googleAuth.d.ts +69 -0
- package/dist/mocks/googleAuth.js +55 -0
- package/dist/mocks/mockGroup.d.ts +11 -0
- package/dist/mocks/mockGroup.js +21 -0
- package/dist/mocks/notifiers.d.ts +21 -0
- package/dist/mocks/notifiers.js +26 -0
- package/dist/mocks/sendgrid.d.ts +22 -0
- package/dist/mocks/sendgrid.js +32 -0
- package/dist/mocks/twilio.d.ts +72 -0
- package/dist/mocks/twilio.js +64 -0
- package/dist/preload/registerBackendPreload.js +4 -1
- package/dist/time/freezeTime.d.ts +16 -0
- package/dist/time/freezeTime.js +49 -0
- package/dist/transaction/testTransaction.d.ts +43 -6
- package/dist/transaction/testTransaction.js +371 -92
- package/dist/utils/waitUntil.d.ts +22 -0
- package/dist/utils/waitUntil.js +34 -0
- package/package.json +53 -8
- package/src/assertions/expectAPIError.ts +51 -0
- package/src/assertions/strictResponseProperties.ts +42 -0
- package/src/cache/mongoTestCache.ts +2 -2
- package/src/cli/collectFiles.ts +115 -0
- package/src/cli/testHygiene.ts +539 -0
- package/src/cli/testHygieneCli.ts +4 -0
- package/src/cli/testHygieneRules.ts +719 -0
- package/src/cli/testShard.ts +532 -0
- package/src/cli/testShardCli.ts +4 -0
- package/src/expo/authTokenStorage.ts +198 -0
- package/src/expo/expoModuleMocks.ts +503 -0
- package/src/expo/libraryModuleMocks.ts +411 -0
- package/src/expo/mockHelpers.ts +73 -0
- package/src/expo/mockModuleAliases.ts +252 -0
- package/src/expo/reactNativeMock.ts +534 -0
- package/src/expo/registerExpoTestEnvironment.ts +260 -0
- package/src/expo/renderWithTerreno.ts +79 -0
- package/src/http/authWithToken.ts +38 -0
- package/src/index.ts +82 -1
- package/src/logging/silenceLogs.ts +0 -2
- package/src/mocks/aiSdk.ts +199 -0
- package/src/mocks/cloudTasks.ts +323 -0
- package/src/mocks/expoPush.ts +134 -0
- package/src/mocks/gcs.ts +305 -0
- package/src/mocks/googleAuth.ts +136 -0
- package/src/mocks/mockGroup.ts +32 -0
- package/src/mocks/notifiers.ts +36 -0
- package/src/mocks/sendgrid.ts +57 -0
- package/src/mocks/twilio.ts +143 -0
- package/src/preload/registerBackendPreload.ts +4 -1
- package/src/time/freezeTime.ts +61 -0
- package/src/transaction/testTransaction.ts +456 -124
- package/src/utils/waitUntil.ts +47 -0
- package/biome.jsonc +0 -20
- package/bunfig.toml +0 -16
- package/src/cache/mongoTestCache.test.ts +0 -103
- package/src/env/setTerrenoTestEnv.test.ts +0 -26
- package/src/http/authAsUser.test.ts +0 -40
- package/src/http/getBaseServer.test.ts +0 -45
- package/src/logging/setupEnvironment.test.ts +0 -24
- package/src/logging/silenceLogs.test.ts +0 -52
- package/src/logging/testLogger.test.ts +0 -58
- package/src/mocks/sentryBun.test.ts +0 -230
- package/src/mongo/connection.test.ts +0 -43
- package/src/mongo/mongoServer.test.ts +0 -99
- package/src/preload/registerBackendPreload.test.ts +0 -10
- package/src/transaction/testTransaction.test.ts +0 -64
- package/src/utils/helpers.test.ts +0 -46
- package/tsconfig.json +0 -18
package/README.md
CHANGED
|
@@ -42,7 +42,13 @@ Then run `bun test` in the package. The preload starts `mongodb-memory-server` w
|
|
|
42
42
|
- `registerBackendPreload` — full lifecycle with optional transactions and fixture cache
|
|
43
43
|
- `setTerrenoTestEnv` — canonical auth secrets for tests
|
|
44
44
|
- `getBaseServer` / `authAsUser` — Express + supertest helpers
|
|
45
|
+
- `authWithToken` — authenticate with a pre-minted token, skipping the login round-trip
|
|
46
|
+
- `waitUntil` / `waitForCalls` / `freezeTime` — poll instead of sleeping; freeze the clock
|
|
47
|
+
- `expectAPIError` / `assertStrictResponseProperties` — error-body and field-leak assertions
|
|
48
|
+
- Opt-in SDK mocks: Cloud Tasks, SendGrid, Twilio, Expo push, GCS, Google auth, AI SDK, notifiers
|
|
45
49
|
- Log silencing and Sentry mocks for quiet CI
|
|
50
|
+
- `@terreno/test/expo/*` — Bun test environment for Expo / React Native apps
|
|
51
|
+
- `terreno-test-shard` and `terreno-test-hygiene` CLIs
|
|
46
52
|
|
|
47
53
|
## Documentation
|
|
48
54
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ExpectedAPIError {
|
|
2
|
+
status: number;
|
|
3
|
+
title?: string | RegExp;
|
|
4
|
+
detail?: string | RegExp;
|
|
5
|
+
code?: string;
|
|
6
|
+
/** Partial match against `meta.fields`, the per-field validation messages. */
|
|
7
|
+
fields?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
interface ResponseLike {
|
|
10
|
+
status: number;
|
|
11
|
+
body: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Asserts a supertest response is the JSONAPI error body `@terreno/api` sends for an `APIError`:
|
|
15
|
+
* `{status, title, detail?, code?, meta?: {fields?}}`. Only the keys you pass are checked.
|
|
16
|
+
*/
|
|
17
|
+
export declare const expectAPIError: (res: ResponseLike, expected: ExpectedAPIError) => void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectAPIError = void 0;
|
|
4
|
+
const bun_test_1 = require("bun:test");
|
|
5
|
+
const expectText = (actual, expected) => {
|
|
6
|
+
if (expected instanceof RegExp) {
|
|
7
|
+
(0, bun_test_1.expect)(String(actual)).toMatch(expected);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
(0, bun_test_1.expect)(actual).toBe(expected);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Asserts a supertest response is the JSONAPI error body `@terreno/api` sends for an `APIError`:
|
|
14
|
+
* `{status, title, detail?, code?, meta?: {fields?}}`. Only the keys you pass are checked.
|
|
15
|
+
*/
|
|
16
|
+
const expectAPIError = (res, expected) => {
|
|
17
|
+
const body = (res.body ?? {});
|
|
18
|
+
(0, bun_test_1.expect)(res.status).toBe(expected.status);
|
|
19
|
+
(0, bun_test_1.expect)(body.status).toBe(expected.status);
|
|
20
|
+
if (expected.title !== undefined) {
|
|
21
|
+
expectText(body.title, expected.title);
|
|
22
|
+
}
|
|
23
|
+
if (expected.detail !== undefined) {
|
|
24
|
+
expectText(body.detail, expected.detail);
|
|
25
|
+
}
|
|
26
|
+
if (expected.code !== undefined) {
|
|
27
|
+
(0, bun_test_1.expect)(body.code).toBe(expected.code);
|
|
28
|
+
}
|
|
29
|
+
if (expected.fields !== undefined) {
|
|
30
|
+
(0, bun_test_1.expect)(body.meta?.fields ?? {}).toMatchObject(expected.fields);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.expectAPIError = expectAPIError;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists the dot-separated path of every property in `value`. Arrays add no path segment, so
|
|
3
|
+
* `{data: [{email}]}` yields `data` and `data.email`; that lets one allowlist cover list and
|
|
4
|
+
* single-document responses.
|
|
5
|
+
*/
|
|
6
|
+
export declare const collectPropertyPaths: (value: unknown, prefix?: string) => string[];
|
|
7
|
+
/**
|
|
8
|
+
* Fails when a response exposes any property outside `allowedPaths`.
|
|
9
|
+
*
|
|
10
|
+
* Guards permission-scoped endpoints against leaking fields (PHI, secrets) when someone adds a
|
|
11
|
+
* field to a model or a populate. A path is allowed when it is listed, is an ancestor of a listed
|
|
12
|
+
* path, or sits under a listed path (listing `address` allows `address.city`).
|
|
13
|
+
*/
|
|
14
|
+
export declare const assertStrictResponseProperties: (body: unknown, allowedPaths: string[]) => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertStrictResponseProperties = exports.collectPropertyPaths = void 0;
|
|
4
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
/**
|
|
6
|
+
* Lists the dot-separated path of every property in `value`. Arrays add no path segment, so
|
|
7
|
+
* `{data: [{email}]}` yields `data` and `data.email`; that lets one allowlist cover list and
|
|
8
|
+
* single-document responses.
|
|
9
|
+
*/
|
|
10
|
+
const collectPropertyPaths = (value, prefix = "") => {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return [...new Set(value.flatMap((item) => (0, exports.collectPropertyPaths)(item, prefix)))];
|
|
13
|
+
}
|
|
14
|
+
if (!isPlainObject(value)) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return Object.entries(value).flatMap(([key, child]) => {
|
|
18
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
19
|
+
return [path, ...(0, exports.collectPropertyPaths)(child, path)];
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
exports.collectPropertyPaths = collectPropertyPaths;
|
|
23
|
+
const isPathAllowed = (path, allowedPaths) => allowedPaths.some((allowed) => allowed === path || allowed.startsWith(`${path}.`) || path.startsWith(`${allowed}.`));
|
|
24
|
+
/**
|
|
25
|
+
* Fails when a response exposes any property outside `allowedPaths`.
|
|
26
|
+
*
|
|
27
|
+
* Guards permission-scoped endpoints against leaking fields (PHI, secrets) when someone adds a
|
|
28
|
+
* field to a model or a populate. A path is allowed when it is listed, is an ancestor of a listed
|
|
29
|
+
* path, or sits under a listed path (listing `address` allows `address.city`).
|
|
30
|
+
*/
|
|
31
|
+
const assertStrictResponseProperties = (body, allowedPaths) => {
|
|
32
|
+
const unexpected = (0, exports.collectPropertyPaths)(body).filter((path) => !isPathAllowed(path, allowedPaths));
|
|
33
|
+
if (unexpected.length > 0) {
|
|
34
|
+
throw new Error(`Unexpected field(s) in response: ${unexpected.join(", ")}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.assertStrictResponseProperties = assertStrictResponseProperties;
|
|
@@ -202,8 +202,8 @@ const loadTestDataIntoDb = async (cachedCollections) => {
|
|
|
202
202
|
continue;
|
|
203
203
|
}
|
|
204
204
|
const convertedDocs = docs.map((doc) => convertValue(doc));
|
|
205
|
-
restorePromises.push(
|
|
206
|
-
.
|
|
205
|
+
restorePromises.push(requireDb()
|
|
206
|
+
.collection(collectionName)
|
|
207
207
|
.insertMany(convertedDocs, { ordered: false }));
|
|
208
208
|
}
|
|
209
209
|
const restoreResults = await Promise.allSettled(restorePromises);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Glob patterns (relative to the working directory) that identify a test file by default. */
|
|
2
|
+
export declare const DEFAULT_TEST_PATTERNS: readonly string[];
|
|
3
|
+
/**
|
|
4
|
+
* Directory names skipped at any depth while walking. Build output, native projects, and
|
|
5
|
+
* Playwright `e2e/` suites are never `bun test` files, and walking `node_modules` is slow.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_EXCLUDED_DIRS: readonly string[];
|
|
8
|
+
export interface CollectFilesOptions {
|
|
9
|
+
/** Files or directories to search, absolute or relative to `cwd`. */
|
|
10
|
+
paths: string[];
|
|
11
|
+
/** Directory that patterns and returned paths are relative to. */
|
|
12
|
+
cwd: string;
|
|
13
|
+
/** Globs matched against each file's `cwd`-relative POSIX path. Defaults to `DEFAULT_TEST_PATTERNS`. */
|
|
14
|
+
patterns?: readonly string[];
|
|
15
|
+
/** Directory names skipped at any depth. Defaults to `DEFAULT_EXCLUDED_DIRS`. */
|
|
16
|
+
excludeDirs?: readonly string[];
|
|
17
|
+
/** Globs matched against each file's `cwd`-relative POSIX path; matches are dropped. */
|
|
18
|
+
exclude?: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export interface CollectFilesResult {
|
|
21
|
+
/** Sorted, de-duplicated `cwd`-relative POSIX paths. */
|
|
22
|
+
files: string[];
|
|
23
|
+
/** Input paths that do not exist. */
|
|
24
|
+
missingPaths: string[];
|
|
25
|
+
}
|
|
26
|
+
/** Converts a native path to forward-slash form so globs and output are platform independent. */
|
|
27
|
+
export declare const toPosixPath: (filePath: string) => string;
|
|
28
|
+
/** Returns whether `filePath` matches at least one glob. */
|
|
29
|
+
export declare const matchesAnyGlob: ({ filePath, globs, }: {
|
|
30
|
+
filePath: string;
|
|
31
|
+
globs: readonly string[];
|
|
32
|
+
}) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Recursively collects files under `paths` whose `cwd`-relative path matches `patterns`,
|
|
35
|
+
* skipping excluded directory names and `exclude` globs. Discovery is filesystem driven so a
|
|
36
|
+
* newly added file is always picked up without editing a hand-maintained list.
|
|
37
|
+
*/
|
|
38
|
+
export declare const collectFiles: ({ paths, cwd, patterns, excludeDirs, exclude, }: CollectFilesOptions) => CollectFilesResult;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.collectFiles = exports.matchesAnyGlob = exports.toPosixPath = exports.DEFAULT_EXCLUDED_DIRS = exports.DEFAULT_TEST_PATTERNS = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
/** Glob patterns (relative to the working directory) that identify a test file by default. */
|
|
10
|
+
exports.DEFAULT_TEST_PATTERNS = ["**/*.test.ts", "**/*.test.tsx"];
|
|
11
|
+
/**
|
|
12
|
+
* Directory names skipped at any depth while walking. Build output, native projects, and
|
|
13
|
+
* Playwright `e2e/` suites are never `bun test` files, and walking `node_modules` is slow.
|
|
14
|
+
*/
|
|
15
|
+
exports.DEFAULT_EXCLUDED_DIRS = [
|
|
16
|
+
".expo",
|
|
17
|
+
".git",
|
|
18
|
+
"android",
|
|
19
|
+
"build",
|
|
20
|
+
"coverage",
|
|
21
|
+
"dist",
|
|
22
|
+
"e2e",
|
|
23
|
+
"ios",
|
|
24
|
+
"node_modules",
|
|
25
|
+
];
|
|
26
|
+
/** Converts a native path to forward-slash form so globs and output are platform independent. */
|
|
27
|
+
const toPosixPath = (filePath) => filePath.replaceAll("\\", "/");
|
|
28
|
+
exports.toPosixPath = toPosixPath;
|
|
29
|
+
/** Returns whether `filePath` matches at least one glob. */
|
|
30
|
+
const matchesAnyGlob = ({ filePath, globs, }) => globs.some((glob) => new Bun.Glob(glob).match(filePath));
|
|
31
|
+
exports.matchesAnyGlob = matchesAnyGlob;
|
|
32
|
+
const walkFiles = ({ dir, excludeDirs, out, }) => {
|
|
33
|
+
for (const entry of (0, node_fs_1.readdirSync)(dir, { withFileTypes: true })) {
|
|
34
|
+
if (excludeDirs.has(entry.name)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const fullPath = node_path_1.default.join(dir, entry.name);
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
walkFiles({ dir: fullPath, excludeDirs, out });
|
|
40
|
+
}
|
|
41
|
+
else if (entry.isFile()) {
|
|
42
|
+
out.push(fullPath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Recursively collects files under `paths` whose `cwd`-relative path matches `patterns`,
|
|
48
|
+
* skipping excluded directory names and `exclude` globs. Discovery is filesystem driven so a
|
|
49
|
+
* newly added file is always picked up without editing a hand-maintained list.
|
|
50
|
+
*/
|
|
51
|
+
const collectFiles = ({ paths, cwd, patterns = exports.DEFAULT_TEST_PATTERNS, excludeDirs = exports.DEFAULT_EXCLUDED_DIRS, exclude = [], }) => {
|
|
52
|
+
const excludedDirNames = new Set(excludeDirs);
|
|
53
|
+
const missingPaths = [];
|
|
54
|
+
const absoluteFiles = [];
|
|
55
|
+
for (const target of paths) {
|
|
56
|
+
const absoluteTarget = node_path_1.default.resolve(cwd, target);
|
|
57
|
+
if (!(0, node_fs_1.existsSync)(absoluteTarget)) {
|
|
58
|
+
missingPaths.push(target);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if ((0, node_fs_1.statSync)(absoluteTarget).isFile()) {
|
|
62
|
+
absoluteFiles.push(absoluteTarget);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
walkFiles({ dir: absoluteTarget, excludeDirs: excludedDirNames, out: absoluteFiles });
|
|
66
|
+
}
|
|
67
|
+
const files = [
|
|
68
|
+
...new Set(absoluteFiles.map((file) => (0, exports.toPosixPath)(node_path_1.default.relative(cwd, file)))),
|
|
69
|
+
].filter((file) => (0, exports.matchesAnyGlob)({ filePath: file, globs: patterns }) &&
|
|
70
|
+
!(0, exports.matchesAnyGlob)({ filePath: file, globs: exclude }));
|
|
71
|
+
return { files: files.sort(), missingPaths };
|
|
72
|
+
};
|
|
73
|
+
exports.collectFiles = collectFiles;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { type HygieneRuleConfig, type HygieneRuleId, type HygieneViolation } from "./testHygieneRules";
|
|
2
|
+
export interface BaselineEntry {
|
|
3
|
+
file: string;
|
|
4
|
+
rule: HygieneRuleId;
|
|
5
|
+
count: number;
|
|
6
|
+
}
|
|
7
|
+
/** JSON config file shape. Relative paths resolve against the config file's directory. */
|
|
8
|
+
export interface TestHygieneConfigFile {
|
|
9
|
+
/** Directory scanned, reported against, and used for barrel paths (default: config dir). */
|
|
10
|
+
root?: string;
|
|
11
|
+
/** Files or directories to scan, relative to `root` (default: `["."]`). */
|
|
12
|
+
paths?: string[];
|
|
13
|
+
/** Test file globs relative to `root`. */
|
|
14
|
+
include?: string[];
|
|
15
|
+
/** Root-relative globs to skip. */
|
|
16
|
+
exclude?: string[];
|
|
17
|
+
/** Directory names skipped at any depth, added to the defaults. */
|
|
18
|
+
excludeDirs?: string[];
|
|
19
|
+
/** Baseline path. */
|
|
20
|
+
baseline?: string;
|
|
21
|
+
/** Rule toggles; omitted rules stay on. */
|
|
22
|
+
rules?: Partial<Record<HygieneRuleId, boolean>>;
|
|
23
|
+
barrels?: {
|
|
24
|
+
aliases?: string[];
|
|
25
|
+
paths?: string[];
|
|
26
|
+
allowMockIn?: string[];
|
|
27
|
+
};
|
|
28
|
+
mockHelperModules?: string[];
|
|
29
|
+
realExportGetters?: {
|
|
30
|
+
modules?: string[];
|
|
31
|
+
namePattern?: string;
|
|
32
|
+
};
|
|
33
|
+
sleepCallees?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface ResolvedHygieneConfig {
|
|
36
|
+
rootDir: string;
|
|
37
|
+
paths: string[];
|
|
38
|
+
include: string[];
|
|
39
|
+
exclude: string[];
|
|
40
|
+
excludeDirs: string[];
|
|
41
|
+
baselinePath: string;
|
|
42
|
+
rules: HygieneRuleId[];
|
|
43
|
+
ruleConfig: HygieneRuleConfig;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Drops violations whose preceding line carries a matching suppression directive. The directive
|
|
47
|
+
* accepts a comma-separated rule list, followed by an optional `-- reason`.
|
|
48
|
+
*/
|
|
49
|
+
export declare const applySuppressions: ({ sourceText, violations, }: {
|
|
50
|
+
sourceText: string;
|
|
51
|
+
violations: HygieneViolation[];
|
|
52
|
+
}) => {
|
|
53
|
+
violations: HygieneViolation[];
|
|
54
|
+
};
|
|
55
|
+
/** Parses, runs the enabled rules on, and suppression-filters one file. Filesystem free. */
|
|
56
|
+
export declare const checkTestSource: ({ fileName, sourceText, config, rules, }: {
|
|
57
|
+
fileName: string;
|
|
58
|
+
sourceText: string;
|
|
59
|
+
config: HygieneRuleConfig;
|
|
60
|
+
rules?: readonly HygieneRuleId[];
|
|
61
|
+
}) => {
|
|
62
|
+
violations: HygieneViolation[];
|
|
63
|
+
};
|
|
64
|
+
/** Counts violations per file/rule pair, sorted by file then rule for stable diffs. */
|
|
65
|
+
export declare const buildBaseline: ({ violations, }: {
|
|
66
|
+
violations: HygieneViolation[];
|
|
67
|
+
}) => {
|
|
68
|
+
entries: BaselineEntry[];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Splits violations into new ones (beyond the baseline count for their file/rule pair) and
|
|
72
|
+
* reports baseline entries whose count is now higher than reality, so the baseline can ratchet.
|
|
73
|
+
*/
|
|
74
|
+
export declare const diffAgainstBaseline: ({ violations, baseline, }: {
|
|
75
|
+
violations: HygieneViolation[];
|
|
76
|
+
baseline: BaselineEntry[];
|
|
77
|
+
}) => {
|
|
78
|
+
newViolations: HygieneViolation[];
|
|
79
|
+
staleEntries: BaselineEntry[];
|
|
80
|
+
};
|
|
81
|
+
/** Parses and validates baseline JSON. */
|
|
82
|
+
export declare const parseBaseline: ({ text, }: {
|
|
83
|
+
text: string;
|
|
84
|
+
}) => {
|
|
85
|
+
entries: BaselineEntry[];
|
|
86
|
+
} | {
|
|
87
|
+
error: string;
|
|
88
|
+
};
|
|
89
|
+
/** Counts violations per rule, including rules with zero findings, in rule order. */
|
|
90
|
+
export declare const countByRule: ({ violations, rules, }: {
|
|
91
|
+
violations: HygieneViolation[];
|
|
92
|
+
rules?: readonly HygieneRuleId[];
|
|
93
|
+
}) => {
|
|
94
|
+
counts: Record<string, number>;
|
|
95
|
+
};
|
|
96
|
+
/** Applies defaults and resolves config-file paths against `configDir`. */
|
|
97
|
+
export declare const resolveHygieneConfig: ({ file, configDir, }: {
|
|
98
|
+
file?: TestHygieneConfigFile;
|
|
99
|
+
configDir: string;
|
|
100
|
+
}) => {
|
|
101
|
+
config: ResolvedHygieneConfig;
|
|
102
|
+
};
|
|
103
|
+
export interface TestHygieneCliOptions {
|
|
104
|
+
config: ResolvedHygieneConfig;
|
|
105
|
+
format: "json" | "text";
|
|
106
|
+
isHelp: boolean;
|
|
107
|
+
isUpdateBaseline: boolean;
|
|
108
|
+
useBaseline: boolean;
|
|
109
|
+
}
|
|
110
|
+
/** Merges the config file (if any) with CLI flags. Flags win; list flags extend the config. */
|
|
111
|
+
export declare const parseTestHygieneArgs: ({ argv, cwd, readFile, }: {
|
|
112
|
+
argv: string[];
|
|
113
|
+
cwd: string;
|
|
114
|
+
readFile?: (filePath: string) => string | undefined;
|
|
115
|
+
}) => {
|
|
116
|
+
options: TestHygieneCliOptions;
|
|
117
|
+
} | {
|
|
118
|
+
error: string;
|
|
119
|
+
};
|
|
120
|
+
export interface HygieneLogger {
|
|
121
|
+
info: (message: string) => void;
|
|
122
|
+
error: (message: string) => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* CLI entry point: scans test files, applies the baseline, prints findings and per-rule counts,
|
|
126
|
+
* and returns the exit code instead of exiting so it is testable.
|
|
127
|
+
*/
|
|
128
|
+
export declare const runTestHygieneCli: ({ argv, cwd, logger, }: {
|
|
129
|
+
argv: string[];
|
|
130
|
+
cwd?: string;
|
|
131
|
+
logger?: HygieneLogger;
|
|
132
|
+
}) => {
|
|
133
|
+
exitCode: number;
|
|
134
|
+
};
|