-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
run-many.spec.ts
134 lines (126 loc) · 3.35 KB
/
run-many.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
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
import { ProjectGraph } from '@nrwl/nx-cloud/lib/core/models/run-context.model';
import { projectsToRun } from './run-many';
import { performance } from 'perf_hooks';
describe('run-many', () => {
describe('projectsToRun', () => {
let projectGraph: ProjectGraph;
beforeEach(() => {
projectGraph = {
nodes: {
proj1: {
name: 'proj1',
type: 'lib',
data: {
root: 'proj1',
targets: {
build: {},
test: {},
},
},
},
proj2: {
name: 'proj2',
type: 'lib',
data: {
root: 'proj2',
targets: {
test: {},
},
},
},
},
dependencies: {},
};
});
it('should select all projects with a target', () => {
const projects = projectsToRun(
{
all: true,
targets: ['test'],
projects: [],
},
projectGraph
).map(({ name }) => name);
expect(projects).toContain('proj1');
expect(projects).toContain('proj2');
});
it('should select a project with a target', () => {
const projects = projectsToRun(
{
targets: ['test'],
projects: ['proj1'],
},
projectGraph
).map(({ name }) => name);
expect(projects).toContain('proj1');
expect(projects).not.toContain('proj2');
});
it('should filter projects with a pattern', () => {
const projects = projectsToRun(
{
targets: ['test'],
projects: ['proj*'],
},
projectGraph
).map(({ name }) => name);
expect(projects).toContain('proj1');
expect(projects).toContain('proj2');
});
it('should exclude projects', () => {
const projects = projectsToRun(
{
all: true,
targets: ['test'],
projects: [],
exclude: ['proj1'],
},
projectGraph
).map(({ name }) => name);
expect(projects).not.toContain('proj1');
expect(projects).toContain('proj2');
});
it('should exclude projects with a pattern', () => {
const projects = projectsToRun(
{
all: true,
targets: ['test'],
projects: [],
exclude: ['proj*'],
},
projectGraph
).map(({ name }) => name);
expect(projects).not.toContain('proj1');
expect(projects).not.toContain('proj2');
});
describe('perf testing', () => {
beforeEach(() => {
for (let i = 0; i < 1000000; i++) {
projectGraph.nodes['proj' + i] = {
name: 'proj' + i,
type: 'lib',
data: {
root: 'proj' + i,
targets: {
test: {},
},
},
};
}
});
it('should be able to select and exclude via patterns', async () => {
performance.mark('start');
projectsToRun(
{
targets: ['test'],
projects: ['proj1*'],
exclude: ['proj12*'],
},
projectGraph
);
performance.mark('end');
const measure = performance.measure('projects', 'start', 'end');
expect(measure.duration).toBeLessThan(4000);
});
});
});
});