Skip to content

Commit

Permalink
test(@angular/build): add dev-server HMR enabled console message tests
Browse files Browse the repository at this point in the history
Tests of the development server's console message output for the `hmr`
option including enabled, disabled, and default cases.
  • Loading branch information
clydin authored and alan-agius4 committed Jan 20, 2025
1 parent 2cbb5a3 commit be5bf49
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import { logging } from '@angular-devkit/core';
import { executeDevServer } from '../../index';
import { executeOnceAndFetch } from '../execute-fetch';
import { describeServeBuilder } from '../jasmine-helpers';
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';

describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
describe('option: "hmr"', () => {
beforeEach(async () => {
setupTarget(harness, {});
});

it('shows message with opt out steps by default', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
});

const { result, logs } = await executeOnceAndFetch(harness, '/');

expect(result?.success).toBeTrue();
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('Component HMR has been enabled'),
}),
);
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('--no-hmr'),
}),
);
});

it('shows message with opt out steps when explicitly enabled', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
hmr: true,
});

const { result, logs } = await executeOnceAndFetch(harness, '/');

expect(result?.success).toBeTrue();
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('Component HMR has been enabled'),
}),
);
expect(logs).toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('--no-hmr'),
}),
);
});

it('does not show enabled message with opt out steps when explicitly disabled', async () => {
harness.useTarget('serve', {
...BASE_OPTIONS,
hmr: false,
});

const { result, logs } = await executeOnceAndFetch(harness, '/');

expect(result?.success).toBeTrue();
expect(logs).not.toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('Component HMR has been enabled'),
}),
);
expect(logs).not.toContain(
jasmine.objectContaining<logging.LogEntry>({
message: jasmine.stringMatching('--no-hmr'),
}),
);
});
});
});

0 comments on commit be5bf49

Please sign in to comment.