

























@@ -1,6 +1,6 @@
11import path from "node:path";
22import { describe, expect, it } from "vitest";
3-import { analyzeTopology } from "../../scripts/lib/ts-topology/analyze.js";
3+import { analyzeTopology, filterRecordsForReport } from "../../scripts/lib/ts-topology/analyze.js";
44import { renderTextReport } from "../../scripts/lib/ts-topology/reports.js";
55import { createFilesystemPublicSurfaceScope } from "../../scripts/lib/ts-topology/scope.js";
66import { main } from "../../scripts/ts-topology.ts";
@@ -22,16 +22,17 @@ const publicSurfaceEnvelope = analyzeTopology({
2222scope: fixtureScope,
2323report: "public-surface-usage",
2424});
25-const singleOwnerEnvelope = analyzeTopology({
26- repoRoot,
27-scope: fixtureScope,
28-report: "single-owner-shared",
29-});
30-const unusedEnvelope = analyzeTopology({
31- repoRoot,
32-scope: fixtureScope,
33-report: "unused-public-surface",
34-});
25+26+function deriveReportEnvelope(report: Parameters<typeof filterRecordsForReport>[1]) {
27+return {
28+ ...publicSurfaceEnvelope,
29+ report,
30+records: filterRecordsForReport(publicSurfaceEnvelope.records, report),
31+};
32+}
33+34+const singleOwnerEnvelope = deriveReportEnvelope("single-owner-shared");
35+const unusedEnvelope = deriveReportEnvelope("unused-public-surface");
35363637describe("ts-topology", () => {
3738it("collapses canonical symbols exported by multiple public subpaths", () => {
@@ -100,7 +101,7 @@ describe("ts-topology", () => {
100101 `);
101102});
102103103-it("emits stable JSON and filtered report output through the CLI", async () => {
104+it("emits stable JSON through the CLI and filtered report output", async () => {
104105const captured = createCapturedIo();
105106const jsonExit = await main(
106107[
@@ -121,27 +122,13 @@ describe("ts-topology", () => {
121122payload.records.map((record: { exportNames: string[] }) => record.exportNames[0]),
122123).toEqual(["aliasedThing", "singleOwnerHelper"]);
123124124-const textCaptured = createCapturedIo();
125-const textExit = await main(
126-[
127-"--scope=custom",
128-"--entrypoint-root=src/public",
129-"--import-prefix=fixture-sdk",
130-"--repo-root=test/fixtures/ts-topology/basic",
131-"--report=consumer-topology",
132-"--limit=2",
133-],
134-textCaptured.io,
135-);
136-expect(textExit).toBe(0);
137-expect(textCaptured.readStdout()).toMatchInlineSnapshot(`
125+expect(renderTextReport(deriveReportEnvelope("consumer-topology"), 2)).toMatchInlineSnapshot(`
138126 "Scope: custom
139127 Records with consumers: 5
140128141129 Top 2 consumer-topology records:
142130 - fixture-sdk:sharedThing prod=3 test=0 internal=0
143- - fixture-sdk:SharedType prod=2 test=0 internal=0
144- "
131+ - fixture-sdk:SharedType prod=2 test=0 internal=0"
145132 `);
146133});
147134});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。