|
| 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.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { executeDevServer } from '../../index'; |
| 10 | +import { executeOnceAndFetch } from '../execute-fetch'; |
| 11 | +import { describeServeBuilder } from '../jasmine-helpers'; |
| 12 | +import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup'; |
| 13 | + |
| 14 | +// TODO: Temporarily disabled pending investigation into test-only Vite not stopping when caching is enabled |
| 15 | +describeServeBuilder( |
| 16 | + executeDevServer, |
| 17 | + DEV_SERVER_BUILDER_INFO, |
| 18 | + (harness, setupTarget, isViteRun) => { |
| 19 | + // prebundling is not available in webpack |
| 20 | + (isViteRun ? xdescribe : xdescribe)('option: "prebundle"', () => { |
| 21 | + beforeEach(async () => { |
| 22 | + setupTarget(harness); |
| 23 | + |
| 24 | + harness.useProject('test', { |
| 25 | + cli: { |
| 26 | + cache: { |
| 27 | + enabled: true, |
| 28 | + }, |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + // Application code is not needed for these tests |
| 33 | + await harness.writeFile( |
| 34 | + 'src/main.ts', |
| 35 | + ` |
| 36 | + import { VERSION as coreVersion } from '@angular/core'; |
| 37 | + import { VERSION as platformVersion } from '@angular/platform-browser'; |
| 38 | +
|
| 39 | + console.log(coreVersion); |
| 40 | + console.log(platformVersion); |
| 41 | + `, |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should prebundle dependencies when option is not present', async () => { |
| 46 | + harness.useTarget('serve', { |
| 47 | + ...BASE_OPTIONS, |
| 48 | + }); |
| 49 | + |
| 50 | + const { result, content } = await executeOnceAndFetch(harness, '/main.js'); |
| 51 | + |
| 52 | + expect(result?.success).toBeTrue(); |
| 53 | + expect(content).toContain('vite/deps/@angular_core.js'); |
| 54 | + expect(content).not.toContain('node_modules/@angular/core/'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should prebundle dependencies when option is set to true', async () => { |
| 58 | + harness.useTarget('serve', { |
| 59 | + ...BASE_OPTIONS, |
| 60 | + prebundle: true, |
| 61 | + }); |
| 62 | + |
| 63 | + const { result, content } = await executeOnceAndFetch(harness, '/main.js'); |
| 64 | + |
| 65 | + expect(result?.success).toBeTrue(); |
| 66 | + expect(content).toContain('vite/deps/@angular_core.js'); |
| 67 | + expect(content).not.toContain('node_modules/@angular/core/'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should not prebundle dependencies when option is set to false', async () => { |
| 71 | + harness.useTarget('serve', { |
| 72 | + ...BASE_OPTIONS, |
| 73 | + prebundle: false, |
| 74 | + }); |
| 75 | + |
| 76 | + const { result, content } = await executeOnceAndFetch(harness, '/main.js'); |
| 77 | + |
| 78 | + expect(result?.success).toBeTrue(); |
| 79 | + expect(content).not.toContain('vite/deps/@angular_core.js'); |
| 80 | + expect(content).toContain('node_modules/@angular/core/'); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should not prebundle specified dependency if added to exclude list', async () => { |
| 84 | + harness.useTarget('serve', { |
| 85 | + ...BASE_OPTIONS, |
| 86 | + prebundle: { exclude: ['@angular/platform-browser'] }, |
| 87 | + }); |
| 88 | + |
| 89 | + const { result, content } = await executeOnceAndFetch(harness, '/main.js'); |
| 90 | + |
| 91 | + expect(result?.success).toBeTrue(); |
| 92 | + expect(content).toContain('vite/deps/@angular_core.js'); |
| 93 | + expect(content).not.toContain('node_modules/@angular/core/'); |
| 94 | + expect(content).not.toContain('vite/deps/@angular_platform-browser.js'); |
| 95 | + expect(content).toContain('node_modules/@angular/platform-browser/'); |
| 96 | + }); |
| 97 | + }); |
| 98 | + }, |
| 99 | +); |
0 commit comments