Debian Codegraph @

workspaces/arborist/test/peer-entry-sets.js

raw
1 const t = require('tap')
2 const peerEntrySets = require('../lib/peer-entry-sets.js')
3
4 const Node = require('../lib/node.js')
5
6 t.test('basic test', t => {
7 // a -> (b, c, d)
8 // b -> PEER(d) b -> d -> e -> f <-> g
9 // c -> PEER(f, h) c -> (f <-> g, h -> g)
10 // d -> PEER(e) d -> e -> f <-> g
11 // e -> PEER(f)
12 // f -> PEER(g)
13 // g -> PEER(f)
14 // h -> PEER(g)
15 const version = '1.0.0'
16 const path = '/some/path'
17 const a = new Node({
18 path,
19 pkg: { name: 'a', version, dependencies: { b: '', c: '', d: '' } },
20 children: [
21 { pkg: { name: 'b', version, peerDependencies: { d: '' } } },
22 { pkg: { name: 'c', version, peerDependencies: { f: '', h: '' } } },
23 { pkg: { name: 'd', version, peerDependencies: { e: '' } } },
24 { pkg: { name: 'e', version, peerDependencies: { f: '' } } },
25 { pkg: { name: 'f', version, peerDependencies: { g: '' } } },
26 // g has an invalid dep on c, skip that one
27 { pkg: { name: 'g', version, dependencies: { c: '2' }, peerDependencies: { f: '' } } },
28 // h has an invalid peer dep on d, skip that one
29 { pkg: { name: 'h', version, peerDependencies: { g: '', d: '2' } } },
30 ],
31 })
32 const b = a.children.get('b')
33 const c = a.children.get('c')
34 const d = a.children.get('d')
35 const e = a.children.get('e')
36 const f = a.children.get('f')
37 const g = a.children.get('g')
38 const h = a.children.get('h')
39
40 t.formatSnapshot = entrySet => {
41 return new Map([...entrySet.entries()].map(([edge, nodes]) => {
42 return [
43 [edge.from.location, edge.type, edge.name, edge.spec],
44 [...nodes].map(n => [n.location, n.version]),
45 ]
46 }))
47 }
48
49 t.matchSnapshot(peerEntrySets(b), 'b')
50 t.matchSnapshot(peerEntrySets(c), 'c')
51 t.matchSnapshot(peerEntrySets(d), 'd')
52 t.matchSnapshot(peerEntrySets(e), 'e')
53 t.matchSnapshot(peerEntrySets(f), 'f')
54 t.matchSnapshot(peerEntrySets(g), 'g')
55 t.matchSnapshot(peerEntrySets(h), 'h')
56 t.end()
57 })