-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathreport.spec.ts
More file actions
153 lines (125 loc) · 5.77 KB
/
report.spec.ts
File metadata and controls
153 lines (125 loc) · 5.77 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import child_process from 'node:child_process';
import {
dependencies as licenseKitDependenciesObj,
devDependencies as licenseKitDevDependenciesObj,
} from '../../../packages/license-kit/package.json';
import {
dependencies as sharedDependenciesObj,
devDependencies as sharedDevDependenciesObj,
} from '../../../packages/shared/package.json';
import { dependencies as dependenciesObj, devDependencies as devDependenciesObj } from '../package.json';
const dependencies = Object.keys(dependenciesObj).sort();
const devDependencies = Object.keys(devDependenciesObj).sort();
const licenseKitDependencies = Object.keys(licenseKitDependenciesObj).sort();
const licenseKitDevDependencies = Object.keys(licenseKitDevDependenciesObj).sort();
const sharedDependencies = Object.keys(sharedDependenciesObj).sort();
const sharedDevDependencies = Object.keys(sharedDevDependenciesObj).sort();
async function runReportCommandForJsonOutput(args: string[] = []) {
const command = `yarn workspace license-kit-node-example report${args ? ` ${args.join(' ')}` : ''}`;
const output = await new Promise<string>((resolve) => {
child_process.exec(command, (_, stdout) => {
resolve(stdout);
});
});
return JSON.parse(output);
}
describe('license-kit report', () => {
it('including transitive deps, with dev deps with default settings', async () => {
const json = await runReportCommandForJsonOutput();
expect(json['dhtmlx-gantt'].type).toMatch('GPL-2.0');
expect(json['is-even'].content).toMatch('MIT License');
expect(json['is-even'].type).toMatch('MIT');
expect(json.mariadb.content).toMatch('GNU LESSER GENERAL PUBLIC LICENSE');
expect(json.mariadb.type).toMatch('LGPL-2.1-or-later');
expect(json.zustand.content).toMatch('MIT License');
expect(json.zustand.type).toMatch('MIT');
});
it('without transitive deps and without dev deps', async () => {
const json = await runReportCommandForJsonOutput(['--dev-deps-mode', 'none', '--transitive-deps-mode', 'none']);
expect(Object.keys(json).toSorted()).toEqual(dependencies.toSorted());
});
it('without transitive deps and with root-only dev deps', async () => {
const json = await runReportCommandForJsonOutput([
'--dev-deps-mode',
'root-only',
'--transitive-deps-mode',
'none',
]);
expect(Object.keys(json).toSorted()).toEqual(Array.from(new Set([...dependencies, ...devDependencies])).toSorted());
});
it('with root-only dev deps and with transitive dependencies of workspace-specifier-only dependencies', async () => {
const json = await runReportCommandForJsonOutput([
'--dev-deps-mode',
'root-only',
'--transitive-deps-mode',
'from-workspace-only',
]);
expect(Object.keys(json).toSorted()).toEqual(
Array.from(new Set([...dependencies, ...devDependencies, ...licenseKitDependencies])).toSorted(),
);
});
it('without dev deps and with transitive dependencies of external dependencies only', async () => {
const json = await runReportCommandForJsonOutput([
'--dev-deps-mode',
'none',
'--transitive-deps-mode',
'from-external-only',
]);
const resultKeys = Object.keys(json);
expect(resultKeys.toSorted()).toEqual([
'@types/geojson',
'@types/node',
'denque',
'dhtmlx-gantt',
'iconv-lite',
'is-even',
'is-number',
'is-odd',
'lru-cache',
'mariadb',
'safer-buffer',
'undici-types',
'yallist',
'zustand',
]);
expect(resultKeys).not.toIncludeAllMembers(licenseKitDependencies);
expect(resultKeys).not.toIncludeAllMembers(licenseKitDevDependencies);
});
it('with root-only dev deps and with transitive dependencies of external dependencies only', async () => {
const json = await runReportCommandForJsonOutput([
'--dev-deps-mode',
'root-only',
'--transitive-deps-mode',
'from-external-only',
]);
const resultKeys = Object.keys(json);
expect(resultKeys).toContain('license-kit');
// this time, the result should also include all dependencies of the direct devDependencies of the root package.json
expect(resultKeys.length).toBeGreaterThan(200);
expect(resultKeys).toIncludeAllMembers([
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-transform-block-scoped-functions',
'@babel/plugin-transform-block-scoping',
'@babel/plugin-transform-class-properties',
'@babel/helper-create-class-features-plugin',
'@babel/helper-member-expression-to-functions',
]);
expect(resultKeys).not.toIncludeAllMembers(licenseKitDependencies);
expect(resultKeys).not.toIncludeAllMembers(licenseKitDevDependencies);
// note: sharedDependencies should not be included, yet they contain glob, which is a transitive dependency of something else
expect(resultKeys).not.toIncludeAllMembers(sharedDevDependencies);
});
it('with root-only dev deps and with all transitive dependencies', async () => {
const json = await runReportCommandForJsonOutput(['--dev-deps-mode', 'root-only', '--transitive-deps-mode', 'all']);
const resultKeys = Object.keys(json);
// this time, the result should also include all transitive dependencies of direct devDependencies of the root package.json,
// such as that of license-kit itself (which is a direct devDependency of the root package.json)
expect(resultKeys.length).toBeGreaterThan(300);
expect(resultKeys).toContain('license-kit');
expect(resultKeys).toContain('@callstack/react-native-legal-shared');
expect(resultKeys).toIncludeAllMembers(licenseKitDependencies);
expect(resultKeys).not.toIncludeAllMembers(licenseKitDevDependencies);
expect(resultKeys).toIncludeAllMembers(sharedDependencies);
expect(resultKeys).not.toIncludeAllMembers(sharedDevDependencies);
});
});