|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| - |
9 | 8 | import { Architect } from '@angular-devkit/architect';
|
10 |
| -import { join, normalize, tags, virtualFs } from '@angular-devkit/core'; |
| 9 | +import { join, normalize, tags, virtualFs, workspaces } from '@angular-devkit/core'; |
11 | 10 | import { BrowserBuilderOutput } from '../../src/browser';
|
12 | 11 | import { createArchitect, host } from '../utils';
|
13 | 12 |
|
14 |
| - |
15 |
| -describe('Browser Builder works with BOM index.html', () => { |
| 13 | +// tslint:disable-next-line:no-big-function |
| 14 | +describe('Browser Builder index HTML processing', () => { |
16 | 15 | const targetSpec = { project: 'app', target: 'build' };
|
17 | 16 | let architect: Architect;
|
18 | 17 |
|
@@ -108,4 +107,134 @@ describe('Browser Builder works with BOM index.html', () => {
|
108 | 107 | );
|
109 | 108 | await run.stop();
|
110 | 109 | });
|
| 110 | + |
| 111 | + it('uses the input value from the index option longform', async () => { |
| 112 | + const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host)); |
| 113 | + const app = workspace.projects.get('app'); |
| 114 | + if (!app) { |
| 115 | + fail('Test application "app" not found.'); |
| 116 | + |
| 117 | + return; |
| 118 | + } |
| 119 | + const target = app.targets.get('build'); |
| 120 | + if (!target) { |
| 121 | + fail('Test application "app" target "build" not found.'); |
| 122 | + |
| 123 | + return; |
| 124 | + } |
| 125 | + if (!target.options) { |
| 126 | + target.options = {}; |
| 127 | + } |
| 128 | + target.options.index = { input: 'src/index-2.html' }; |
| 129 | + await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host)); |
| 130 | + |
| 131 | + host.writeMultipleFiles({ |
| 132 | + 'src/index-2.html': tags.oneLine` |
| 133 | + <html><head><base href="/"><%= csrf_meta_tags %></head> |
| 134 | + <body><app-root></app-root></body></html> |
| 135 | + `, |
| 136 | + }); |
| 137 | + await host.delete(join(host.root(), normalize('src/index.html'))).toPromise(); |
| 138 | + |
| 139 | + // Recreate architect to use update angular.json |
| 140 | + architect = (await createArchitect(host.root())).architect; |
| 141 | + |
| 142 | + const run = await architect.scheduleTarget(targetSpec); |
| 143 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true })); |
| 144 | + |
| 145 | + const outputIndexPath = join(host.root(), 'dist', 'index.html'); |
| 146 | + const content = await host.read(normalize(outputIndexPath)).toPromise(); |
| 147 | + expect(virtualFs.fileBufferToString(content)).toBe( |
| 148 | + `<html><head><base href="/"><%= csrf_meta_tags %></head> ` |
| 149 | + + `<body><app-root></app-root><script src="runtime.js"></script>` |
| 150 | + + `<script src="polyfills.js"></script><script src="styles.js"></script>` |
| 151 | + + `<script src="vendor.js"></script><script src="main.js"></script></body></html>`, |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | + it('uses the output value from the index option longform', async () => { |
| 156 | + const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host)); |
| 157 | + const app = workspace.projects.get('app'); |
| 158 | + if (!app) { |
| 159 | + fail('Test application "app" not found.'); |
| 160 | + |
| 161 | + return; |
| 162 | + } |
| 163 | + const target = app.targets.get('build'); |
| 164 | + if (!target) { |
| 165 | + fail('Test application "app" target "build" not found.'); |
| 166 | + |
| 167 | + return; |
| 168 | + } |
| 169 | + if (!target.options) { |
| 170 | + target.options = {}; |
| 171 | + } |
| 172 | + target.options.index = { input: 'src/index.html', output: 'main.html' }; |
| 173 | + await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host)); |
| 174 | + |
| 175 | + host.writeMultipleFiles({ |
| 176 | + 'src/index.html': tags.oneLine` |
| 177 | + <html><head><base href="/"></head> |
| 178 | + <body><app-root></app-root></body></html> |
| 179 | + `, |
| 180 | + }); |
| 181 | + |
| 182 | + // Recreate architect to use update angular.json |
| 183 | + architect = (await createArchitect(host.root())).architect; |
| 184 | + |
| 185 | + const run = await architect.scheduleTarget(targetSpec); |
| 186 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true })); |
| 187 | + |
| 188 | + const outputIndexPath = join(host.root(), 'dist', 'main.html'); |
| 189 | + const content = await host.read(normalize(outputIndexPath)).toPromise(); |
| 190 | + expect(virtualFs.fileBufferToString(content)).toBe( |
| 191 | + `<html><head><base href="/"></head> ` |
| 192 | + + `<body><app-root></app-root><script src="runtime.js"></script>` |
| 193 | + + `<script src="polyfills.js"></script><script src="styles.js"></script>` |
| 194 | + + `<script src="vendor.js"></script><script src="main.js"></script></body></html>`, |
| 195 | + ); |
| 196 | + }); |
| 197 | + |
| 198 | + it('creates subdirectories for output value from the index option longform', async () => { |
| 199 | + const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host)); |
| 200 | + const app = workspace.projects.get('app'); |
| 201 | + if (!app) { |
| 202 | + fail('Test application "app" not found.'); |
| 203 | + |
| 204 | + return; |
| 205 | + } |
| 206 | + const target = app.targets.get('build'); |
| 207 | + if (!target) { |
| 208 | + fail('Test application "app" target "build" not found.'); |
| 209 | + |
| 210 | + return; |
| 211 | + } |
| 212 | + if (!target.options) { |
| 213 | + target.options = {}; |
| 214 | + } |
| 215 | + target.options.index = { input: 'src/index.html', output: 'extra/main.html' }; |
| 216 | + await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host)); |
| 217 | + |
| 218 | + host.writeMultipleFiles({ |
| 219 | + 'src/index.html': tags.oneLine` |
| 220 | + <html><head><base href="/"></head> |
| 221 | + <body><app-root></app-root></body></html> |
| 222 | + `, |
| 223 | + }); |
| 224 | + |
| 225 | + // Recreate architect to use update angular.json |
| 226 | + architect = (await createArchitect(host.root())).architect; |
| 227 | + |
| 228 | + const run = await architect.scheduleTarget(targetSpec); |
| 229 | + await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true })); |
| 230 | + |
| 231 | + const outputIndexPath = join(host.root(), 'dist', 'extra', 'main.html'); |
| 232 | + const content = await host.read(normalize(outputIndexPath)).toPromise(); |
| 233 | + expect(virtualFs.fileBufferToString(content)).toBe( |
| 234 | + `<html><head><base href="/"></head> ` |
| 235 | + + `<body><app-root></app-root><script src="runtime.js"></script>` |
| 236 | + + `<script src="polyfills.js"></script><script src="styles.js"></script>` |
| 237 | + + `<script src="vendor.js"></script><script src="main.js"></script></body></html>`, |
| 238 | + ); |
| 239 | + }); |
111 | 240 | });
|
0 commit comments