Skip to content

Commit 2b9cdc1

Browse files
committed
refactor: reduce the number of builds done in output-path_spec
Significantly reduces the number of application builds performed in this test
1 parent e586379 commit 2b9cdc1

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

packages/angular/build/src/builders/application/tests/options/output-path_spec.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { BuilderOutput } from '@angular-devkit/architect';
910
import { buildApplication } from '../../index';
1011
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup';
1112

@@ -33,7 +34,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
3334
});
3435

3536
describe(`when option value is is a string`, () => {
36-
beforeEach(() => {
37+
let result: BuilderOutput | undefined;
38+
beforeAll(async () => {
3739
harness.useTarget('build', {
3840
...BASE_OPTIONS,
3941
polyfills: [],
@@ -44,25 +46,25 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
4446
entry: 'src/server.ts',
4547
},
4648
});
49+
50+
const buildOutput = await harness.executeOnce();
51+
result = buildOutput.result;
4752
});
4853

4954
it(`should emit browser bundles in 'browser' directory`, async () => {
50-
const { result } = await harness.executeOnce();
5155
expect(result?.success).toBeTrue();
5256

5357
harness.expectFile('dist/browser/main.js').toExist();
5458
});
5559

5660
it(`should emit media files in 'browser/media' directory`, async () => {
57-
const { result } = await harness.executeOnce();
5861
expect(result?.success).toBeTrue();
5962

6063
harness.expectFile('dist/browser/media/spectrum.png').toExist();
6164
harness.expectFile('dist/browser/media/abc.svg').toExist();
6265
});
6366

6467
it(`should emit server bundles in 'server' directory`, async () => {
65-
const { result } = await harness.executeOnce();
6668
expect(result?.success).toBeTrue();
6769

6870
harness.expectFile('dist/server/server.mjs').toExist();
@@ -71,7 +73,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
7173

7274
describe(`when option value is an object`, () => {
7375
describe(`'media' is set to 'resources'`, () => {
74-
beforeEach(() => {
76+
let result: BuilderOutput | undefined;
77+
beforeAll(async () => {
7578
harness.useTarget('build', {
7679
...BASE_OPTIONS,
7780
polyfills: [],
@@ -85,33 +88,35 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
8588
entry: 'src/server.ts',
8689
},
8790
});
91+
92+
const buildOutput = await harness.executeOnce();
93+
result = buildOutput.result;
8894
});
8995

9096
it(`should emit browser bundles in 'browser' directory`, async () => {
91-
const { result } = await harness.executeOnce();
9297
expect(result?.success).toBeTrue();
9398

9499
harness.expectFile('dist/browser/main.js').toExist();
95100
});
96101

97102
it(`should emit media files in 'browser/resource' directory`, async () => {
98-
const { result } = await harness.executeOnce();
99103
expect(result?.success).toBeTrue();
100104

101105
harness.expectFile('dist/browser/resource/spectrum.png').toExist();
102106
harness.expectFile('dist/browser/resource/abc.svg').toExist();
103107
});
104108

105109
it(`should emit server bundles in 'server' directory`, async () => {
106-
const { result } = await harness.executeOnce();
107110
expect(result?.success).toBeTrue();
108111

109112
harness.expectFile('dist/server/server.mjs').toExist();
110113
});
111114
});
112115

113116
describe(`'media' is set to ''`, () => {
114-
beforeEach(() => {
117+
let result: BuilderOutput | undefined;
118+
119+
beforeAll(async () => {
115120
harness.useTarget('build', {
116121
...BASE_OPTIONS,
117122
polyfills: [],
@@ -125,17 +130,18 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
125130
entry: 'src/server.ts',
126131
},
127132
});
133+
134+
const buildOutput = await harness.executeOnce();
135+
result = buildOutput.result;
128136
});
129137

130138
it(`should emit browser bundles in 'browser' directory`, async () => {
131-
const { result } = await harness.executeOnce();
132139
expect(result?.success).toBeTrue();
133140

134141
harness.expectFile('dist/browser/main.js').toExist();
135142
});
136143

137144
it(`should emit media files in 'browser' directory`, async () => {
138-
const { result } = await harness.executeOnce();
139145
expect(result?.success).toBeTrue();
140146

141147
harness.expectFile('dist/browser/spectrum.png').toExist();
@@ -146,15 +152,16 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
146152
});
147153

148154
it(`should emit server bundles in 'server' directory`, async () => {
149-
const { result } = await harness.executeOnce();
150155
expect(result?.success).toBeTrue();
151156

152157
harness.expectFile('dist/server/server.mjs').toExist();
153158
});
154159
});
155160

156161
describe(`'server' is set to 'node-server'`, () => {
157-
beforeEach(() => {
162+
let result: BuilderOutput | undefined;
163+
164+
beforeAll(async () => {
158165
harness.useTarget('build', {
159166
...BASE_OPTIONS,
160167
polyfills: [],
@@ -168,33 +175,31 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
168175
entry: 'src/server.ts',
169176
},
170177
});
178+
179+
const buildOutput = await harness.executeOnce();
180+
result = buildOutput.result;
171181
});
172182

173183
it(`should emit browser bundles in 'browser' directory`, async () => {
174-
const { result } = await harness.executeOnce();
175184
expect(result?.success).toBeTrue();
176-
177185
harness.expectFile('dist/browser/main.js').toExist();
178186
});
179187

180188
it(`should emit media files in 'browser/media' directory`, async () => {
181-
const { result } = await harness.executeOnce();
182189
expect(result?.success).toBeTrue();
183-
184190
harness.expectFile('dist/browser/media/spectrum.png').toExist();
185191
harness.expectFile('dist/browser/media/abc.svg').toExist();
186192
});
187193

188194
it(`should emit server bundles in 'node-server' directory`, async () => {
189-
const { result } = await harness.executeOnce();
190195
expect(result?.success).toBeTrue();
191-
192196
harness.expectFile('dist/node-server/server.mjs').toExist();
193197
});
194198
});
195199

196200
describe(`'browser' is set to 'public'`, () => {
197-
beforeEach(() => {
201+
let result: BuilderOutput | undefined;
202+
beforeEach(async () => {
198203
harness.useTarget('build', {
199204
...BASE_OPTIONS,
200205
polyfills: [],
@@ -208,25 +213,25 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
208213
entry: 'src/server.ts',
209214
},
210215
});
216+
217+
const buildOutput = await harness.executeOnce();
218+
result = buildOutput.result;
211219
});
212220

213221
it(`should emit browser bundles in 'public' directory`, async () => {
214-
const { result } = await harness.executeOnce();
215222
expect(result?.success).toBeTrue();
216223

217224
harness.expectFile('dist/public/main.js').toExist();
218225
});
219226

220227
it(`should emit media files in 'public/media' directory`, async () => {
221-
const { result } = await harness.executeOnce();
222228
expect(result?.success).toBeTrue();
223229

224230
harness.expectFile('dist/public/media/spectrum.png').toExist();
225231
harness.expectFile('dist/public/media/abc.svg').toExist();
226232
});
227233

228234
it(`should emit server bundles in 'server' directory`, async () => {
229-
const { result } = await harness.executeOnce();
230235
expect(result?.success).toBeTrue();
231236

232237
harness.expectFile('dist/server/server.mjs').toExist();
@@ -299,7 +304,8 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
299304
});
300305

301306
describe(`'server' is set ''`, () => {
302-
beforeEach(() => {
307+
let result: BuilderOutput | undefined;
308+
beforeAll(async () => {
303309
harness.useTarget('build', {
304310
...BASE_OPTIONS,
305311
polyfills: [],
@@ -313,25 +319,25 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
313319
entry: 'src/server.ts',
314320
},
315321
});
322+
323+
const buildOutput = await harness.executeOnce();
324+
result = buildOutput.result;
316325
});
317326

318327
it(`should emit browser bundles in 'browser' directory`, async () => {
319-
const { result } = await harness.executeOnce();
320328
expect(result?.success).toBeTrue();
321329

322330
harness.expectFile('dist/browser/main.js').toExist();
323331
});
324332

325333
it(`should emit media files in 'browser/media' directory`, async () => {
326-
const { result } = await harness.executeOnce();
327334
expect(result?.success).toBeTrue();
328335

329336
harness.expectFile('dist/browser/media/spectrum.png').toExist();
330337
harness.expectFile('dist/browser/media/abc.svg').toExist();
331338
});
332339

333340
it(`should emit server bundles in '' directory`, async () => {
334-
const { result } = await harness.executeOnce();
335341
expect(result?.success).toBeTrue();
336342

337343
harness.expectFile('dist/server.mjs').toExist();

0 commit comments

Comments
 (0)