-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
buildable-libs-utils.spec.ts
88 lines (82 loc) · 2.15 KB
/
buildable-libs-utils.spec.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {
calculateProjectDependencies,
DependentBuildableProjectNode,
updatePaths,
} from './buildable-libs-utils';
import {
DependencyType,
ProjectGraph,
ProjectType,
} from '../core/project-graph';
import { getMockContext } from './testing';
// TODO(v13): remove this deprecated file
describe('updatePaths', () => {
const deps: DependentBuildableProjectNode[] = [
{ name: '@proj/lib', node: {} as any, outputs: ['dist/libs/lib'] },
];
it('should add path', () => {
const paths: Record<string, string[]> = {
'@proj/test': ['libs/test/src/index.ts'],
};
updatePaths(deps, paths);
expect(paths).toEqual({
'@proj/lib': ['dist/libs/lib'],
'@proj/test': ['libs/test/src/index.ts'],
});
});
it('should replace paths', () => {
const paths: Record<string, string[]> = {
'@proj/lib': ['libs/lib/src/index.ts'],
'@proj/lib/sub': ['libs/lib/sub/src/index.ts'],
};
updatePaths(deps, paths);
expect(paths).toEqual({
'@proj/lib': ['dist/libs/lib'],
'@proj/lib/sub': ['dist/libs/lib/sub'],
});
});
});
describe('calculateProjectDependencies', () => {
it('should include npm packages in dependency list', async () => {
const graph: ProjectGraph = {
nodes: {
example: {
type: ProjectType.lib,
name: 'example',
data: {
files: [],
root: '/root/example',
},
},
'npm:formik': {
type: 'npm',
name: 'npm:formik',
data: {
files: [],
packageName: 'formik',
version: '0.0.0',
},
},
},
dependencies: {
example: [
{
source: 'example',
target: 'npm:formik',
type: DependencyType.static,
},
],
},
};
const context = await getMockContext();
context.target.project = 'example';
const results = await calculateProjectDependencies(graph, context);
expect(results).toMatchObject({
target: {
type: ProjectType.lib,
name: 'example',
},
dependencies: [{ name: 'formik' }],
});
});
});