archunit
Version:
ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app
107 lines • 5.46 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const graph_1 = require("../../src/graph");
(0, globals_1.describe)('Graph report generation examples', () => {
const outputDir = path.join(process.cwd(), 'reports', 'graph-examples');
const tsConfigPath = path.join(process.cwd(), 'tsconfig.json');
(0, globals_1.it)('generates graph reports for this repository in all supported formats', async () => {
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const fullGraph = (0, graph_1.projectGraph)(tsConfigPath).titled('ArchUnitTS Full Dependency Graph');
const collapsedGraph = (0, graph_1.projectGraph)(tsConfigPath)
.titled('ArchUnitTS Folder-Level Dependency Graph')
.collapseToFolderDepth(2);
const metricsFocus = (0, graph_1.projectGraph)(tsConfigPath)
.titled('ArchUnitTS Metrics Focus')
.focusOn('src/metrics/**', 1);
const graphFocus = (0, graph_1.projectGraph)(tsConfigPath)
.titled('ArchUnitTS Graph Module Focus')
.focusOn('src/graph/**', 1);
const graphReporterReachable = (0, graph_1.projectGraph)(tsConfigPath)
.titled('Dependencies Reachable From Graph Reporter')
.reachableFrom('src/graph/graph-reporter.ts');
const commonDependents = (0, graph_1.projectGraph)(tsConfigPath)
.titled('Dependents Of Common Utilities')
.dependentsOf('src/common/**')
.collapseToFolderDepth(2);
await fullGraph.exportAsHTML(path.join(outputDir, 'full.html'));
await fullGraph.exportAsMermaid(path.join(outputDir, 'full.mmd'));
await fullGraph.exportAsDOT(path.join(outputDir, 'full.dot'));
await fullGraph.exportAsD2(path.join(outputDir, 'full.d2'));
await fullGraph.exportAsCSV(path.join(outputDir, 'full.csv'));
await fullGraph.exportAsJSON(path.join(outputDir, 'full.json'));
await collapsedGraph.exportAsHTML(path.join(outputDir, 'collapsed-depth-2.html'));
await collapsedGraph.exportAsMermaid(path.join(outputDir, 'collapsed-depth-2.mmd'));
await collapsedGraph.exportAsDOT(path.join(outputDir, 'collapsed-depth-2.dot'));
await metricsFocus.exportAsHTML(path.join(outputDir, 'focus-metrics.html'));
await metricsFocus.exportAsMermaid(path.join(outputDir, 'focus-metrics.mmd'));
await graphFocus.exportAsHTML(path.join(outputDir, 'focus-graph.html'));
await graphFocus.exportAsMermaid(path.join(outputDir, 'focus-graph.mmd'));
await graphReporterReachable.exportAsHTML(path.join(outputDir, 'reachable-from-graph-reporter.html'));
await graphReporterReachable.exportAsJSON(path.join(outputDir, 'reachable-from-graph-reporter.json'));
await commonDependents.exportAsHTML(path.join(outputDir, 'dependents-of-common.html'));
await commonDependents.exportAsMermaid(path.join(outputDir, 'dependents-of-common.mmd'));
const expectedFiles = [
'full.html',
'full.mmd',
'full.dot',
'full.d2',
'full.csv',
'full.json',
'collapsed-depth-2.html',
'collapsed-depth-2.mmd',
'collapsed-depth-2.dot',
'focus-metrics.html',
'focus-metrics.mmd',
'focus-graph.html',
'focus-graph.mmd',
'reachable-from-graph-reporter.html',
'reachable-from-graph-reporter.json',
'dependents-of-common.html',
'dependents-of-common.mmd',
];
for (const file of expectedFiles) {
const outputPath = path.join(outputDir, file);
(0, globals_1.expect)(fs.existsSync(outputPath)).toBe(true);
(0, globals_1.expect)(fs.statSync(outputPath).size).toBeGreaterThan(0);
}
});
});
//# sourceMappingURL=graph-report-generation.spec.js.map