|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC 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.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { logging } from '@angular-devkit/core'; |
| 10 | +import { executeDevServer } from '../../index'; |
| 11 | +import { executeOnceAndFetch } from '../execute-fetch'; |
| 12 | +import { describeServeBuilder } from '../jasmine-helpers'; |
| 13 | +import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; |
| 14 | + |
| 15 | +describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => { |
| 16 | + describe('option: "hmr"', () => { |
| 17 | + beforeEach(async () => { |
| 18 | + setupTarget(harness, {}); |
| 19 | + }); |
| 20 | + |
| 21 | + it('shows message with opt out steps by default', async () => { |
| 22 | + harness.useTarget('serve', { |
| 23 | + ...BASE_OPTIONS, |
| 24 | + }); |
| 25 | + |
| 26 | + const { result, logs } = await executeOnceAndFetch(harness, '/'); |
| 27 | + |
| 28 | + expect(result?.success).toBeTrue(); |
| 29 | + expect(logs).toContain( |
| 30 | + jasmine.objectContaining<logging.LogEntry>({ |
| 31 | + message: jasmine.stringMatching('Component HMR has been enabled'), |
| 32 | + }), |
| 33 | + ); |
| 34 | + expect(logs).toContain( |
| 35 | + jasmine.objectContaining<logging.LogEntry>({ |
| 36 | + message: jasmine.stringMatching('--no-hmr'), |
| 37 | + }), |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it('shows message with opt out steps when explicitly enabled', async () => { |
| 42 | + harness.useTarget('serve', { |
| 43 | + ...BASE_OPTIONS, |
| 44 | + hmr: true, |
| 45 | + }); |
| 46 | + |
| 47 | + const { result, logs } = await executeOnceAndFetch(harness, '/'); |
| 48 | + |
| 49 | + expect(result?.success).toBeTrue(); |
| 50 | + expect(logs).toContain( |
| 51 | + jasmine.objectContaining<logging.LogEntry>({ |
| 52 | + message: jasmine.stringMatching('Component HMR has been enabled'), |
| 53 | + }), |
| 54 | + ); |
| 55 | + expect(logs).toContain( |
| 56 | + jasmine.objectContaining<logging.LogEntry>({ |
| 57 | + message: jasmine.stringMatching('--no-hmr'), |
| 58 | + }), |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('does not show enabled message with opt out steps when explicitly disabled', async () => { |
| 63 | + harness.useTarget('serve', { |
| 64 | + ...BASE_OPTIONS, |
| 65 | + hmr: false, |
| 66 | + }); |
| 67 | + |
| 68 | + const { result, logs } = await executeOnceAndFetch(harness, '/'); |
| 69 | + |
| 70 | + expect(result?.success).toBeTrue(); |
| 71 | + expect(logs).not.toContain( |
| 72 | + jasmine.objectContaining<logging.LogEntry>({ |
| 73 | + message: jasmine.stringMatching('Component HMR has been enabled'), |
| 74 | + }), |
| 75 | + ); |
| 76 | + expect(logs).not.toContain( |
| 77 | + jasmine.objectContaining<logging.LogEntry>({ |
| 78 | + message: jasmine.stringMatching('--no-hmr'), |
| 79 | + }), |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
0 commit comments