packageBoundary.test.mjs
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import assert from 'node:assert/strict'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import {
checkPackageBoundaries,
findIllegalPackageEdges,
} from '../../scripts/check-package-boundaries.mjs'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const subpackageRoots = ['packageStudy', 'packageWorkspace', 'tabWorkOrder']
function graphWithEdges(edges) {
return {
nodes: [
{ id: 'main', type: 'module', path: 'utils/main.js' },
{ id: 'application', type: 'domain' },
{ id: 'study', type: 'module', path: 'packageStudy/utils/study.js' },
{ id: 'workspace', type: 'component', path: 'packageWorkspace/components/card/card' },
{ id: 'work-order', type: 'page', path: 'tabWorkOrder/pages/orderDetail/orderDetail' },
{ id: 'test', type: 'test', path: 'tests/package-size/example.test.mjs' },
],
edges,
}
}
test('package boundary audit rejects main-to-subpackage and cross-subpackage edges', () => {
const graph = graphWithEdges([
{ from: 'main', to: 'study', type: 'imports', evidence: { path: 'utils/main.js' } },
{
from: 'application',
to: 'study',
type: 'usesComponent',
evidence: { path: 'app.json' },
},
{
from: 'study',
to: 'workspace',
type: 'usesComponent',
evidence: { path: 'packageStudy/pages/example/example.json' },
},
{ from: 'work-order', to: 'main', type: 'imports', evidence: {} },
{ from: 'test', to: 'study', type: 'imports', evidence: {} },
])
assert.deepEqual(
findIllegalPackageEdges({ graph, subpackageRoots }).map(edge => [
edge.fromOwner,
edge.toOwner,
edge.type,
]),
[
['main', 'packageStudy', 'usesComponent'],
['packageStudy', 'packageWorkspace', 'usesComponent'],
['main', 'packageStudy', 'imports'],
],
)
})
test('current runtime graph contains no illegal package dependency edges', async () => {
const report = await checkPackageBoundaries({ rootDir: projectRoot })
assert.deepEqual(report.illegalEdges, [])
assert.ok(report.checkedEdges > 0)
assert.deepEqual(report.subpackageRoots, subpackageRoots)
})