Skip to content

Commit 6a29ce4

Browse files
filipesilvavikerman
authored andcommitted
test: add issue for broken app-shell test
1 parent ecc9d0e commit 6a29ce4

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

packages/angular_devkit/build_angular/src/app-shell/index.ts

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import { JsonObject, experimental, join, normalize, resolve, schema } from '@ang
1515
import { NodeJsSyncHost } from '@angular-devkit/core/node';
1616
import * as fs from 'fs';
1717
import * as path from 'path';
18+
import { readTsconfig } from '../angular-cli-files/utilities/read-tsconfig';
1819
import { augmentAppWithServiceWorker } from '../angular-cli-files/utilities/service-worker';
1920
import { BrowserBuilderOutput } from '../browser';
2021
import { Schema as BrowserBuilderSchema } from '../browser/schema';
2122
import { ServerBuilderOutput } from '../server';
2223
import { Schema as BuildWebpackAppShellSchema } from './schema';
2324

24-
2525
async function _renderUniversal(
2626
options: BuildWebpackAppShellSchema,
2727
context: BuilderContext,
@@ -31,40 +31,48 @@ async function _renderUniversal(
3131
const browserIndexOutputPath = path.join(browserResult.outputPath || '', 'index.html');
3232
const indexHtml = fs.readFileSync(browserIndexOutputPath, 'utf8');
3333
const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult);
34-
3534
const root = context.workspaceRoot;
3635

36+
// Get browser target options.
37+
const browserTarget = targetFromTargetString(options.browserTarget);
38+
const rawBrowserOptions = await context.getTargetOptions(browserTarget);
39+
const browserBuilderName = await context.getBuilderNameForTarget(browserTarget);
40+
const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderSchema>(
41+
rawBrowserOptions,
42+
browserBuilderName,
43+
);
44+
45+
// Determine if browser app was compiled using Ivy.
46+
const { options: compilerOptions } = readTsconfig(browserOptions.tsConfig, context.workspaceRoot);
47+
const ivy = compilerOptions.enableIvy;
48+
3749
// Initialize zone.js
3850
const zonePackage = require.resolve('zone.js', { paths: [root] });
3951
await import(zonePackage);
4052

4153
// Load platform server module renderer
4254
const platformServerPackage = require.resolve('@angular/platform-server', { paths: [root] });
43-
const renderModuleFactory = await import(platformServerPackage)
55+
const renderOpts = {
56+
document: indexHtml,
57+
url: options.route,
58+
};
59+
60+
// Render app to HTML using Ivy or VE
61+
const html = await import(platformServerPackage)
4462
// tslint:disable-next-line:no-implicit-dependencies
45-
.then((m: typeof import('@angular/platform-server')) => m.renderModuleFactory);
63+
.then((m: typeof import('@angular/platform-server')) =>
64+
ivy
65+
? m.renderModule(require(serverBundlePath).AppServerModule, renderOpts)
66+
: m.renderModuleFactory(require(serverBundlePath).AppServerModuleNgFactory, renderOpts),
67+
);
4668

47-
const AppServerModuleNgFactory = require(serverBundlePath).AppServerModuleNgFactory;
69+
// Overwrite the client index file.
4870
const outputIndexPath = options.outputIndexPath
4971
? path.join(root, options.outputIndexPath)
5072
: browserIndexOutputPath;
5173

52-
// Render to HTML and overwrite the client index file.
53-
const html = await renderModuleFactory(AppServerModuleNgFactory, {
54-
document: indexHtml,
55-
url: options.route,
56-
});
57-
5874
fs.writeFileSync(outputIndexPath, html);
5975

60-
const browserTarget = targetFromTargetString(options.browserTarget);
61-
const rawBrowserOptions = await context.getTargetOptions(browserTarget);
62-
const browserBuilderName = await context.getBuilderNameForTarget(browserTarget);
63-
const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderSchema>(
64-
rawBrowserOptions,
65-
browserBuilderName,
66-
);
67-
6876
if (browserOptions.serviceWorker) {
6977
const host = new NodeJsSyncHost();
7078
// Create workspace.
@@ -81,10 +89,7 @@ async function _renderUniversal(
8189
if (!projectName) {
8290
throw new Error('Must either have a target from the context or a default project.');
8391
}
84-
const projectRoot = resolve(
85-
workspace.root,
86-
normalize(workspace.getProject(projectName).root),
87-
);
92+
const projectRoot = resolve(workspace.root, normalize(workspace.getProject(projectName).root));
8893

8994
await augmentAppWithServiceWorker(
9095
host,
@@ -99,7 +104,6 @@ async function _renderUniversal(
99104
return browserResult;
100105
}
101106

102-
103107
async function _getServerModuleBundlePath(
104108
options: BuildWebpackAppShellSchema,
105109
context: BuilderContext,
@@ -121,7 +125,6 @@ async function _getServerModuleBundlePath(
121125
}
122126
}
123127

124-
125128
async function _appShellBuilder(
126129
options: JsonObject & BuildWebpackAppShellSchema,
127130
context: BuilderContext,
@@ -139,7 +142,7 @@ async function _appShellBuilder(
139142

140143
try {
141144
const [browserResult, serverResult] = await Promise.all([
142-
browserTargetRun.result as {} as BrowserBuilderOutput,
145+
(browserTargetRun.result as {}) as BrowserBuilderOutput,
143146
serverTargetRun.result,
144147
]);
145148

@@ -154,12 +157,8 @@ async function _appShellBuilder(
154157
return { success: false, error: err.message };
155158
} finally {
156159
// Just be good citizens and stop those jobs.
157-
await Promise.all([
158-
browserTargetRun.stop(),
159-
serverTargetRun.stop(),
160-
]);
160+
await Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]);
161161
}
162162
}
163163

164-
165164
export default createBuilder(_appShellBuilder);

packages/angular_devkit/build_angular/test/app-shell/app-shell_spec_large.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { createArchitect, host, veEnabled } from '../utils';
1313

1414

1515
// DISABLED_FOR_IVY These should pass but are currently not supported
16+
// See https://github.com/angular/angular-cli/issues/15383 for details.
1617
(veEnabled ? describe : xdescribe)('AppShell Builder', () => {
1718
const target = { project: 'app', target: 'app-shell' };
1819
let architect: Architect;

tests/legacy-cli/e2e_runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ if (!argv.ve) {
105105
// We don't have a platform-server usage story yet for Ivy.
106106
// It's contingent on lazy loading and factory shim considerations that are still being
107107
// discussed.
108+
// Broken currently https://github.com/angular/angular-cli/issues/15383
108109
.filter(name => !name.endsWith('tests/build/platform-server.ts'))
109110
.filter(name => !name.endsWith('tests/build/build-app-shell.ts'))
110111
.filter(name => !name.endsWith('tests/build/build-app-shell-with-schematic.ts'));

0 commit comments

Comments
 (0)