Skip to content

Commit 2041c70

Browse files
committed
test(@angular-devkit/build-angular): add dev-server builder deployUrl behavior tests
This change adds expanded unit tests for the dev-server builder's build deploy URL behavior using the builder test harness.
1 parent 352416f commit 2041c70

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

packages/angular_devkit/build_angular/src/dev-server/deploy-url_spec.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { serveWebpackBrowser } from '../../index';
9+
import { executeOnceAndFetch } from '../execute-fetch';
10+
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO, describeBuilder, setupBrowserTarget } from '../setup';
11+
12+
describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "browser builder deployUrl"', () => {
14+
beforeEach(() => {
15+
setupBrowserTarget(harness, {
16+
deployUrl: 'test/',
17+
});
18+
});
19+
20+
it('uses the deploy URL defined in the "browserTarget" options as the serve path', async () => {
21+
harness.useTarget('serve', {
22+
...BASE_OPTIONS,
23+
});
24+
25+
const { result, response } = await executeOnceAndFetch(harness, 'runtime.js');
26+
27+
expect(result?.success).toBeTrue();
28+
expect(result?.baseUrl).toMatch(/\/test$/);
29+
expect(response?.url).toMatch(/\/test\/runtime.js$/);
30+
expect(await response?.text()).toContain('window["webpackJsonp"]');
31+
});
32+
});
33+
});

packages/angular_devkit/build_angular/src/dev-server/tests/execute-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function executeOnceAndFetch<T>(
2626
mergeMap(async (executionResult) => {
2727
let response = undefined;
2828
if (executionResult.result?.success) {
29-
const resolvedUrl = new URL(url, executionResult.result.baseUrl as string);
29+
const resolvedUrl = new URL(url, `${executionResult.result.baseUrl}/`);
3030
response = await fetch(resolvedUrl, options?.request);
3131
}
3232

0 commit comments

Comments
 (0)